The data associated with an entity selected with the Window, WPolygon, Crossing, or CPolygon method is the integer ID of the polygon that selected the entity. It is up to the application to associate the polygon identifiers and make the connection between the polygon and the entities it selected. For example, the following returns an entity selected by Crossing (note that the polygon ID is –1): Command: (ssnamex ss4 0)
((3 <Entity name: 1d62d60> 0 -1) (-1 (0 (-1.80879 8.85536 0.0)) (0 (13.4004 8.85536 0.0)) (0 (13.4004 1.80024 0.0)) (0 (-1.80879 1.80024 0.0))))
--- my first approach could be to glue all the lines that are collinear, based on a gap separation, then from there generate the closed boundaries.
(defun c:test ( / sel )
(if (setq sel (ssget "_+.:E:S:L" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
(splitpoly (ssname sel 0))
)
(princ)
)
(defun splitpoly ( ent / *error* are col enx lin lst mxa mxp new nwp ply pnt reg tmp val var vec vtx )
(defun *error* ( msg )
(mapcar 'setvar var val)
(LM:endundo (LM:acdoc))
(if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
(princ (strcat "\nError: " msg))
)
(princ)
)
(LM:startundo (LM:acdoc))
(setq col 0
var '(cmdecho peditaccept)
val (mapcar 'getvar var)
enx (entget ent)
vtx (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx))
)
(mapcar 'setvar var '(0 1))
(if (= 1 (logand 1 (cdr (assoc 70 enx))))
(setq vtx (cons (last vtx) vtx))
)
(while (cadr vtx)
(setq tmp (list (car vtx) (cadr vtx)))
(foreach x (setq vtx (cdr vtx))
(if (LM:collinear-p x (car tmp) (cadr tmp))
(setq tmp (cons x tmp))
)
)
(setq lst (cons tmp lst) tmp nil)
)
(foreach x lst
(setq vec (mapcar '- (car x) (cadr x))
lin
(append lin
(mapcar
'(lambda ( a b )
(vlax-ename->vla-object
(entmakex (list '(0 . "LINE") (cons 10 a) (cons 11 b)))
)
)
(setq x
(vl-sort x
'(lambda ( a b )
(< (caddr (trans a ent vec))
(caddr (trans b ent vec))
)
)
)
)
(cdr x)
)
)
)
)
(foreach obj
(setq reg
(vlax-invoke
(vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
'addregion lin
)
)
(command "_.pedit" "_m")
(apply 'command (mapcar 'vlax-vla-object->ename (vlax-invoke obj 'explode)))
(command "" "_j" "" "")
(vla-delete obj)
(setq ply (entlast)
vtx (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ply)))
new (list (cadr vtx) (car vtx))
vtx (cddr vtx)
)
(while (setq pnt (car vtx))
(setq vtx (cdr vtx))
(if (LM:collinear-p pnt (car new) (cadr new))
(setq new (cons pnt (cdr new)))
(setq new (cons pnt new))
)
)
(setq new (reverse new))
(while (LM:collinear-p (car new) (cadr new) (last new))
(setq new (cdr new))
)
(setq nwp
(entmakex
(append
(list
'(000 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
(cons 90 (length new))
'(070 . 1)
(cons 62 (setq col (1+ col)))
)
(mapcar '(lambda ( p ) (cons 10 p)) new)
)
)
)
(if (< mxa (setq are (vla-get-area (vlax-ename->vla-object ply))))
(setq mxa are
mxp nwp
)
)
(entdel ply)
)
(foreach l lin (vla-delete l))
(entdel ent)
(entdel mxp)
(*error* nil)
(princ)
)
;; Collinear-p - Lee Mac
;; Returns T if p1,p2,p3 are collinear
(defun LM:Collinear-p ( p1 p2 p3 )
( (lambda ( a b c )
(or
(equal (+ a b) c 1e-3)
(equal (+ b c) a 1e-3)
(equal (+ c a) b 1e-3)
)
)
(distance p1 p2) (distance p2 p3) (distance p1 p3)
)
)
;; Start Undo - Lee Mac
;; Opens an Undo Group.
(defun LM:startundo ( doc )
(LM:endundo doc)
(vla-startundomark doc)
)
;; End Undo - Lee Mac
;; Closes an Undo Group.
(defun LM:endundo ( doc )
(while (= 8 (logand 8 (getvar 'undoctl)))
(vla-endundomark doc)
)
)
;; Active Document - Lee Mac
;; Returns the VLA Active Document Object
(defun LM:acdoc nil
(eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
(LM:acdoc)
)
(vl-load-com) (princ)
(vl-sort x
(lambda ( a b )
(< (caddr (trans a ent vec))
(caddr (trans b ent vec))
)
)
)
^
just tried your routine Lee and getting (A2014):
Command: TEST
Select objects:
Error: bad function: #<USUBR @00000000340ffac0 -lambda->; reset after error
breaks here:Quote(vl-sort x
(lambda ( a b )
(< (caddr (trans a ent vec))
(caddr (trans b ent vec))
)
)
)
can't do more - I lost my lsp powers many moons ago.... :-(
Command: TEST
Select objects:
Yes or No, please.
; quit after error
Convert Lines, Arcs and Splines to polylines [Yes/No]? <Y> *Cancel*
Select polyline or [Multiple]: *Cancel*
Command: *Cancel*
(command "_.pedit" "_m")
(apply 'command (mapcar 'vlax-vla-object->ename (vlax-invoke obj 'explode)))
(command "" "_j" "" "") ;;; <<== this line
yep --- has some more (appears to) --- :)QuoteCommand: TEST
Select objects:
Yes or No, please.
; quit after error
Convert Lines, Arcs and Splines to polylines [Yes/No]? <Y> *Cancel*
Select polyline or [Multiple]: *Cancel*
Command: *Cancel*
breaks here:Quote(command "_.pedit" "_m")
(apply 'command (mapcar 'vlax-vla-object->ename (vlax-invoke obj 'explode)))
(command "" "_j" "" "") ;;; <<== this line
But I see that does the job --- Good!
(defun c:lins2lws ( / plintav-ss big ent i li livlalst ms pea pl qaf reg s ss tmp tot )
(defun plintav-ss ( ss / intersobj1obj2 LM:Unique AT:GetVertices _reml member-fuzz add_vtx
sslpl sshpl i ent n ent1 ss-ent1 k ent2 intpts intptsall pl plpts restintpts par )
(vl-load-com)
(defun intersobj1obj2 ( obj1 obj2 / coords pt ptlst )
(if (eq (type obj1) 'ENAME) (setq obj1 (vlax-ename->vla-object obj1)))
(if (eq (type obj2) 'ENAME) (setq obj2 (vlax-ename->vla-object obj2)))
(setq coords (vl-catch-all-apply 'vlax-safearray->list (list (vl-catch-all-apply 'vlax-variant-value (list (vla-intersectwith obj1 obj2 AcExtendNone))))))
(if (vl-catch-all-error-p coords)
(setq ptlst nil)
(repeat (/ (length coords) 3)
(setq pt (list (car coords) (cadr coords) (caddr coords)))
(setq ptlst (cons pt ptlst))
(setq coords (cdddr coords))
)
)
ptlst
)
(defun LM:Unique ( lst )
(if lst (cons (car lst) (LM:Unique (vl-remove (car lst) (cdr lst)))))
)
(defun AT:GetVertices ( e / p l )
(LM:Unique
(if e
(if (eq (setq p (vlax-curve-getEndParam e)) (fix p))
(repeat (setq p (1+ (fix p)))
(setq l (cons (vlax-curve-getPointAtParam e (setq p (1- p))) l))
)
(list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e))
)
)
)
)
(defun _reml ( l1 l2 / a n ls )
(while
(setq n nil
a (car l2)
)
(while (and l1 (null n))
(if (equal a (car l1) 1e-8)
(setq l1 (cdr l1)
n t
)
(setq ls (append ls (list (car l1)))
l1 (cdr l1)
)
)
)
(setq l2 (cdr l2))
)
(append ls l1)
)
(defun member-fuzz ( expr lst fuzz )
(while (and lst (not (equal (car lst) expr fuzz)))
(setq lst (cdr lst))
)
lst
)
(defun add_vtx ( obj add_pt ent_name / bulg sw ew )
(vla-GetWidth obj (fix add_pt) 'sw 'ew)
(vla-addVertex
obj
(1+ (fix add_pt))
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray vlax-vbdouble (cons 0 1))
(list
(car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
(cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
)
)
)
)
(setq bulg (vla-GetBulge obj (fix add_pt)))
(vla-SetBulge obj
(fix add_pt)
(/
(sin (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
(cos (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
)
)
(vla-SetBulge obj
(1+ (fix add_pt))
(/
(sin (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
(cos (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
)
)
(vla-SetWidth obj (fix add_pt) sw (+ sw (* (- ew sw) (- add_pt (fix add_pt)))))
(vla-SetWidth obj (1+ (fix add_pt)) (+ sw (* (- ew sw) (- add_pt (fix add_pt)))) ew)
(vla-update obj)
)
(setq sslpl (ssadd) sshpl (ssadd))
(setq i -1)
(while (setq ent (ssname ss (setq i (1+ i))))
(if (eq (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
(progn
(entupd ent)
(vla-update (vlax-ename->vla-object ent))
(ssadd ent sslpl)
)
)
(if (eq (cdr (assoc 0 (entget ent))) "POLYLINE")
(ssadd ent sshpl)
)
)
(setq i -1)
(while (setq ent (ssname sshpl (setq i (1+ i))))
(command "_.convertpoly" "l" ent "")
(entupd ent)
(vla-update (vlax-ename->vla-object ent))
(ssadd ent sslpl)
)
(repeat (setq n (sslength ss))
(setq ent1 (ssname ss (setq n (1- n))))
(setq ss-ent1 (ssdel ent1 ss))
(repeat (setq k (sslength ss-ent1))
(setq ent2 (ssname ss-ent1 (setq k (1- k))))
(setq intpts (intersobj1obj2 ent1 ent2))
(setq intptsall (append intpts intptsall))
)
)
(setq i -1)
(while (setq pl (ssname sslpl (setq i (1+ i))))
(setq plpts (AT:GetVertices pl))
(setq restintpts (_reml intptsall plpts))
(foreach pt restintpts
(if
(and
(not (member-fuzz pt plpts 1e-6))
(setq par (vlax-curve-getparamatpoint pl pt))
)
(add_vtx (vlax-ename->vla-object pl) par pl)
)
)
)
(setq i -1)
(while (setq ent (ssname sshpl (setq i (1+ i))))
(command "_.convertpoly" "h" ent "")
)
(princ)
)
(vl-load-com)
(setq ms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(setq tot 0.0)
(setq pea (getvar 'peditaccept))
(setq qaf (getvar 'qaflags))
(setvar 'peditaccept 1)
(setvar 'qaflags 1)
(setq ss (ssget "_X" '((0 . "LINE") (8 . "NEW"))))
(command "_.pedit" "_m" ss)
(while (> (getvar 'cmdactive) 0) (command ""))
(setq ss (ssget "_X" '((0 . "LWPOLYLINE") (8 . "NEW"))))
(plintav-ss ss)
(setq ss (ssget "_X" '((0 . "LWPOLYLINE") (8 . "NEW"))))
(command "_.explode" ss)
(while (> (getvar 'cmdactive) 0) (command ""))
(setq ss (ssget "_P"))
(setq i -1)
(while (setq li (ssname ss (setq i (1+ i))))
(setq livlalst (cons (vlax-ename->vla-object li) livlalst))
)
(setq reg (vlax-invoke ms 'AddRegion livlalst))
(foreach r reg
(setq ent (entlast))
(command "_.pedit" "_m")
(apply 'command (mapcar 'vlax-vla-object->ename (vlax-invoke r 'explode)))
(command "" "_j" "" "")
(if
(and
(not (eq ent (setq ent (entlast))))
(= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
)
(progn
(setq tmp (vlax-curve-getarea ent)
tot (+ tot tmp)
)
(if (< (car big) tmp)
(setq big (list tmp ent))
)
)
)
(vla-delete r)
)
(if (equal (car big) (/ tot 2.0) 1e-3) ;; Gian Paolo Cattaneo
(entdel (cadr big))
)
(foreach obj livlalst (vla-delete obj))
(setq ss (ssget "_X" '((0 . "LWPOLYLINE") (8 . "NEW"))))
(setq i -1)
(while (setq pl (ssname ss (setq i (1+ i))))
(command "_.explode" pl)
(while (> (getvar 'cmdactive) 0) (command ""))
(setq s (ssget "_P"))
(command "-overkill" "_p")
(while (> (getvar 'cmdactive) 0) (command ""))
(command "_.pedit" "_m" "_p" "" "_j" "" "")
(entmod (subst (cons 8 lay) (assoc 8 (entget (entlast))) (entget (entlast))))
)
(setvar 'clayer lay)
(command "_.-purge" "_LA" "NEW" "_N")
(while (> (getvar 'cmdactive) 0) (command ""))
(setvar 'peditaccept pea)
(setvar 'qaflags qaf)
(setq lay nil)
(princ)
)
(defun c:splitlw ( / *error* a ent i k pl ss v vl vv )
(vl-load-com)
(defun *error* ( msg )
(if msg (prompt msg))
(princ)
)
;;;----------------------------------- main routine -----------------------------------;;;
(command "_.undo" "_BE")
(setq pl (car (entsel "\nPick closed LWPOLYLINE polygon in WCS...")))
(setq lay (cdr (assoc 8 (entget pl))))
(if (not (tblsearch "LAYER" "NEW"))
(progn
(command "_.layer" "_m" "NEW")
(while (> (getvar 'cmdactive) 0) (command ""))
)
(progn
(alert "Purge layer \"NEW\" which is used in this routine and restart routine again - quitting...")
(exit)
)
)
(entmod (subst (cons 8 "NEW") (assoc 8 (entget pl)) (entget pl)))
(setq vl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (eq (car x) 10)) (entget pl))))
(if (not (equal (car vl) (last vl) 1e-6)) (setq vl (reverse (cons (car vl) (reverse vl)))))
(setq k -1)
(foreach p1 (setq v (append vl (cdr vl)))
(setq vv (append vl (cdr vl)))
(setq k (1+ k))
(if (nth (1+ k) vv) (setq a (angle p1 (nth (1+ k) vv))))
(foreach p2 (repeat (1+ k) (setq vv (cdr vv)))
(if (equal a (angle p1 p2) 1e-6)
(entmake (list '(0 . "LINE") (cons 8 "NEW") (cons 10 p1) (cons 11 p2)))
)
)
)
(command "_.explode" pl)
(while (> (getvar 'cmdactive) 0) (command ""))
(setq ss (ssget "_X" '((0 . "LINE") (8 . "NEW"))))
(setq i -1)
(while (setq ent (ssname ss (setq i (1+ i))))
(if (equal (cdr (assoc 10 (entget ent))) (cdr (assoc 11 (entget ent))) 1e-6)
(entdel ent)
)
)
(setq ss (ssget "_X" '((0 . "LINE") (8 . "NEW"))))
(command "_.select" ss)
(while (> (getvar 'cmdactive) 0) (command ""))
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "-overkill\np\n\n\n")
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "(c:lins2lws)\n")
(alert "For \"UNDO\" - type \"UNDO\" \"B\"")
(princ)
)
splitcllw-boundaryextensions.lsp updated... Now it uses plintav-new.lsp from PLINETOOLS from link posted above... Tell me if now something's wrong...
M.R.
Hi, have you tried splitcllw-boundaryextensions.lsp & plintav-new.lsp ? It worked well in the time routine was written with my tests... Make sure Lwpoly dont have bulges and that edges are concave (not convex)...
Select objects:
24 found
bad argument type: 2D/3D point: nil
Hi, according to your picture, routine did the job for what was written... I dont know why it throwed an error and I dont know what do you want to achieve... Try debugging an error... I dont have currently PC and I am typing this from my phone so I cant help you much more... If in routine was written (c:plintav), then I suppose it may work as well and without plintav-new... If you want instead to get splitting of lwpoly shown at right of picture, you should use code posted at prevoius page (splitcllw)... I hope you can manage to accomplish desired task with yor knowledge... If something is struggling you, just ask... I think you will get desired answer as well good and without my help... Kind regards, M.R.
Maybe this way: