Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Polyline details to excel lisp

11 REPLIES 11
Reply
Message 1 of 12
symoin
423 Views, 11 Replies

Polyline details to excel lisp

Help me with a lisp code to extract the coordinates of a polyline, distance between the vertices, deflection angle with left or right and a cumulative length from start to each of the vertices. .I want an excel file file where it will show point id(Sl.No.), easting, Northing, distance between the vertices, angle and then the cumulative distance as station. each row for the details between 2 vertices. i need the result in an excel file in the same folder and should ask for he file name. if you are not sure then ask me questions

11 REPLIES 11
Message 2 of 12
Kent1Cooper
in reply to: symoin

As a start, post a [small] sample drawing with a couple of typical Polylines, and a sample output file with the information in the format you're after.

Kent Cooper, AIA
Message 3 of 12
symoin
in reply to: Kent1Cooper

sample drawing and csv  for the headers only attached

Message 4 of 12
Sea-Haven
in reply to: symoin

Two functions required label a point and then send to excel, for me I go direct to Excel. 

 

This is very much a 1st go as need to work out the deflection angle. 552 rows. The make Excel with a name can be added. Its Christmas so limited time.

 

Do you want a table in dwg as well ?

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/polyline-details-to-excel-lisp/td-p/13227556
; 1st go By AlanH DEC 2024

(defun c:pl2excel ( / plent obj num myxl row)
;;	Thanks to fixo			;;
;;   = Set Excel cell text =    ;;
;;				;;
(defun xlsetcelltext ( row column text)
(setq cells (vlax-get-property  (vlax-get-property myxl "ActiveSheet") "Cells"))
  (vl-catch-all-apply
    'vlax-put-property
    (list cells 'Item row column
	(vlax-make-variant (vl-princ-to-string text) vlax-vbstring)))
)

(setq plent (entsel "\nPick Pline"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))))
(progn (alert "you have not picked a pline will now exit")(exit))
)
(setq obj (vlax-ename->vla-object (car plent)))


(or (setq myxl (vlax-get-object "Excel.Application"))
    (setq myxl (vlax-get-or-create-object "excel.Application"))
)
(vla-put-visible myXL :vlax-true)
(vlax-put-property myxl 'ScreenUpdating :vlax-true)
(vlax-put-property myXL 'DisplayAlerts :vlax-true)
(vlax-invoke-method (vlax-get-property myXL 'WorkBooks) 'Add)

(setq row 1)

(xlsetcelltext row 1 "Point ID")
(xlsetcelltext row 2 "Easting")
(xlsetcelltext row 3 "Northing")
(xlsetcelltext row 4 "Distance")
(xlsetcelltext row 5 "Deflection Angle")
(xlsetcelltext row 6 "Station")

(setq num 0)
(foreach pt co-ord
  (setq row (1+ row))
  (command "text" pt 2.5 0.0 (setq num (1+ num)))
  (xlsetcelltext row 1 (rtos num 2 0))
  (xlsetcelltext row 2 (car pt))
  (xlsetcelltext row 3 (cadr pt))
  (setq dist (vlax-curve-getdistatpoint obj pt))
  (xlsetcelltext row 4 (rtos dist 2 1))
)

(princ)
)

 

 

 

 

 

Message 5 of 12
symoin
in reply to: Sea-Haven

symoin_0-1735059683217.png

Thanks for your time in this festival season. I request further modification to this code. it should add the distance between the 2 vertices and deflection Angle and here what is shown as distance should go to station column (cumulative distance).

Message 6 of 12
Sea-Haven
in reply to: symoin

As I said 1st version bit busy at moment. Its christmas.

Message 7 of 12
Sea-Haven
in reply to: symoin

Give this a try and please let me know if you have any questions or changes needed.

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/polyline-details-to-excel-lisp/td-p/13227556
; 1st go By AlanH DEC 2024

(defun rtd (a)
(/ (* a 180.0) pi)
)

(defun c:pl2excel ( / plent obj num myxl row oldsnap dist ang)
;;	Thanks to fixo			;;
;;   = Set Excel cell text =    ;;
;;				;;
(defun xlsetcelltext ( row column text / cells )
(setq cells (vlax-get-property  (vlax-get-property myxl "ActiveSheet") "Cells"))
  (vl-catch-all-apply
    'vlax-put-property
    (list cells 'Item row column
	(vlax-make-variant (vl-princ-to-string text) vlax-vbstring)))
)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

(setq plent (entsel "\nPick Pline"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))))
(progn (alert "you have not picked a pline will now exit")(exit))
)
(setq obj (vlax-ename->vla-object (car plent)))


(or (setq myxl (vlax-get-object "Excel.Application"))
    (setq myxl (vlax-get-or-create-object "excel.Application"))
)
(vla-put-visible myXL :vlax-true)
(vlax-put-property myxl 'ScreenUpdating :vlax-true)
(vlax-put-property myXL 'DisplayAlerts :vlax-true)
(vlax-invoke-method (vlax-get-property myXL 'WorkBooks) 'Add)

(setq row 1)

(xlsetcelltext row 1 "Point ID")
(xlsetcelltext row 2 "Easting")
(xlsetcelltext row 3 "Northing")
(xlsetcelltext row 4 "Distance")
(xlsetcelltext row 5 "Deflection Angle")
(xlsetcelltext row 6 "Station")
(setq row 2)

(setvar 'textstyle "Standard")
(setq num 0)
(setq pt1 (nth num co-ord))
(command "text" pt1 2.5 0.0 (rtos (setq num (1+ num)) 2 0))
(xlsetcelltext row 1 (rtos num 2 0))
(xlsetcelltext row 2 (car pt1))
(xlsetcelltext row 3 (cadr pt1))
(xlsetcelltext row 4 "0.0")
(xlsetcelltext row 5 "-")
(xlsetcelltext row 6 "0.0")

(repeat (- (length co-ord) 2)
  (setq row (1+ row))
  (command "text" pt1 2.5 0.0 (rtos (setq num (1+ num)) 2 0))
  (xlsetcelltext row 1 (rtos num 2 0))
  (xlsetcelltext row 2 (car pt1))
  (xlsetcelltext row 3 (cadr pt1))
  (setq pt2 (nth num co-ord))
  (setq dist (distance pt1 pt2))
  (xlsetcelltext row 4 (rtos dist 2 3))
  (setq ang (angle pt1 pt2))
  (xlsetcelltext row 5 (rtos ang 2 3))
  (setq dist (vlax-curve-getdistatpoint obj pt1))
  (xlsetcelltext row 6 (rtos dist 2 1))
  (setq pt1 pt2)
)

(command "Text" pt1 2.5 0.0 (rtos (setq num (1+ num)) 2 0))
(setq row (1+ row))
(xlsetcelltext row 1 (rtos num 2 0))
(xlsetcelltext row 2 (car pt2))
(xlsetcelltext row 3 (cadr pt2))
(setq dist (distance pt1 pt2))
(xlsetcelltext row 4 (rtos dist 2 3))
(setq ang (rtd (angle (nth (- (length co-ord) 2) co-ord) pt2)))
(xlsetcelltext row 5 (rtos ang 2 3))
(setq dist (vlax-curve-getdistatpoint obj pt1))
(xlsetcelltext row 6 (rtos dist 2 1))

(setvar 'osmode oldsnap)
(princ)
)
(c:pl2excel)

 

Message 8 of 12
ec-cad
in reply to: Sea-Haven

Sea-Haven,

I get an unknown command.

So, change very last line to be:

(c:pl2excel)

And, it runs just fine. Fun to open the Excel when it's running, watch all the numbers appear.

:slightly_smiling_face:

Last line looks a bit wierd though.

552-1392031091.10226.44941343.4

ECCAD

Message 9 of 12
sigmmadesigner
in reply to: Sea-Haven

It is possible to export in txt or word format
Happy New Year!!!!

Message 10 of 12
Sea-Haven
in reply to: ec-cad

Thanks @ec-cad I will have another look at last line. 

 

There is a command was going to try that turns off Excel calcs so hopefully makes the Excel then populates the screen, similar to tablesuppress in lisp.

Message 11 of 12
Sea-Haven
in reply to: sigmmadesigner

@sigmmadesigner it is possible normally to make a csv file. You can have a go at writing to a file instead. Just replace the xlsetcelltext with a strcat of the values with a "," between them then write to a file.

 

I can do a Libre Calc version Libre Calc is free.

Message 12 of 12
ec-cad
in reply to: sigmmadesigner

You (could) save the Excel Sheet as a file-type ".csv", or run this modified version Lisp file, that

just saves the same info as a .csv file. 

Cheers

ECCAD

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report