Radu Iordache Posted February 13, 2023 Posted February 13, 2023 I use a LISP to generate an XML from a DWG in order to use in another program. This LISP works well in AutoCAD but misses something in ProgeCAD. The generated XMLs are nearly identical but the one from ProgeCAD does not contain coordinates of polygons (see below image). Can anyone help me modify the LISP for ex. by generating coordinates by another method that will maybe work in ProgeCAD? (I suspect the problem is at wlax-get Obj 'coordinates line) I am not a LISP programmer, only user. Thank you very much! Comparison image attached LISP attached cgdata.lsp Quote
Steven P Posted February 13, 2023 Posted February 13, 2023 This should also return a list of coordinates: (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 ) Will have a look to see how to fit it into your code 1 Quote
Steven P Posted February 13, 2023 Posted February 13, 2023 and try this, Add the code I posted above into your LISP file and change the cgpoly part for the below, see if that works by taking away the VLA- part (defun cgpoly (/ lst ss i en obj) (and (setq ss (ssget "X" '((0 . "LWPOLYLINE") ; object Name (-4 . "&=") ; bit coded (70 . 1) ; polyline is closed ) ) ) (repeat (setq i (sslength ss)) (setq en (ssname ss (setq i (1- i))) obj (vlax-ename->vla-object en) ) (write-line "<LWPOLYGON>" file) (write-line (strcat "<LAYER>" (vlax-get obj 'Layer) "</LAYER>") file) (write-line (strcat "<HANDLE>" (vlax-get obj 'Handle) "</HANDLE>") file) (write-line (strcat "<AREA>" (rtos (vlax-get obj 'Area) 2 4) "</AREA>") file) ;---- (setq lst (getcoords en)) (setq idx 0) (setq xy "") (repeat (length lst) (setq xy (strcat xy (rtos (car (nth idx lst)) 2 3) " " (rtos (cadr (nth idx lst)) 2 3) ", ")) (setq idx (+ 1 idx)) ) (write-line (strcat "<LOCATION>POLYGON((" (vl-string-trim ", " xy) "))</LOCATION>") file) ;---- (write-line "</LWPOLYGON>" file) ) ) ) 1 Quote
Radu Iordache Posted February 13, 2023 Author Posted February 13, 2023 13 minutes ago, Steven P said: and try this, Add the code I posted above into your LISP file and change the cgpoly part for the below, see if that works by taking away the VLA- part (defun cgpoly (/ lst ss i en obj) (and (setq ss (ssget "X" '((0 . "LWPOLYLINE") ; object Name (-4 . "&=") ; bit coded (70 . 1) ; polyline is closed ) ) ) (repeat (setq i (sslength ss)) (setq en (ssname ss (setq i (1- i))) obj (vlax-ename->vla-object en) ) (write-line "<LWPOLYGON>" file) (write-line (strcat "<LAYER>" (vlax-get obj 'Layer) "</LAYER>") file) (write-line (strcat "<HANDLE>" (vlax-get obj 'Handle) "</HANDLE>") file) (write-line (strcat "<AREA>" (rtos (vlax-get obj 'Area) 2 4) "</AREA>") file) ;---- (setq lst (getcoords en)) (setq idx 0) (setq xy "") (repeat (length lst) (setq xy (strcat xy (rtos (car (nth idx lst)) 2 3) " " (rtos (cadr (nth idx lst)) 2 3) ", ")) (setq idx (+ 1 idx)) ) (write-line (strcat "<LOCATION>POLYGON((" (vl-string-trim ", " xy) "))</LOCATION>") file) ;---- (write-line "</LWPOLYGON>" file) ) ) ) It works!!! Thank you very much! There is only one more difference, the coordinates should be YX (north east). Can you tell me what I should change to achieve this? AutoCAD: <LOCATION>POLYGON((602.734 290.312, 169.906 405.813, 293.918 800.951, 729.178 642.896))</LOCATION> ProgeCAD: <LOCATION>POLYGON((290.312 602.734, 405.813 169.906, 800.951 293.918, 642.896 729.178))</LOCATION> Quote
Radu Iordache Posted February 13, 2023 Author Posted February 13, 2023 1 hour ago, Steven P said: and try this, Add the code I posted above into your LISP file and change the cgpoly part for the below, see if that works by taking away the VLA- part (defun cgpoly (/ lst ss i en obj) (and (setq ss (ssget "X" '((0 . "LWPOLYLINE") ; object Name (-4 . "&=") ; bit coded (70 . 1) ; polyline is closed ) ) ) (repeat (setq i (sslength ss)) (setq en (ssname ss (setq i (1- i))) obj (vlax-ename->vla-object en) ) (write-line "<LWPOLYGON>" file) (write-line (strcat "<LAYER>" (vlax-get obj 'Layer) "</LAYER>") file) (write-line (strcat "<HANDLE>" (vlax-get obj 'Handle) "</HANDLE>") file) (write-line (strcat "<AREA>" (rtos (vlax-get obj 'Area) 2 4) "</AREA>") file) ;---- (setq lst (getcoords en)) (setq idx 0) (setq xy "") (repeat (length lst) (setq xy (strcat xy (rtos (car (nth idx lst)) 2 3) " " (rtos (cadr (nth idx lst)) 2 3) ", ")) (setq idx (+ 1 idx)) ) (write-line (strcat "<LOCATION>POLYGON((" (vl-string-trim ", " xy) "))</LOCATION>") file) ;---- (write-line "</LWPOLYGON>" file) ) ) ) I managed to reverse them by myself. Thanks again for your help, much appreciated! 1 Quote
Steven P Posted February 13, 2023 Posted February 13, 2023 24 minutes ago, Radu Iordache said: I managed to reverse them by myself. Nice! Quote
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.