Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Autolisp or Macro to Plot Polylines using Station-Offset

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
1399 Views, 7 Replies

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

 

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.

7 REPLIES 7
Message 2 of 8
rl_jackson
in reply to: Anonymous

A script would be easy if you could export the SO etc. as a (trying to remember either comma or semicolon - thinking later for a script). Would still involve some intervention as far as selecting an alignment, I bet @tcorey  might have a better idea.


Rick Jackson
Survey CAD Technician VI

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 3 of 8
Udo_Huebner
in reply to: rl_jackson

I wrote some sample lisp code. Input data is taken from a textfile instead of excel file, so you have to save the excel file to  a space delimited text file first.

 

 

(defun C:UHCreate4sidedPlinesOnAlignment()
  ; ask for a Textfile
  ;; Station1 Offset1 Station2 Offset2 Station3 Offset3 Station4 Offset4
  ;; ; 10 -5 11 -5.5 11 5.5 10 5.0
  ;; ; 20 -5 21 -6.5 21 6.5 20 5.0

  ; no erorhandling for wrong structure in Text file implemented
  (prompt "\nPlace 4-sided Polylines on Aligment - CAD-Huebner 2020/6/6")
  (if (setq file (open (setq filename (getfiled  "Select a space delimited Text File with Station values" "" "txt" 0)) "r"))
    (progn
      ; standard entity selection
      (setq sel (entsel "\nSelect Alignment: "))
      ; get the entity name
      (setq ent (car sel))
       ; check to make sure the selection was the expected type
       (if (and ent (eq "AECC_ALIGNMENT" (cdr (assoc 0 (entget ent)))))
          ; if so, convert the entity into a VLA-OBJECT
          (setq vlaobj (vlax-ename->vla-object ent))
       )
       (if vlaobj
	 (progn
	   ; read row by row 4 station and offset values
	   (While (setq row (read-line file))
	     (setq Stationlist (read (strcat "(" row ")"))
		   Pointlist nil
	     )
	     ; determine PointLocation for the station values
	     (repeat 4
	       (setq sta (car  Stationlist)
		     off (cadr Stationlist)
		     Stationlist (cddr  Stationlist)
	       )    
               ; using the above variables, find this point on the alignment
               (vlax-invoke-method vlaobj 'PointLocation sta off 'x 'y)
	       (setq pointlist (cons (list x y) Pointlist))
	     )
	     (createPlinefromPointlist pointlist)
	   )
	 )
       ); end if vlaobj
       (close file)
     )	
   )
); end defun

; subroutine
(defun createPlinefromPointlist (pointlist / arrPline lwPlineObj)
  (print Pointlist)
  ;(command "_Pline" (nth 1 Pointlist)(nth 2 Pointlist)(nth 3 Pointlist)(nth 4 Pointlist) "_close")
  (setq arrPline (gc:2dPointListToVariant Pointlist))
  (setq lwPlineObj (vla-AddLightweightPolyline (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) arrPLine))
  (vla-put-closed lwPlineObj :vlax-true)
)  
;; LISP -> variant

;; gc:2dPointListToVariant (gile)
;; Return a variant of 2d coordinates
;;
;; Argument: a 2d points list -type (x y)-

(defun gc:2dPointListToVariant (lst)
  (vlax-make-variant
    (vlax-safearray-fill
      (vlax-make-safearray
        vlax-VbDouble
        (cons 0 (1- (* 2 (length lst))))
      )
      (apply 'append lst)
    )
  )
)

 

 

Gruß Udo Hübner (CAD-Huebner)
Message 4 of 8
Udo_Huebner
in reply to: Udo_Huebner

This may also be done using a dynamo script.

Gruß Udo Hübner (CAD-Huebner)
Message 5 of 8
Anonymous
in reply to: Udo_Huebner

Dear @Anonymous thank you very much! The code works perfectly!

 

Now, just to finish, would it be possible to add two more things to your code please?

 

1) I would like each closed rectangle to be hatched (ANSI31 with a scale of 0.3 is fine)

 

2) If I insert a number (basically a counter: 1, 2, 3, 4.....) before the first station (STA1), would it be possible to add this number as an mtext (Arial font, 2.5 Height) at the middle of the rectangle?  That way the rectangle can be properly "tagged" or "identified". 

 

That way the .txt file would be: COUNTER STA1 OFFST1 STA2 OFFST2 STA3 OFFST3 STA4 OFFST4

 

I want to mention that I am using Civil 3D in metric units by the way (don't know if it's relevant, but just wanted to put that out there).

 

I want to really and truly thank you for your help!

Thanks a lot!! 🙂

Message 6 of 8
tcorey
in reply to: Udo_Huebner

Nice.



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 7 of 8
Udo_Huebner
in reply to: Anonymous

Yes, a lot of extensions can be done with this tiny lisp as a base.

The numbering should support the scale and sheet orientation. But this makes the macro too specific and less suitable for a forum post. I don't want to inflate the macro.
I would do the numbering with Sample Lines and the hatching with the commands SELECTSIMILAR and HATCH. These are only 2 commands and then the hatching is done for all polylines.

If you really want to add this functionality to the Lisp program, you better try to extend it by yourself according to your needs. This is a good opportunity to get started with programming.

 

Gruß Udo Hübner (CAD-Huebner)
Message 8 of 8
davilavanegas
in reply to: Udo_Huebner

Thanks @Udo_Huebner,

 

I was trying same thing. But I dont know invoke-method form pointlocation store 'x and 'y value by deafult.

 

Regards,


______________________
RDV - Rinat Dávila Vanegas  | LinkedInYouTube | Facebook


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

Post to forums  

Rail Community


 

Autodesk Design & Make Report