Lisp to export coordinates of a selected lines from Autocad to excel sheet.

Lisp to export coordinates of a selected lines from Autocad to excel sheet.

pramodrajpandit123
Contributor Contributor
7,867 Views
9 Replies
Message 1 of 10

Lisp to export coordinates of a selected lines from Autocad to excel sheet.

pramodrajpandit123
Contributor
Contributor

Currently I select the the lines then from list("Li") ,I copy the coordinates and paste it in text file.As this method is really cumbersome .Is there any lisp/script available to export the coordinates from SELECTED lines from Autocad i.e (X1,Y1,Z1,X2,Y2,Z2)--(X-start point ,Y-Startpoint,Z-Startpoint,X-End point,Y-End point,Z-Endpoint) to currently opened Excel file.

As i am new to lisp & learning it , i could not get an idea on how to build such lisp.

0 Likes
Accepted solutions (1)
7,868 Views
9 Replies
Replies (9)
Message 2 of 10

pbejse
Mentor
Mentor

@pramodrajpandit123 wrote:

...Is there any lisp/script available to export the coordinates from SELECTED lines...  to currently opened Excel file.


Why an opened excel file? You can direct the lisp program to "append" a csv file and copy those to the "opened Excel.

 


@pramodrajpandit123 wrote:

As i am new to lisp & learning it , i could not get an idea on how to build such lisp.


You;re trying to learn right?.. so start with this.  Let me type that for you... <-- gems from this forum


-Beggars cant be choosers-

 

 

0 Likes
Message 3 of 10

Sea-Haven
Mentor
Mentor

This is what you need as a start, it has been around for a long time I am not going to go into the details about how to use. Opens a excel and can take a variable value and put in a cell.

 

You could write a lisp that makes a csv result Line,x1,y1,x2,y2,layer copies to clipboard then you go to excel and paste in a cell excel macro pulls apart placing in correct cells like A1 B2 C1 D1 E1 F1 I dont have a VBA csv to 1 cell if some one has then may be easy. cell row col = array (x)

 

 

Message 4 of 10

Sea-Haven
Mentor
Mentor

Thought would have a go at a excel macro for anyone paste a string into A1 at least 4 words sperated by a space. This is a test.

 

Sub String_To_Array()
 
Sheets("Sheet1").Activate

 Dim StringValue As String
 StringValue = Cells(1, 1).Value
 
' MsgBox StringValue
 
 Dim SingleValue() As String
 
 SingleValue = Split(StringValue, " ")

' MsgBox SingleValue(0)
Cells(1, 2).Value = SingleValue(0)
Cells(1, 3).Value = SingleValue(1)
Cells(1, 4).Value = SingleValue(2)
Cells(1, 5).Value = SingleValue(3)

End Sub

 

Message 5 of 10

pramodrajpandit123
Contributor
Contributor

I'll work on the lisp ..Thanks !!

0 Likes
Message 6 of 10

pramodrajpandit123
Contributor
Contributor

The VBA is working great but i am confused on how the lisp works..Can you please give an idea on screencast on how the lisp works ?

0 Likes
Message 7 of 10

Sea-Haven
Mentor
Mentor
Accepted solution

This has no error checks and is set for a line select but can be made into other objects etc.

 

(defun c:test ( / str ent)
(vl-load-com)
(setq ent(entget (car (entsel "\nPick a line"))))
(setq end (cdr (assoc 11 ent)))
(setq start (cdr (assoc 11 ent)))
(setq str (strcat 
          (rtos (nth 0 start) 2 2) " " (rtos (nth 1 start) 2 2) " " (rtos (nth 2 start) 2 2) " "
          (rtos (nth 0 end) 2 2) " " (rtos (nth 1 end) 2 2) " " (rtos (nth 2 end) 2 2)
          )
)
(vlax-invoke
	(vlax-get
		(vlax-get (setq 2ClipB (vlax-create-object "htmlfile"))
			'ParentWindow
		) 'ClipBoardData )  'SetData "Text" str
)
(alert "paste into excel A1")
(princ)
)
Message 8 of 10

pramodrajpandit123
Contributor
Contributor

This lisp and VBA combined basically solves my problem but how can i select multiple lines at once and get their coordinates all at excel?

0 Likes
Message 9 of 10

pbejse
Mentor
Mentor

Refer to post # 2

 

Message 10 of 10

Sea-Haven
Mentor
Mentor

Like Pbe just change the code in my post from copying to clipboard to write file str. Just google writing to file.