Create multiple lines by station offset

Create multiple lines by station offset

AllenJessup
Mentor Mentor
2,001 Views
18 Replies
Message 1 of 19

Create multiple lines by station offset

AllenJessup
Mentor
Mentor

I think I remember seeing a solution to this a few years ago. But I haven't found it in a search. I have multiple State acquisition maps defined by Station-Offset. I has thought there was a way to create lines or points from a text file containing the stations and offsets. I know something can be done using the Survey command language but thought there was a simpler way. Anyone have any idea what I'm talking about?

Allen Jessup
CAD Manager - Designer
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

0 Likes
Accepted solutions (2)
2,002 Views
18 Replies
Replies (18)
Message 2 of 19

tcorey
Mentor
Mentor

Sounds simple enough with LISP. Post your file..

 

Or use a script. Open the file, add the correct commands, saveas something.scr.

 

Back in AutoCAD, use the SCRIPT command to load and run the script.

 

If it was me, I would use LISP.



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

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 3 of 19

udo.huebner
Autodesk Support
Autodesk Support
Accepted solution

Perhaps tranparent command 'SO  (Station & Offset) is all you need.

Start

Command: LINE 'SO            (select Alignment once)

 

repeat Station and Offset values

 

With Lisp at the command Line you can ask for the Alignment first (setq AL (car (entsel "Select alignment:")))

and use 

LINE 'SO !AL 100 1 200 2 ....

Message 4 of 19

AllenJessup
Mentor
Mentor

@tcorey Thanks. I was considering that. But I didn't know how to select the Alignment in Lisp. @udo.huebner has provided me with that. Now it's just a lot of typing!

Allen Jessup
CAD Manager - Designer
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

0 Likes
Message 5 of 19

AllenJessup
Mentor
Mentor

@udo.huebner wrote:

 

LINE 'SO !AL 100 1 200 2 ....


Thanks. I wanted to avoid doing this from the command line because there are bound to be some typo's. For a Script or Lisp. I can proof read the file before running and rerun it easily if there are any mistakes. I like the use of the ! in your routine to evaluate AL. Don't see that too much.

Allen Jessup
CAD Manager - Designer
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

0 Likes
Message 6 of 19

tcorey
Mentor
Mentor

Allen, if you do it with a LISP routine, what's to type, other than a few lines of code?

 

If you attach your text file, I can give you explicit instructions.



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

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes
Message 7 of 19

AllenJessup
Mentor
Mentor

@tcorey Every single Station and Offset from 16± acquisition maps. I can either do it right in the lisp or have the lisp call a script. Either way they would have to be typed. I'm thinking of bypassing this step and asking if the state have these coordinated.

Allen Jessup
CAD Manager - Designer
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

0 Likes
Message 8 of 19

AllenJessup
Mentor
Mentor

@tcorey I created a file that would represent the first map. It's SDF with the first column being the Station and the second being the offset. It takes a bit to glean these from the description. Their format is "to a point 308 feet northwesterly , measured at right angles, to statioin 106+64".

Thanks for your help.

Allen Jessup
CAD Manager - Designer
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

0 Likes
Message 9 of 19

AllenJessup
Mentor
Mentor

@udo.huebner It look like I'm missing something. After running

(setq AL (car (entsel "Select alignment:"))) and selecting an alignment;

(Command "Line" "'SO" !AL 10582 544) asks me to select an Alighment

 

Allen Jessup
CAD Manager - Designer
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

0 Likes
Message 10 of 19

TerryDotson
Mentor
Mentor

Request the full working 30-day evaluation of C3DTools and use it's Alignment Point Import tool.  It works with comma delimited and makes easy work out of space delimited by showing you the text file and letting you tell it the character positions and lengths, etc.

 

alipntimp.png

 

Of course the coordinates won't match yours since I had to make up an alignment.

 

Message 11 of 19

tcorey
Mentor
Mentor

Hello @AllenJessup,

 

Here's some code that will ask for an alignment selection, then read your file line by line, placing an AutoCAD Point at the specified station and offset. It would be easy enough to make it create COGO Points, then you could draw line by point number, zip, done.  You will need to edit the code to your file name and path. 

 

(defun c:go ( / DES_Alignment fl l1 sppos sta off xy l1) 
  (setq DES_Alignment (vlax-ename->vla-object (car (entsel "\nSelect Alignment: "))))
  

  (while (not (= (vlax-get-property DES_Alignment 'ObjectName) "AeccDbAlignment"))
    (setq DES_Alignment (vlax-ename->vla-object (car (entsel "\nSelect Alignment: "))))
    )
  (setq fl (open "E:\\_Support\\_Usenet\\20180508 Allen Jessup Lines by Sta-Off from file\\142_152.txt" "r"))
  (setq l1 (read-line fl))
  (while (and l1)
  
  (setq sppos (vl-string-position 32 l1))
    (setq sta (substr l1 1 sppos))
    (setq off (substr l1 (+ sppos 2) ))
	(vlax-invoke-method DES_Alignment 'PointLocation (atof sta) (atof off) 'x 'y)
	(setq xy (list x y))
	
	(vl-cmdf "Point" xy)
	
	(setq l1 (read-line fl))
	
	
	
  
  );end while
  (close fl) 
  (princ)
  );end defun


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

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes
Message 12 of 19

tcorey
Mentor
Mentor
Accepted solution

Better yet, this draws the lines:

 

(defun c:go ( / DES_Alignment fl l1 sppos sta off xy l1) 
  (setq DES_Alignment (vlax-ename->vla-object (car (entsel "\nSelect Alignment: "))))
  

  (while (not (= (vlax-get-property DES_Alignment 'ObjectName) "AeccDbAlignment"))
    (setq DES_Alignment (vlax-ename->vla-object (car (entsel "\nSelect Alignment: "))))
    )
  (setq fl (open "E:\\_Support\\_Usenet\\20180508 Allen Jessup Lines by Sta-Off from file\\142_152.txt" "r"))
  (setq l1 (read-line fl))
  (setq lins (ssadd))
  (while (and l1)
  
  (setq sppos (vl-string-position 32 l1))
    (setq sta (substr l1 1 sppos))
    (setq off (substr l1 (+ sppos 2) ))
	(vlax-invoke-method DES_Alignment 'PointLocation (atof sta) (atof off) 'x 'y)
	(setq xy (list x y))
	
	(vl-cmdf "Point" xy)
	(ssadd (entlast) lins)
	
	
	(setq l1 (read-line fl))
	
	
	
  
  );end while
  (setq ctr 0
		len (sslength lins)
		)
		(while (< ctr len)
		(setq p1 (vlax-get (vlax-ename->vla-object (ssname lins ctr)) 'Coordinates))
		
		(setq p2 (vlax-get (vlax-ename->vla-object (ssname lins (+ ctr 1))) 'Coordinates))
		(if (and p2) (vl-cmdf "Line" p1 p2 ""))
		(setq ctr (1+ ctr))
		)
  (close fl) 
  (princ)
  );end defun
  
  
  


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

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 13 of 19

AllenJessup
Mentor
Mentor

@TerryDotson wrote:

f course the coordinates won't match yours since I had to make up an alignment.

 


Smiley Very Happy

Allen Jessup
CAD Manager - Designer
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

0 Likes
Message 14 of 19

AllenJessup
Mentor
Mentor

@tcorey Thank you. However I'm getting an error that is confusing me.

 

Select Alignment: Point
Current point modes: PDMODE=0 PDSIZE=0.00000
Specify a point:
Command: Point
Current point modes: PDMODE=0 PDSIZE=0.00000
Specify a point:
Command: Point
Current point modes: PDMODE=0 PDSIZE=0.00000
Specify a point:
Command: Point
Current point modes: PDMODE=0 PDSIZE=0.00000
Specify a point:
Command: Point
Current point modes: PDMODE=0 PDSIZE=0.00000
Specify a point:
Command: Point
Current point modes: PDMODE=0 PDSIZE=0.00000
Specify a point:
Command: ; error: Automation Error. Invalid input

 

I'm not too good at lisp. But it looks like it stops at: (vl-cmdf "Point" xy). I tried setting PDMODE and PDSIZE to 1..0 but it just repeats the error with 1.00000 instead of 0.00000. 

I changed the function name and the path in the code. I'll attach the file I'm using if you want to check what I have done.

 

Allen Jessup
CAD Manager - Designer
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

0 Likes
Message 15 of 19

tcorey
Mentor
Mentor

Automation error. That's a version problem, I think. What version are you using? 

 

I am using 2018.2/2019. Both work. When I run the routine,  I get an expected error at the end, but the lines are drawn. 

 

 

 

 

 

 

 

 

 

 



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

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes
Message 16 of 19

AllenJessup
Mentor
Mentor

I'm using 2017

Allen Jessup
CAD Manager - Designer
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

0 Likes
Message 17 of 19

tcorey
Mentor
Mentor

I found an omission that may have been causing that automation error. 

 

Here's the LISP, with the omission fixed and with a fix for a benign error I was getting after the lines finished being added.

 

(defun c:go ( / DES_Alignment fl l1 sppos sta off xy l1) 
(vl-load-com) (setq DES_Alignment (vlax-ename->vla-object (car (entsel "\nSelect Alignment: ")))) (while (not (= (vlax-get-property DES_Alignment 'ObjectName) "AeccDbAlignment")) (setq DES_Alignment (vlax-ename->vla-object (car (entsel "\nSelect Alignment: ")))) ) (setq fl (open "E:\\_Support\\_Usenet\\20180508 Allen Jessup Lines by Sta-Off from file\\142_152.txt" "r")) (setq l1 (read-line fl)) (setq lins (ssadd)) (while (and l1) (setq sppos (vl-string-position 32 l1)) (setq sta (substr l1 1 sppos)) (setq off (substr l1 (+ sppos 2) )) (vlax-invoke-method DES_Alignment 'PointLocation (atof sta) (atof off) 'x 'y) (setq xy (list x y)) (vl-cmdf "Point" xy) (ssadd (entlast) lins) (setq l1 (read-line fl)) );end while (setq ctr 0 len (sslength lins) ) (while (< ctr len) (setq p1 (vlax-get (vlax-ename->vla-object (ssname lins ctr)) 'Coordinates)) (if (< (+ ctr 1) len) (progn (setq p2 (vlax-get (vlax-ename->vla-object (ssname lins (+ ctr 1))) 'Coordinates)) (vl-cmdf "Line" p1 p2 "") ) ) (setq ctr (1+ ctr)) ) (close fl) (princ) );end defun


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

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes
Message 18 of 19

AllenJessup
Mentor
Mentor

Now it's: 

Select Alignment: ; error: no function definition: GETDOC

Allen Jessup
CAD Manager - Designer
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

0 Likes
Message 19 of 19

tcorey
Mentor
Mentor

Get the code again. I saw that and edited it out of my response. 



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

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes