TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ElpanovEvgeniy on August 08, 2006, 05:59:02 AM
-
If who that interfered with with self-traverses of selfcontained polylines, inform please the information.
Polylines have many the arc segments (thousand) and by hand-carry to find problem places very difficultly...
The idea or a search algorithm for self-traverses Is necessary for their elimination.
Beforehand THANK!
-
Hi
Here's a routine which returns all self-intersection points of a lwpolyline, if it can help ...
((lambda (/ ent vtx lst ent rslt)
(setq ent (car (entsel "\nSelect the pline: "))
vtx (mapcar
'(lambda (pt)
(trans
(list (car pt) (cadr pt) (cdr (assoc 38 (entget ent))))
ent
0
)
)
(mapcar
'cdr
(vl-remove-if-not
'(lambda (x) (= (car x) 10))
(entget ent)
)
)
)
lst (vlax-invoke
(vlax-ename->vla-object ent)
'Explode
)
)
(while (cdr lst)
(repeat (1- (setq n (length lst)))
(if
(setq int (vlax-invoke
(car lst)
'IntersectWith
(nth (setq n (1- n)) lst)
acExtendNone
)
)
(setq rslt (cons int rslt))
)
)
(vla-delete (car lst))
(setq lst (cdr lst))
)
(vla-delete (car lst))
(setq
rslt (vl-remove-if
'(lambda (x) (vl-some '(lambda (y) (equal x y 1e-9)) vtx))
rslt
)
)
)
)
Edit : Take care of the behavior of IntersectWith method in UCS not parallel with the WCS.
-
Hey Evgeniy;
Need more input - what it is the purpose for this routine?, a drawing sample , an image - etc. (or maybe just me)
-
Hey Evgeniy;
Need more input - what it is the purpose for this routine?, a drawing sample , an image - etc. (or maybe just me)
This Lwpolyline have Self intersections...
-
Sorry, I certainly didn't have understood what you meant with self intersections, I tried the routine I posted on your lwpolyline, it takes a while but don't return any intersection point.
-
Sorry, I certainly didn't have understood what you meant with self intersections, I tried the routine I posted on your lwpolyline, it takes a while but don't return any intersection point.
Excuse, I have badly explained a problem...
-
This Lwpolyline have Self intersections...
I ran some tests and does not - how do you found that out?
Here is a very simple test (in your case for the complexity of the polyline it takes forever doing it in lisp)
Make a selection of the polyline, extract the number of coordinates (vertices) and do a self intersection using the same object (polyline) and extract the number of intersections if this number is greater than the vertices - it's self-intersect
;; return
;; T = self-intersect
;; nil = normal
(defun c:tst ()
(setq ename (car (entsel)))
(setq obj (vlax-ename->vla-object ename))
(setq ints (vlax-safearray->list
(vlax-variant-value
(vla-intersectwith obj obj acExtendNone))))
(> (/ (length ints) 3)
(/ (length (vlax-get obj 'coordinates)) 2)))
-
I ran some tests and does not - how do you found that out?
Here is a very simple test (in your case for the complexity of the polyline it takes forever doing it in lisp)
Make a selection of the polyline, extract the number of coordinates (vertices) and do a self intersection using the same object (polyline) and extract the number of intersections if this number is greater than the vertices - it's self-intersect
;; return
;; T = self-intersect
;; nil = normal
(defun c:tst ()
(setq ename (car (entsel)))
(setq obj (vlax-ename->vla-object ename))
(setq ints (vlax-safearray->list
(vlax-variant-value
(vla-intersectwith obj obj acExtendNone))))
(> (/ (length ints) 3)
(/ (length (vlax-get obj 'coordinates)) 2)))
(/ (length ints) 3) = 1327
(/ (length (vlax-get obj 'coordinates)) 2) = 1898
Command: _region
Select objects: Specify opposite corner: 1 found
Select objects:
1 loop extracted.
1 loop rejected.
Self intersections : 1 loop.
0 Regions created.
-
I need to look for some old code of mine.... I remember that I wrote a function for this, I thought what I posted was right.... (lately not true = excuse 12344 = age) :lol:
-
Here is an old function - but for the type of complexity of your pline it will take a lot - so wait be patience and have a coffee:
Found here:
http://discussion.autodesk.com/thread.jspa?messageID=1118437
;;; 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)
)
)
)
)
)
)
)
-
Evgeniy;
What will be the purpose of this function/routine?
Do you want to select all the objects and generate a closed polyline?
Thanks.
-
Is this problem solved ?
I think Acad 'region' command can't accept this Lwpolyline , just like can't build the boundary though 'Bpoly' method , but don't be sure .
Isn't there cross-itself points in it ? At least I can not found now .
-
Hi all,
I'm wondering if there is a way of correcting this problem with self intersecting polylines.
I have exploded the sample drawings polyline & then used overkill to remove duplicate objects, one found & erased.
I then recreated the poly by join - all - which works to make a polyline BUT it is still self intersecting.
Any help would be appreciated.
Thanks in advance
JohnB