Autolisp routine to export co ordinate of line to already opened excel file

Autolisp routine to export co ordinate of line to already opened excel file

Anonymous
Not applicable
1,313 Views
7 Replies
Message 1 of 8

Autolisp routine to export co ordinate of line to already opened excel file

Anonymous
Not applicable

Hi All,

 

I am looking for a lisp which will ask for line selection in auto cad model space and will export the all selected line co ordinates to already open excel file.

 

Thanks in advance 🙂

0 Likes
Accepted solutions (1)
1,314 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

Hi all,

 

Could any one please guide me on this?

 

Thanks

0 Likes
Message 3 of 8

patrick_35
Collaborator
Collaborator
Accepted solution

Hi

 

For example

(defun c:test(/ doc ent lin xls wks)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (and (ssget '((0 . "LINE")))
    (progn
      (setq xls (vlax-get-or-create-object "Excel.Application"))
      (or (setq wks (vlax-get xls 'ActiveSheet))
	(vlax-invoke (vlax-get xls 'workbooks) 'Add)
      )
      (setq wks (vlax-get xls 'ActiveSheet)
	    lin 2
      )
      (vlax-put xls 'Visible :vlax-true)
      (vlax-put (vlax-get-property wks 'range "A1") 'value "StartPoint")
      (vlax-put (vlax-get-property wks 'range "B1") 'value "EndPoint")
      (vlax-for ent (setq sel (vla-get-activeselectionset doc))
	(vlax-put (vlax-get-property wks 'range (strcat "A" (itoa lin))) 'value (trans (vlax-get ent 'startpoint) 1 0))
	(vlax-put (vlax-get-property wks 'range (strcat "B" (itoa lin))) 'value (trans (vlax-get ent 'endpoint) 1 0))
	(setq lin (1+ lin))
      )
      (vla-delete sel)
      (mapcar 'vlax-release-object (list wks xls))
      (gc)(gc)
    )
  )
  (vla-endundomark doc)
  (princ)
)
Message 4 of 8

Anonymous
Not applicable

Thank You Very Much 🙂

its working fine

0 Likes
Message 5 of 8

Anonymous
Not applicable

Hi Patrick,

 

Could you please extend a code a bit to give me start point and point "X,Y" co ordinate??

 

I am getting only Start point x co ordinate and end point x co ordinate

 

Thanks in advance for your kind Support

0 Likes
Message 6 of 8

patrick_35
Collaborator
Collaborator

Oh yeah, right


I was too fast, I did not pay attention
The corrected lisp

(defun c:test(/ doc ent lin pts xls wks)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (and (ssget '((0 . "LINE")))
    (progn
      (setq xls (vlax-get-or-create-object "Excel.Application"))
      (or (vlax-get xls 'ActiveSheet)
	(vlax-invoke (vlax-get xls 'workbooks) 'Add)
      )
      (setq wks (vlax-get xls 'ActiveSheet)
	    lin 2
      )
      (vlax-put xls 'Visible :vlax-true)
      (mapcar '(lambda(a b)(vlax-put (vlax-get-property wks 'range a) 'value b)) '("A1" "B1" "C1" "D1") '("X StartPoint" "Y StartPoint" "X EndPoint" "Y EndPoint"))
      (vlax-for ent (setq sel (vla-get-activeselectionset doc))
	(setq pts (trans (vlax-get ent 'startpoint) 1 0))
	(vlax-put (vlax-get-property wks 'range (strcat "A" (itoa lin))) 'value (car pts))
	(vlax-put (vlax-get-property wks 'range (strcat "B" (itoa lin))) 'value (cadr pts))
	(setq pts (trans (vlax-get ent 'endpoint) 1 0))
	(vlax-put (vlax-get-property wks 'range (strcat "C" (itoa lin))) 'value (car pts))
	(vlax-put (vlax-get-property wks 'range (strcat "D" (itoa lin))) 'value (cadr pts))
	(setq lin (1+ lin))
      )
      (vla-delete sel)
      (mapcar 'vlax-release-object (list wks xls))
      (gc)(gc)
    )
  )
  (vla-endundomark doc)
  (princ)
)

@+

0 Likes
Message 7 of 8

Anonymous
Not applicable

Hi Patrick,

 

code is taking longer time with more number of entities, for example if the lines are 60,000 then it is taking more than 30 min,

is it possible to store all values in array and then paste data in excel at single stretch? could you please extend the code?

 

Thanks in Advance

 

0 Likes
Message 8 of 8

patrick_35
Collaborator
Collaborator

Hi

 

It is the number of elements that is very important.
To be faster it is necessary to change language and go for example to vb.net.

 

To test, you can remove the vlax-put just to see the time it takes to retrieve the coordinates of the lines.

 

You should know that visual lisp is faster than autolisp.

 

@+

0 Likes