Results 1 to 4 of 4

Thread: Autolisp or Macro to Plot Polylines using Station-Offset

  1. #1
    The Silent Type
    Join Date
    2020-06
    Posts
    1
    Login to Give a bone
    0

    Question Autolisp or Macro to Plot Polylines using Station-Offset

    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
    c3d automation.png


    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

    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.

  2. #2
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    0

    Default Re: Autolisp or Macro to Plot Polylines using Station-Offset

    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
    Attached Images Attached Images

  3. #3
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    0

    Default Re: Autolisp or Macro to Plot Polylines using Station-Offset

    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.

    Code:
    ; 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)

  4. #4
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    0

    Default Re: Autolisp or Macro to Plot Polylines using Station-Offset

    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.

    Code:
    ; 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
    Attached Files Attached Files

Similar Threads

  1. Autolisp program to label station and offset.
    By aaronic_abacus in forum AutoLISP
    Replies: 7
    Last Post: 2020-09-16, 01:36 AM
  2. 2017: Place a station label at a specific station on an alignment by typing in the station?
    By tadthurston725387 in forum AutoCAD Civil 3D - General
    Replies: 1
    Last Post: 2020-02-08, 04:58 PM
  3. Replies: 0
    Last Post: 2016-11-21, 05:02 AM
  4. 2015: Beg Station & End Station
    By tim_newsome in forum AutoCAD Civil 3D - Profiles
    Replies: 1
    Last Post: 2015-02-18, 09:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •