Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

self-intersecting entity?

22 views
Skip to first unread message

Alfredo Medina

unread,
Dec 13, 2001, 7:51:04 PM12/13/01
to
How can I detect through Lisp if a Lwpolyline, Pline or Spline is a
self-intersecting entity?

Any help would be appreciated.

Alfredo Medina
alfm...@hotmail.com

Cad Manager
The Prisco Group
Hopewell NJ

Luis Esquivel

unread,
Dec 13, 2001, 8:12:15 PM12/13/01
to
Alfredo,

I'm about to leave right now but here is a quick one, not fully tested, also
there is one function in the bonus tools I do not remember the name.

Tested only with lwpolylines...

(defun C:TEST ()
(vl-load-com)
(setq ent (car (entsel)))
(setq vla (vlax-ename->vla-object ent))
(list (/ (length (vlax-safearray->list
(variant-value (vla-get-coordinates vla))
)
)
2
)
(/ (length
(vlax-safearray->list
(variant-value (vla-intersectwith vla vla acExtendNone))
)
)
3
)
)
)

;; ->'(9 9) = not self-intersected if returns pairs
;; ->'(8 10) = self-intersected if returns not pairs

I will back on Monday, see ya.

Luis
CrazyCAD person...

John Uhden

unread,
Dec 14, 2001, 10:24:06 AM12/14/01
to
I think the following will work...
;;-------------------------------------------------------------
;; Function returns a list of 3D points from a continuous list
;; as returned by (vlax-safearray->list (vlax-variant-value X))
;;
(defun @cv_parse_list (|list |n / |item |new)
(foreach |element (reverse |list)
(setq |item (cons |element |item))
(if (= (length |item) |n)
(setq |new (cons |item |new) |item nil)
)
)
|new
)

(defun @self_intersect (object / name open)
(cond
((= (type object) 'ENAME)
(setq object (vlax-ename->vla-object object)
name (vlax-get object "ObjectName")
)
)
((= (type object) 'VLA-OBJECT)
(setq name (vlax-get object "ObjectName"))
)
)
(cond
((not name))
((wcmatch name "AcDb#dPolyline")
(setq open (* 2 (1+ (vlax-get object "Closed"))))
(> (length (@cv_parse_list (vlax-invoke object "IntersectWith"
object acExtendNone) 3))
(- (length (@cv_parse_list (vlax-get object "Coordinates") 3))
open)
)
)
((= name "AcDbPolyline")
(setq open (* 2 (1+ (vlax-get object "Closed"))))
(> (length (@cv_parse_list (vlax-invoke object "IntersectWith"
object acExtendNone) 3))
(- (length (@cv_parse_list (vlax-get object "Coordinates") 2))
open)
)
)
((= name "AcDbSpline")
(if (vlax-invoke object "IntersectWith" object acExtendNone) T)
)
)
)

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juh...@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332

"Alfredo Medina" <alme...@hotmail.com> wrote in message
news:3C194CF8...@hotmail.com...

Alfredo Medina

unread,
Dec 16, 2001, 11:01:58 AM12/16/01
to
John & Luis,

Thank you guys for your help. I will try it out and will post again with
comments.

Alfredo Medina
alfm...@hotmail.com

Luis Esquivel wrote:

>Alfredo,
>
>I'm about to leave right now but here is a quick one, not fully tested, also
>there is one function in the bonus tools I do not remember the name.
>
>Tested only with lwpolylines...
>
>(defun C:TEST ()

(...)

John Uhden wrote:
>
> I think the following will work...
> ;;-------------------------------------------------------------
> ;; Function returns a list of 3D points from a continuous list
> ;; as returned by (vlax-safearray->list (vlax-variant-value X))
> ;;

(...)

Luis Esquivel

unread,
Dec 17, 2001, 2:50:55 PM12/17/01
to
Okay here is a better one just modified to work with plines or splines...
have fun!

;;; sample by Luis Esquivel, December 17, 2001
;;; self-intersect
;;; return: T or nil
;;; note: you must pass a polyline or spline object, no error catching

(defun C:TEST (/ ent)
(lbx-self-intersect
(setq ent (car (entsel)))
)
)

(defun lbx-self-intersect (ent / vla objname)
(vl-load-com)
(setq vla (vlax-ename->vla-object ent)
objname (vla-get-objectname vla)
)
(if (= "AcDbSpline" objname)
(progn
(if (safearray-value
(vlax-variant-value
(vla-intersectwith
vla
vla
acExtendNone
)
)
)
T
nil
)
)
(progn
(apply
'/=
(list
(- (/ (length (vlax-safearray->list


(variant-value (vla-get-coordinates vla))
)
)
2
)
2
)
(/ (length
(vlax-safearray->list
(variant-value
(vla-intersectwith vla vla acExtendNone)
)
)
)
3
)
)
)

)
)
)


John Uhden

unread,
Dec 17, 2001, 4:53:57 PM12/17/01
to
Luis: Nice job!

Good News: It worked on a 3DMesh
Bad News: It doesn't work properly on an AcDb2dPolyline ("heavy") <see my
previous contribution>

You're just a (cond ...) away from perfection.


--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juh...@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332


"Luis Esquivel" <lu...@slarchitects.com> wrote in message
news:2AC2EE71ED54F181...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Dec 17, 2001, 5:32:33 PM12/17/01
to
Luis:

I lied. We've got more problems than that.

ActiveX methods can return the coordinates of only definition points... no
way to get the extras added by curve-fitting without using the old-fashioned
way (entget (entnext etc.)). So mine is technically wrong as well. If we
limit the domain to just LWPolys and Splines, then I can fix your
open/closed situation fast.

Gotta go.....................


--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juh...@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332


"Luis Esquivel" <lu...@slarchitects.com> wrote in message

news:2BA513F017396C1F...@in.WebX.maYIadrTaRb...
> Thanks John,
>
> Actually I been doing more test on this function and found some special
> conditions, here is what I have so far, in case some else wants to help me
> on this.
>
> I do not need for now this specific <function> but never the less, I need
to
> get focus in other kind of stuff right now so here it is...


>
> ;;; sample by Luis Esquivel, December 17, 2001
> ;;; self-intersect
> ;;; return: T or nil
> ;;; note: you must pass a polyline or spline object, no error catching
>
> (defun C:TEST (/ ent)
> (lbx-self-intersect
> (setq ent (car (entsel)))
> )
> )
>

> (defun lbx-self-intersect (ent)
> ;;; / vla objname)


> (vl-load-com)
> (setq vla (vlax-ename->vla-object ent)
> objname (vla-get-objectname vla)
> )
> (if (= "AcDbSpline" objname)
> (progn
> (if (safearray-value
> (vlax-variant-value
> (vla-intersectwith
> vla
> vla
> acExtendNone
> )
> )
> )
> T
> nil
> )
> )
> (progn

> (if (= :vlax-false (vla-get-closed vla))
> (progn
> (if (safearray-value
> (setq intersections


> (variant-value
> (vla-intersectwith vla vla acExtendNone)
> )
> )
> )
> (apply
> '/=
> (list
> (- (/ (length (vlax-safearray->list
> (variant-value (vla-get-coordinates vla))
> )
> )
> 2
> )
> 2
> )

> (/ (length (vlax-safearray->list intersections)) 3)
> )
> )
> )
> )
> (if (safearray-value
> (setq intersections


> (variant-value
> (vla-intersectwith vla vla acExtendNone)
> )
> )
> )
>

> (apply
> '/=
> (list


> (/ (length (vlax-safearray->list
> (variant-value (vla-get-coordinates vla))
> )
> )
> 2
> )

> (/ (length (vlax-safearray->list intersections)) 3)


> )
> )
> )
> )
> )
> )

> )
>
> Still need to verify when a open polyline is selected and has two straight
> segments see image...
>
>


----------------------------------------------------------------------------
----


Tony Tanzillo

unread,
Dec 17, 2001, 7:16:36 PM12/17/01
to
Create a copy of the object, make it closed,
and then try to create a region from it.

If the operation fails, then the reason is most
likely because the object is self-intersecting
(although there are other reasons why it may fail
as well).

"Alfredo Medina" <alme...@hotmail.com> wrote in message
news:3C194CF8...@hotmail.com...

Alfredo Medina

unread,
Dec 18, 2001, 7:24:00 PM12/18/01
to
Tony,

Thank you very much. That is a good idea. I will try it out.

Alfredo Medina

Tony Tanzillo wrote:
>
> Create a copy of the object, make it closed,
> and then try to create a region from it.
>
> If the operation fails, then the reason is most
> likely because the object is self-intersecting
> (although there are other reasons why it may fail
> as well).
>
> "Alfredo Medina" <alme...@hotmail.com> wrote in message
> news:3C194CF8...@hotmail.com...
> > How can I detect through Lisp if a Lwpolyline, Pline or Spline is a
> > self-intersecting entity?
> >

(...)

0 new messages