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
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.
sample drawing and csv for the headers only attached
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)
)
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).
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)
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.
![]()
Last line looks a bit wierd though.
| 552 | -13920 | 31091.1 | 0 | 226.449 | 41343.4 |
ECCAD
@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.
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.