Radu Iordache Posted March 11, 2023 Share Posted March 11, 2023 The attached lisp selects all polylines in a drawing (open or closed) and writes a coordinate list for each one in a file. I need to modify the lisp so it will do the job for open polylines only. The closed polylines should be filtered out (not included in the output file). Can anybody help? Thanks in advance! coolist.lsp Quote Link to comment Share on other sites More sharing options...
hosneyalaa Posted March 11, 2023 Share Posted March 11, 2023 HI TRY POLYLINE DXF Group code 70 ;;;================================================== (vl-load-com) ; initialization (defun getcoords ( en / coordslst ) (setq coordslst (list)) (setq enlst (entget en)) (foreach x enlst (if (= (car x) 10) (setq coordslst (append coordslst (list (cdr x)))) ) ; end if ) ; end foreach coordslst ) ;;;================================================== (defun c:coolist (/ xml file) (setq fname "D:/coo.xml") (setq file (open fname "w")) (cgpolydesc) (close file) (startapp "notepad.exe" fname) ) ;_ end of defun ;;;================================================== (defun cgpolydesc (/ lst ss i en obj) (and (setq ss (ssget "X" '((0 . "LWPOLYLINE") ; object Name (-4 . "&=") ; bit coded (70 . 1) ; polylines are OPEN OR CLOSED ) ) ) (repeat (setq i (sslength ss)) (setq en (ssname ss (setq i (1- i))) obj (vlax-ename->vla-object en) ) ;---- (setq lst (getcoords en)) (setq idx 0) (setq xy "") (repeat (length lst) (setq xy (strcat xy (rtos (cadr (nth idx lst)) 2 8) "," (rtos (car (nth idx lst)) 2 8) " ")) (setq idx (+ 1 idx)) ) (write-line (strcat (vl-string-trim ", " xy)) file) ;---- ) ) ) ;_ end of defun 'cgpolydesc' ;;;================================================== 1 Quote Link to comment Share on other sites More sharing options...
Radu Iordache Posted March 11, 2023 Author Share Posted March 11, 2023 19 minutes ago, hosneyalaa said: HI TRY POLYLINE DXF Group code 70 ;;;================================================== (vl-load-com) ; initialization (defun getcoords ( en / coordslst ) (setq coordslst (list)) (setq enlst (entget en)) (foreach x enlst (if (= (car x) 10) (setq coordslst (append coordslst (list (cdr x)))) ) ; end if ) ; end foreach coordslst ) ;;;================================================== (defun c:coolist (/ xml file) (setq fname "D:/coo.xml") (setq file (open fname "w")) (cgpolydesc) (close file) (startapp "notepad.exe" fname) ) ;_ end of defun ;;;================================================== (defun cgpolydesc (/ lst ss i en obj) (and (setq ss (ssget "X" '((0 . "LWPOLYLINE") ; object Name (-4 . "&=") ; bit coded (70 . 1) ; polylines are OPEN OR CLOSED ) ) ) (repeat (setq i (sslength ss)) (setq en (ssname ss (setq i (1- i))) obj (vlax-ename->vla-object en) ) ;---- (setq lst (getcoords en)) (setq idx 0) (setq xy "") (repeat (length lst) (setq xy (strcat xy (rtos (cadr (nth idx lst)) 2 8) "," (rtos (car (nth idx lst)) 2 8) " ")) (setq idx (+ 1 idx)) ) (write-line (strcat (vl-string-trim ", " xy)) file) ;---- ) ) ) ;_ end of defun 'cgpolydesc' ;;;================================================== Thanks but 70.1 will select only closed polylines. I need the opposite, to select only the ones that are NOT closed. One way would be to select all of them (by 70.0) and then filter out the closed ones (by 70.1) but I don't know how to do that. I am a lisp user, unfortunately not a programmer. Quote Link to comment Share on other sites More sharing options...
hosneyalaa Posted March 11, 2023 Share Posted March 11, 2023 43 minutes ago, Radu Iordache said: Thanks but 70.1 will select only closed polylines. I need the opposite, to select only the ones that are NOT closed. One way would be to select all of them (by 70.0) and then filter out the closed ones (by 70.1) but I don't know how to do that. I am a lisp user, unfortunately not a programmer. I'm sorry @Radu Iordache look at this Quote Link to comment Share on other sites More sharing options...
Radu Iordache Posted March 11, 2023 Author Share Posted March 11, 2023 35 minutes ago, hosneyalaa said: I'm sorry @Radu Iordache look at this Thank you. I found some ideas there but finaly solved it like this: (defun cgpolydesc (/ lst ss i en obj) (and (setq ss (ssget "X" '((0 . "LWPOLYLINE") ; object Name (-4 . "<NOT") (70 . 1) (-4 . "NOT>"); polylines NOT CLOSED ) ) ) (repeat (setq i (sslength ss)) (setq en (ssname ss (setq i (1- i))) obj (vlax-ename->vla-object en) ) 1 Quote Link to comment Share on other sites More sharing options...
Tsuky Posted March 11, 2023 Share Posted March 11, 2023 (edited) You must prefered the bitwise "&" because you can have the bit typelinegen and closed (70 . 129) (setq ss (ssget "_X" '( (0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 1) (-4 . "NOT>") ) ) ) See the help Edited March 11, 2023 by Tsuky 1 Quote Link to comment Share on other sites More sharing options...
Radu Iordache Posted March 11, 2023 Author Share Posted March 11, 2023 3 hours ago, Tsuky said: You must prefered the bitwise "&" because you can have the bit typelinegen and closed (70 . 129) (setq ss (ssget "_X" '( (0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 1) (-4 . "NOT>") ) ) ) See the help Thanks, done! Quote Link to comment Share on other sites More sharing options...
DAVID_OJEDA Posted March 14, 2023 Share Posted March 14, 2023 (edited) On 11/3/2023 at 9:18, Radu Iordache said: ¡Gracias, listo! ; ; Check for open polylines ; (c) 2009 Lee Mac ; (defun c:GetLwClsd (/ ss) ; Notice that *flag_def* is not localised, as it is a global variable (or *flag_def* (setq *flag_def* "Open")) ;; Set first-time default (initget "Open Closed") ; Only allow these values, allow enter also (setq *flag_def* (cond ((getkword (strcat "\nLooking for [O]pen or [C]losed LWPolylines? <" *flag_def* "> : "))) ;; Either a keyword has been entered, hence set it as the new default (t *flag_def*))) ;; Else use the original default (if (setq ss (ssget "_X" (list (cons 0 "LWPOLYLINE") (cons 8 (getvar "CLAYER")) (cons -4 "<OR") (cons 70 (cond ((eq *flag_def* "Open") 0) (t 1))) (cons 70 (cond ((eq *flag_def* "Open") 128) (t 129))) (cons -4 "OR>")))) (progn (foreach ent (mapcar 'cadr (ssnamex ss)) (setq lay (tblsearch "LAYER" (cdr (assoc 8 (entget ent))))) (if (or (eq 1 (logand 1 (cdr (assoc 70 lay)))) (eq 4 (logand 4 (cdr (assoc 70 lay))))) (ssdel ent ss))) (princ (strcat "\n" (itoa (sslength ss)) " found.")) (sssetfirst nil ss)) (princ "\n<< nothing found >>")) (princ)) (textscr) ; bring text-window to front and inform user (princ "\nSearching LW-Polylines at curent layer. Note: splines, curved fit, and 3D plines will not work\nStart with mit << GetLwClsd >>") Edited March 14, 2023 by DAVID_OJEDA Quote Link to comment Share on other sites More sharing options...
DAVID_OJEDA Posted March 14, 2023 Share Posted March 14, 2023 Test the Lee Mac routine. works great for finding open or closed polylines 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.