KevinPerez27 Posted April 10 Share Posted April 10 I need a Lisp Routine to find in a set of selected closed polylines, the ones that are empty inside, im using Autocad 2021, The information of the closed polylines using the List comand on them are the following: Command: LIST 1 found LWPOLYLINE Layer: "Mylayer" Space: Model space Handle = 2c3 Closed Constant width 0.0000 area 300.5426 perimeter 77.3595 at point X=4707.3509 Y=1402.3153 Z= 0.0000 at point X=4735.6706 Y=1402.3153 Z= 0.0000 at point X=4728.8578 Y=1412.4497 Z= 0.0000 at point X=4715.4995 Y=1414.5833 Z= 0.0000 at point X=4703.6106 Y=1412.9831 Z= 0.0000 My test drawing its in the following image, there are 2 closed polylines with a block inside and another empty, i need to select the 3 closed polylines and after the execution of the routine, select the one empty I need the final result something like this Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 10 Share Posted April 10 You can use SSGET "WP" PTS where pts are a list of pts taken from your pline. It will return nil if nothing inside. You need the extra point to make a closed pline. (setq plent (entsel "\nPick rectang")) (if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))))) (setq co-ord (cons (car co-ord) co-ord)) Note if you have arcs in the pline need extra code as bulge will not be considered. 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted April 11 Share Posted April 11 11 hours ago, BIGAL said: Note if you have arcs in the pline need extra code as bulge will not be considered. This is what you want then... (adding the returned list to (ssget "WP" as above) (defun c:Poly2Chords_List ( / MyEnt MyChords ModifiedEnt) (defun mAssoc ( key lst / result ) (foreach x lst (if (= key (car x)) (setq result (cons (cdr x) result)) ) ) (reverse result) ) (setq MyEnt (entget (car (entsel)))) ; Select Polyline / Line Entity (setq MyChords (getreal "Chords in 360 degrees: ")) (setq ModifiedEnt (PolyChords MyEnt MyChords)) (princ (mAssoc 10 ModifiedEnt)) ) (defun PolyChords ( MyEnt vertexin360 / vertexin360 NewEnt acount p1 p2 open Open b MyBulge MyBulgeC StartAng EndAng MyRadius ccw Chordangle Chords ChordCount NewPt) (princ "OK ") ;;Add in start / end thickness 40, 41 ;;Add in if arc selected do conversion ;;;;; Sub Functions (defun LM:Bulge->Arc ( p1 p2 b / c r ) ;; Refer to Lee Mac Website ;;Gives Arc definition from pline Bulge (setq r (/ (* (distance p1 p2) (1+ (* b b))) 4 b) c (polar p1 (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b)))) r) ) (if (minusp b) (list c (angle c p2) (angle c p1) (abs r)) (list c (angle c p1) (angle c p2) (abs r)) ) ) (defun LM:BulgeCenter ( p1 p2 b ) ;; Refer to Lee Mac Website ;;Gives Arc definition from pline Bulge (polar p1 (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b)))) (/ (* (distance p1 p2) (1+ (* b b))) 4 b) ) ) (defun mAssoc ( key lst / result ) ;;Lee Mac: https://www.cadtutor.net/forum/topic/27914-massoc-implementations/ (foreach x lst (if (= key (car x)) (setq result (cons (cdr x) result)) ) ) (reverse result) ) ;;;;; End Sub Functions ;;Set Variables ;; (setq vertexin360 180) ; Number of chords in full circle, 360: every 1 degree (setq NewEnt (list)) ; New List for the modified entity definition (setq acount 0) ; A counter ;;Find curves '42' (while (< acount (length MyEnt)) (if (and (= (car (nth acount MyEnt)) 42) ; if dxf code 42 (/= (cdr (nth acount MyEnt)) 0) ; and is a value: a bulge! ) ; end and (progn (setq p1 (cdr (nth (- acount 3) MyEnt))) ; Start Coordinate (setq p2 (nth (+ acount 2) MyEnt)) ; End Coordinate as dxf code (if (= (car p2) 210) ; If P2 is "210" and not a "10" - end of polyline (if (= (cdr (assoc 70 MyEnt)) 1) (progn ; Closed Polyline (setq p2 (assoc 10 MyEnt)) ; Set end coordinate to start coordinate (setq open nil) ) ; end progn (progn ;Open PolyLine, end of polyline (setq Open "Open") ) ; end progn ) ; end if closed / open ) ; end if 210 (setq p2 (cdr p2)) ; End Coordinate (setq b (cdr (nth acount MyEnt))) ; Bulge (if (= Open "Open") ; If next point is '210' () ; End of chords (progn ; Calculate Chords (setq MyBulge (LM:Bulge->Arc p1 p2 b)) ; Bulge as arc (setq MyBulgeC (LM:BulgeCenter p1 p2 b) ) ; Bulge Centre (setq StartAng (nth 1 MyBulge)) ; start angle centre to point (setq EndAng (nth 2 MyBulge)) ; End angle centre to point (setq MyRadius (nth 3 MyBulge)) ; Bulge radius (if (< 0 b)(setq ccw 1)(setq ccw -1)) ; clockwise / anticlockwise (setq Chordangle (/ (* 4 (atan b))) ) (setq Chords (* ( / Chordangle (/ (* 2 pi) vertexin360)) ccw) ) ; point every nth degree ; (if (> Chords vertexin360) ;;Check number of chords isn't too big: TL, TR 'corners'. Not needed? ; (progn ; (setq Chordangle (+ (- (cadr MyBulge) (caddr MyBulge)) (* 1 pi)) ) ; (setq Chords (/ Chordangle (/ (* 2 pi) vertexin360) )) ; point every x degrees ; )) ; end progn ; end if (setq ChordCount 1) (while (< ChordCount Chords) (if (= ccw 1) (setq NewPt (polar MyBulgeC (+ (* (/ (* 2 pi) vertexin360) ChordCount) StartAng) MyRadius) ) (setq NewPt (polar MyBulgeC (- EndAng (* (/ (* 2 pi) vertexin360) ChordCount) ) MyRadius) ) ) (setq NewEnt (append NewEnt (list (cons 42 0)) ) ) ; bulge value: 0 (setq NewEnt (append NewEnt (list (cons 91 0)) ) ) ; Vertex Identifier (setq NewEnt (append NewEnt (list (cons 10 NewPt)) )) ; Point (setq NewEnt (append NewEnt (list (cons 40 0)) ) ) ; Start width (setq NewEnt (append NewEnt (list (cons 41 0)) ) ) ; end width (setq ChordCount (+ ChordCount 1)) ) ; end while ) ; end progn ) ; end if Open (end of line) ) ; end progn (progn (setq NewEnt (append NewEnt (list (nth acount MyEnt)) ) ) ; Add other DXF codes to NewEnt listing ) ; end progn ) ; end if '42' (setq acount (+ acount 1)) ) ; end while length MyEnt (setq NewEnt (subst (cons 90 (length (mAssoc 10 NewEnt))) (assoc 90 NewEnt) NewEnt )) ; update number of verticies ;;add in 70 for continuos line types NewEnt ; return new entity definition ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.