PDA

View Full Version : 2018 Autolisp or Macro to Plot Polylines using Station-Offset



ONUNEZ790318
2020-06-06, 05:17 AM
Hello!



I turn to you guys for some help.

I am trying to automate a polyline drawing (rectangle or squares... basically a four vertex shape) that is really recurrent in my work.



Basically I have an Excel table like the one attached
108238


As you can see, each row line represents the four vertices of the polylines that are supposed to be drawn using the station offset command.



Let me describe what I do manually (let's use the first row as an example):

1) Invoke PLINE

2) Type 'SO

3) Select Alignment (now that I am thinking, I could--if you need--include exact alignment name in my excel if that helps in any way)

4) When asked for station, I type 16500

5) When asked for offset, I type 5

6) When asked for another station, I type 16600

7) When asked for offset, I type 5

8) When asked for station, I type 16600

9) When asked for offset, I type -5

10) When asked for station, I type 16500

11) When asked for offset, I type -5

12) When asked for station, I type (again, to go back to vertex 1 and close the polyline) 16500

13) When asked for offset, I type (again, to go back to vertex 1 and close the polyline) 5

14) Hit enter again to finish the command, and done!



As you can see, it is very repetitive and time consuming.



Could anyone help me with a lisp or macro or idea that could probably make my life easier?



I am thinking that maybe I could incorporate some of the code in my excel for it to generate everything automatically. I don't know, I am just throwing ideas around... I hope someone can help me out.



Thank you very much!



Best regards.

BIG-AL
2020-06-09, 01:39 AM
I think I have something but not sure post a dwg or image. So want to draw a 4 sided object based on a chainage and offset this can be done using polyline properties pointatdist and a pline angle at that point.

Include a sample xls

BIG-AL
2020-06-09, 03:48 AM
Try this I had problems with using 'so in an automated way so this uses a pline as the reference. Else would have done a excel solution. using pline 'so !plent 20 3 30 3 30 -3 20 -3 C gets an error at command line.

You need to edit where a CSV file is saved.



; draw a pline at chainage and offsets from a pline
; By Alanh info@alanh.com.au
; June 2020

(defun pl-plbox ( / fname obj pt x ang )

(defun alg-ang (object pnt)
(angle '(0. 0. 0.)
(vlax-curve-getfirstderiv
object
(vlax-curve-getparamatpoint
object
pnt
)
)
)
)

; thanks to Lee-mac for this defun
; www.lee-mac.com
; 44 is comma
(defun _csv->lst ( str / pos )
(if (setq pos (vl-string-position 44 str))
(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
(list str)
)
)

; Starts here
; 1st line in file is not required

(setq obj (vlax-ename->vla-object (car (entsel "Pick pline "))))

(setq fname (open (getfiled "Pick csv " "D:\\acadtemp\\" "csv" 8) "R"))

(princ (read-line fname))
(while (setq newline (read-line fname))
(setq lst (_csv->lst newline))
(setq x 0)
(command "_pline")
(while (= (getvar "cmdactive") 1 )
(repeat (/ (length lst) 2)
(setq pt (vlax-curve-getpointatdist obj (atof (nth x lst))))
(setq ang (- (alg-ang obj pt)(/ pi 2.0)))
(command (polar pt ang (atof (nth (+ x 1) lst))))
(setq x (+ x 2))
)
(command "c")
)
)

(close fname)

(princ)

)


(pl-plbox)

BIG-AL
2020-06-09, 03:58 AM
Try this it uses a CSV file from your excel file, I tried using 'so inside excel as a solution manually yes works automated as a line response gets an error. So this will read a csv file and make plines given offsets. It uses a pline not an Alignment. So version 2 may need a start chainage option.

You need to change the csv file location.

I will see if I can get the alignment to work.



; draw a pline at chainage and offsets from a pline
; By Alanh info@alanh.com.au
; June 2020

(defun pl-plbox ( / fname obj pt x ang )

(defun alg-ang (object pnt)
(angle '(0. 0. 0.)
(vlax-curve-getfirstderiv
object
(vlax-curve-getparamatpoint
object
pnt
)
)
)
)

; thanks to Lee-mac for this defun
; www.lee-mac.com
; 44 is comma
(defun _csv->lst ( str / pos )
(if (setq pos (vl-string-position 44 str))
(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
(list str)
)
)

; Starts here
; 1st line in file is not required

(setq obj (vlax-ename->vla-object (car (entsel "Pick pline "))))

(setq fname (open (getfiled "Pick csv " "D:\\acadtemp\\" "csv" 8) "R"))

(princ (read-line fname))
(while (setq newline (read-line fname))
(setq lst (_csv->lst newline))
(setq x 0)
(command "_pline")
(while (= (getvar "cmdactive") 1 )
(repeat (/ (length lst) 2)
(setq pt (vlax-curve-getpointatdist obj (atof (nth x lst))))
(setq ang (- (alg-ang obj pt)(/ pi 2.0)))
(command (polar pt ang (atof (nth (+ x 1) lst))))
(setq x (+ x 2))
)
(command "c")
)
)

(close fname)

(princ)

)


(pl-plbox)




csv as file upload not supported so just rename back to textsq.csv