Jump to content

Help needed with LISP modification


Recommended Posts

Posted

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

 

comparison.jpg

cgdata.lsp

Posted

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

  • Like 1
Posted

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)
    )
  )
)

 

  • Like 1
Posted
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>

Posted
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!

  • Like 1
Posted
24 minutes ago, Radu Iordache said:

I managed to reverse them by myself.

 

Nice!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...