Need a lisp routine to export Road Centerline Coordinates at Specified Intervals

Need a lisp routine to export Road Centerline Coordinates at Specified Intervals

draconian_acts
Enthusiast Enthusiast
741 Views
11 Replies
Message 1 of 12

Need a lisp routine to export Road Centerline Coordinates at Specified Intervals

draconian_acts
Enthusiast
Enthusiast

I need a lisp routine to export road centerline coordinates from any Plan & Profile drawing,

i.e: I have road project starts from KM 50+000 to 65+000, the plan and profile is at 20m interval

and i need coordinates at 10m interval or 5m interval.

It has to export coordinates in excel sheet with specified columns

Chainage        :            Northing                 :                 Easting             :     Elevations (if possible)

 

the lisp should ask to select centerline , asking for starting station or chainage and the interval (m) at which i need the coordinates.

0 Likes
Accepted solutions (2)
742 Views
11 Replies
Replies (11)
Message 2 of 12

Moshe-A
Mentor
Mentor

@draconian_acts ,

 

post sample dwg

 

0 Likes
Message 3 of 12

ВeekeeCZ
Consultant
Consultant

Are you AutoCAD or C3D user?

0 Likes
Message 4 of 12

draconian_acts
Enthusiast
Enthusiast

Yes , But i need lisp routine for that.

0 Likes
Message 5 of 12

draconian_acts
Enthusiast
Enthusiast

Here is the sample drawing.

0 Likes
Message 6 of 12

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Hi,
Here's how I would do it:
In your drawing isolate the "CL-Rev" layer
Load the lisp "Mesure_PK.lsp", then run the command of the same name: "MESURE_PK"

Example entry:

To the prompt:
Sélectionner un objet curviligne à mesurer:
Select the polyline on the 'CL-Rev' layer

To the prompt:
Etablir les PK avec un écart de ? <1000.0>:
Enter the value 10 (or 5)

To the prompt:
PK de départ 0+000 <0.0>:
Enter the value 50.200

To the prompt:
Entrez une nouvelle valeur pour TEXTSIZE <2.500>:
Enter the value 1

This done, load the lisp "PtDef2CSV.lsp", then run the command of the same name: "PTDEF2CSV"

To the prompt:
Choix d'un objet modèle pour le filtrage:
Choose an insertion of the "BLK_MEASURE_CURVE" block

To the prompt:
Mode de sélection filtrée, choix [Unique/Tout/Manuel]<Manuel>:
Choose "Tout" (or "All")

To the prompt:
Séparateur [Espace/Virgule/Point-virgule/Tabulation]? <Point-virgule>:
Validate by default "Point-vigurle" ("Comma") or other at your convenience...

Once the file is generated, open it with Excel.

0 Likes
Message 7 of 12

draconian_acts
Enthusiast
Enthusiast

i got an idea from your lisp routines and i created one , it's possible with one lisp routine now instead of using two. here is the lisp routine.

0 Likes
Message 8 of 12

draconian_acts
Enthusiast
Enthusiast

Here is the revised version , this one is according to my needs. Command ExpCL

Message 9 of 12

draconian_acts
Enthusiast
Enthusiast
Accepted solution

Here is the revised version , Command ExpCL

 

(defun make_blk_measure ( / )
;; Define a text style and block for measurement
(if (not (tblsearch "STYLE" "$BLK_MEAS"))
(entmake '((0 . "STYLE") (5 . "40") (100 . "AcDbSymbolTableRecord")
(100 . "AcDbTextStyleTableRecord") (2 . "$BLK_MEAS") (70 . 0)
(40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 0.1) (3 . "ARIAL.TTF") (4 . ""))))
(if (not (tblsearch "BLOCK" "BLK_MEASURE_CURVE"))
(progn
(entmake '((0 . "BLOCK") (8 . "0") (2 . "BLK_MEASURE_CURVE") (70 . 2)
(4 . "") (8 . "0") (62 . 0) (6 . "ByBlock") (370 . -2) (10 0.0 0.0 0.0)))
(entmake (append '((0 . "LINE") (100 . "AcDbEntity") (67 . 0) (410 . "Model")
(8 . "0") (62 . 0) (6 . "ByBlock") (370 . -2) (100 . "AcDbLine"))
(list (list 10 0.0 (/ (- (getvar "TEXTSIZE")) 100.0) 0.0))
(list (list 11 0.0 (/ (getvar "TEXTSIZE") 100.0) 0.0))
'((210 0.0 0.0 1.0))))
(entmake '((0 . "ATTDEF") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0")
(62 . 0) (6 . "ByBlock") (370 . -2) (100 . "AcDbText")
(10 0.05 0.1 0.0) (40 . 1.0) (1 . "0.0") (50 . 1.570796326794896)
(41 . 1.0) (51 . 0.0) (7 . "$BLK_MEAS") (71 . 0) (72 . 0)
(11 0.0 0.1 0.0) (210 0.0 0.0 1.0) (100 . "AcDbAttributeDefinition")
(3 . "measure") (2 . "VALUE_MEASURE") (70 . 0) (73 . 2) (74 . 2)))
(entmake '((0 . "ENDBLK") (8 . "0") (8 . "0") (62 . 0) (6 . "ByBlock") (370 . -2))))))

(defun l-coor2l-pt (lst flag / )
(if lst
(cons (list (car lst) (cadr lst) (if flag
(+ (if (vlax-property-available-p ename 'Elevation)
(vlax-get ename 'Elevation)
0.0)
(caddr lst))
(if (vlax-property-available-p ename 'Elevation)
(vlax-get ename 'Elevation)
0.0)))
(l-coor2l-pt (if flag (cdddr lst) (cddr lst)) flag))))

(defun c:ExpCL ( / js poly obj_vlax pt_start total_dist partial_dist
ori_dist increment_dist lst_pt chainage_interval
start_chainage csvFile f_open chainage_str ename)

;; Ask the user to select a polyline (centerline)
(princ "\nSelect the road centerline polyline: ")
(setq poly (car (entsel)))
(if (not poly) (progn (princ "\nNo polyline selected.") (exit)))

;; Get the selected polyline as an object
(setq obj_vlax (vlax-ename->vla-object poly))

;; Get start point and total distance of the polyline
(setq pt_start (vlax-curve-getStartPoint obj_vlax)
total_dist (vlax-curve-getDistAtParam obj_vlax (vlax-curve-getEndParam obj_vlax)))

;; Get the interval and starting chainage
(setq chainage_interval (getreal "\nEnter interval distance for coordinates (e.g. 10): "))
(setq start_chainage (getreal "\nEnter starting chainage (e.g., 50000 for KM 50+000): "))

;; Prompt user for output file (CSV format)
(setq csvFile (getfiled "Select location to save CSV file" "coordinates.csv" "csv" 1))
(setq f_open (open csvFile "w"))
(if (null f_open) (progn (princ "\nFailed to open file.") (exit)))

;; Write the CSV header
(write-line "Chainage,Northing,Easting,Elevation" f_open)

;; Loop through points at the specified interval
(setq increment_dist 0.0)
(setq lst_pt (list pt_start)) ;; Start with the start point
(while (< increment_dist total_dist)
(setq pt (vlax-curve-getPointAtDist obj_vlax increment_dist))
;; Only add the point if it's not the start point
(if (not (equal pt pt_start))
(setq lst_pt (cons pt lst_pt)))
(setq increment_dist (+ increment_dist chainage_interval)))

;; Add the start point explicitly
(setq lst_pt (cons pt_start lst_pt))

;; Loop through the points and write to CSV
(setq lst_pt (reverse lst_pt))
(foreach pt lst_pt
(setq chainage_str (rtos (+ start_chainage (/ (vlax-curve-getDistAtPoint obj_vlax pt) 1.0)) 2 3))
(write-line
(strcat chainage_str "," (rtos (car pt) 2 3) "," (rtos (cadr pt) 2 3) ","
(if (vlax-property-available-p obj_vlax 'Elevation)
(rtos (vlax-get obj_vlax 'Elevation) 2 3)
"0.0"))
f_open))

;; Close the file
(close f_open)
(princ "\nCoordinates exported successfully.")
(prin1))

0 Likes
Message 10 of 12

CADaSchtroumpf
Advisor
Advisor

@draconian_acts 

Glad you were able to put together your own code based on my suggestions.
You are never better served than by yourself...😃

Message 11 of 12

Sea-Haven
Mentor
Mentor

Lots of posts but there are many Chainage.lsp programs out there and may have saved some coding time.

 

It is possible in a CIV3D dwg to get at the alignments and get details like you wanted using a lisp.

 

What you want is built into CIVIL SITE DESIGN, plus more output reports, like cross sections XYZ, similar with CIV3D easier than trying to write code as the packages give you way more for the cost, time is money.

0 Likes
Message 12 of 12

draconian_acts
Enthusiast
Enthusiast

I had tried Chainage.lsp , it was for 3D Polyline Stationing that's a different thing, i didn't mean annotating text over centerline, i was talkin about extracting centerline coordinates and save it as CSV and i got it the guy who shared two lisp routines solved the issue , i turned it into one.

0 Likes