Help on writing a "batch" arc alignement lisp

Help on writing a "batch" arc alignement lisp

Anonymous
Not applicable
1,008 Views
13 Replies
Message 1 of 14

Help on writing a "batch" arc alignement lisp

Anonymous
Not applicable

I'm currently learning AutoLisp to write a script that fullfill a rather specific need: I got a large and ordered spreadsheet of arcs data, that I need to draw, each one being tangent to its neighbour.

 

On column 1: their length / On column two: their radius.

 

My best guess at that point is to find a way to use _AeccCurveFromEndOfObject (curve from end of object): feed the command with my spreadsheet data and automatically pick the start of each newly created arc to draw the next one.

Is that even possible ?

 

Any guidance will be greatly appreciated.

 

0 Likes
1,009 Views
13 Replies
Replies (13)
Message 2 of 14

Sea-Haven
Mentor
Mentor

Two items is not enough need a 3rd the angle left or right.

 

The simplest way would be a CSV file of the data length,rad,R then just pick a pt to start.

0 Likes
Message 3 of 14

Anonymous
Not applicable

Thanks for your help !

 

Are you sure I can't use the Curve from end of object Command ?

 

This piece of code from

 

  • (if (setq ent (car (entsel "\nSelect arc: ")))
    (progn (setq entlist (entget ent) rp (cdr (assoc 10 entlist)) stAng (cdr (assoc 50 entlist)) endAng (cdr (assoc 51 entlist))rad (cdr (assoc 40 entlist))
    )
    (setq startPt (polar rp stang rad) endpt (polar rp endang rad)))
    )

Returns a picked arc endpoints.

 

If I managed to make it return the (ent)last created arc, and use those coordinates to feed the first _AeccCurveFromEndOfObject promptline, wouldn't it be something ?

 

Sorry to insist, I'm clueless at that point and probably seeking a bit of general knowledge.

 

0 Likes
Message 4 of 14

john.uhden
Mentor
Mentor

@Sea-Haven's question regarding the direction is most important unless all your arcs are intended to be counterclockwise, in keeping with AutoCAD's convention.  One way to handle CW vs. CCW would be to change the sign of the radius to negative for a CW direction.  Plus, I am thinking it might be easier to construct a polyline from all the segments.

I know nothing about the aecc... method except that if you are starting from the end of an existing arc entity or polyline, then you probably need only regular AutoLisp with a little vl- thrown in.  I am thinking that the aecc* methods are available only in Civil 3D, which would reduce the number of helpers, except that some of the best here use Civil 3D.

Anyway, when Dave Arnold started this whole civil add-on (DCA) everything was written in plain AutoLisp without any vl- properties or methods, and he included drawing an arc from the end of an existing arc... you know... compound and reverse curves.

John F. Uhden

0 Likes
Message 5 of 14

Anonymous
Not applicable

Thanks for your suggestions, I didn't knew _AeccCurveFromEndOfObject was a Civil 3d Exclusivity.

 

This command got all I need: pick end for tangent > input radius > input length; I just have to find a way to "feed loop" my data into it.

I forgot to say that all my tangent arcs are one big long turn, if the direction is wrong then I guess I'll just Mirror the result.

 

  • (if (setq Ent (entlast))
    (progn
    (setq EntLst (entget Ent) CenterPt (cdr (assoc 10 EntLst)) StartAng (cdr (assoc 50 EntLst)) Rad (cdr (assoc 40 EntLst)))
    (setq StartPt (polar CenterPt StartAng Rad)))
    )

... now returns the start point coordinates of the last created arc as a list variable, that I must find a way to input into _AeccCurveFromEndOfObject command.

Then I guess I'll learn about autolisp loop.

 

Thanks again.

0 Likes
Message 6 of 14

Sea-Haven
Mentor
Mentor

This worked for me

 

(command "AeccCurveFromEndOfObject" pause "R" 50 "L" 100)

Message 7 of 14

Anonymous
Not applicable

It's probably very ugly but it's going somewhere 🙂

 

  • (defun c:CheapAlign ()
    (vl-load-com)
  •  
  • (if (setq Ent (entlast))
    (progn (setq EntLst (entget Ent) FrstCenter (cdr (assoc 10 EntLst)) FrstAng (cdr (assoc 50 EntLst)) FrstRad (cdr (assoc 40 EntLst)))
  •  
  • (setq StartPt (vl-list->string (vl-remove 32 (vl-string->list (vl-string-translate "(" " " (vl-string-translate ")" " " (vl-string-translate " " "," (vl-princ-to-string (polar FrstCenter FrstAng FrstRad)))))))))))
  •  
  • (setq NextRad 1111.11111)
    (setq NextLen 1111.11111)
  •  
  • (command "_.AeccCurveFromEndOfObject" StartPt "R" NextRad "L" NextLen)
  • )

 

It creates a tangent arc of fixed Radius and Length with CurveFromEndOfObject at the start of the last one, each time you fires it.

 

Now I got to find how to feed my data into NextRad and NextLen Variables.

 

And finally I suppose I'll make it create a dummy Arc on the beggining (CurveFromEndOfObject must start from an existing one) - and delete it at the end.

0 Likes
Message 8 of 14

Sea-Haven
Mentor
Mentor

Just need a csv file as the simplest way with the rad and length. Provide a sample or a xls. Just read the file and draw.

0 Likes
Message 9 of 14

Sea-Haven
Mentor
Mentor

This is the manual version. So next would be read a csv and make into a pline.

 

 

(defun c:aaa ( / ang pt pt2 len rad obj)
(setq ang pi)
(setq pt (getpoint "\nPick start point"))
(while (setq rad (getreal "\nEnter rad Enter to exit "))
(setq len (getreal "\nEnter chord length "))
(setq pt2 (polar pt ang rad))
(setq pt2 (list (car pt2)(cadr pt2)))
(command "arc" "C" pt2 pt "L" len)
(setq obj (vlax-ename->vla-object  (entlast)))
(setq ang (+ pi (vlax-get Obj 'endAngle)))
(setq pt  (vlax-get Obj 'endPoint))
)
)
(c:aaa)

 

 

Message 10 of 14

john.uhden
Mentor
Mentor
That's pretty clever converting the list of reals to a comma-delimited
string.
But doesn't the aecc thingy accept a list (x y z)?

John F. Uhden

0 Likes
Message 11 of 14

Anonymous
Not applicable

From my understanding it doesn't work, hence the list/string conversions back and forth..

 

But sea.haven's code seems a lot more refined and instructive to me, so I'm continuing from there 🙂

 

Arc command doesn't accept the Arc Length data I have, so I made a converted Arc Length to Chord Length variable with

 

  • (setq clen (* (* 2 rad) (sin (/ alen (* 2 rad)))))

Now investigating the CSV part, to replace (getreal "\nEnter value).

0 Likes
Message 12 of 14

john.uhden
Mentor
Mentor

BTW,

(setq clen (* (* 2 rad) (sin (/ alen (* 2 rad)))))

could be shortened to

(setq clen (* 2 rad (sin (/ alen 2 rad))))

 

 

John F. Uhden

Message 13 of 14

Sea-Haven
Mentor
Mentor

Use this for csv  just read a line from file. Then (setq radlen (_csv->lst csvtxt)) = (150 125) so then use (car & (cadr for rad and len.

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

 

Message 14 of 14

Anonymous
Not applicable
Sorry for the long absence. Further learning of LISP is a bit too much time consuming for me at the moment, but I'll certainly get back to it. sea.haven's code is perfectly functional, for now even without CSV I can copy paste the data into the command line with a space separator. A big thanks to both of you for your kind help.
0 Likes