Jump to content

Recommended Posts

Posted (edited)

I was wondering if someone could help me with a lisp to draw a spline and get the coordinates of the first two points of the spline. I need them to insert a block in the first point of the spline and to define the angle between the points.

I started with the lisp below but I can't make it work properly, the command prompts are different from the prompts for the standard AutoCAD spline, it promts for and . I have to hit ENTER a few times to exit the program.

I am using AutoCAD 2011.

Thank you.

 

 

(defun c: DrawSpline ()
  (command "._spline")
  (while (> (getvar "cmdactive") 0)
  (command pause)
)

Edited by Arepo
Posted

Consider the following code:

 

(defun c:DrawSpline ( / a e p )
   (setq e (entlast))
   (initcommandversion)
   (command "._spline")
   (while (< 0 (getvar 'cmdactive))
       (command pause)
   )
   (if (not (eq e (setq e (entlast))))
       (progn
           (setq p (vlax-curve-getstartpoint e)
                 a (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv e (vlax-curve-getstartparam e)))
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

 

In the above example, variable 'p' is the start point of the Spline, variable 'a' is the angle of the tangent at the start point.

 

I would also suggest you read the Code Posting Guidlines regarding formatting code in your posts. :)

Posted

Maybe ....

 

(defun c:Test (/ p1 p2)
 (if (and (setq p1 (getpoint "\n First point :"))
          (setq p2 (getpoint "\n Second point :" p1))
     )
   (command "_.spline" "_non" p1 "_non" p2)
   (while (> (getvar 'cmdactive) 0)
     (command pause)
   )
 )
 (princ)
)

Posted
Thank you, Lee Mac. Works perfectly (no idea how you avoided those annoying prompts though :)) I used

(/ (* a 180) PI)

to calculate the insertion angle for the block.

 

You're very welcome Arepo :)

 

The prompts are altered by the use of the initcommandversion function, which initialises a command to a specific (or the latest) version.

Posted

Hi Tharwat,

Is it possibe to extend your code to draw three seperate lines: p1 p2, p3 p4 and another line from intersection of these two lines to a fifth point, while allowing for zoom window before getting the points and zoom previous each time after getting the point?. There is a Road Design application for this.

Regards,

Aloy

Posted
Hi Tharwat,

Is it possibe to extend your code to draw three seperate lines: p1 p2, p3 p4 and another line from intersection of these two lines to a fifth point, while allowing for zoom window before getting the points and zoom previous each time after getting the point?. There is a Road Design application for this.

Regards,

Aloy

 

How the code to draw three separate lines and another line from intersection on these tow lines ???

 

Can you explain your goal in more details please ?

 

You want normal lines of spline ?

Posted

???

 

(defun c:test ( / ip p1 p2 p3 p4 p5 )
   (if
       (and
           (setq p1 (getpoint "\n1st Point: "))
           (setq p2 (getpoint "\n2nd Point: " p1))
           (setq p3 (getpoint "\n3rd Point: "))
           (setq p4 (getpoint "\n4th Point: " p3))
       )
       (if (setq ip (inters p1 p2 p3 p4 nil))
           (if (setq p5 (getpoint "\n5th Point: " ip))
               (mapcar
                   (function
                       (lambda ( a b )
                           (entmake
                               (list
                                  '(0 . "LINE")
                                   (cons 10 (trans a 1 0))
                                   (cons 11 (trans b 1 0))
                               )
                           )
                       )
                   )
                   (list p1 p3 ip)
                   (list p2 p4 p5)
               )
           )
           (princ "\nLines are Parallel.")
       )
   )
   (princ)
)

Posted (edited)

LeeMac,

Thank you very much. The code works to get the three lines. Actually the third line is on the bisector of angle between the first two lines. However I need to zoom in on the areas covering the five points before giving them on command and need to zoom out also each time after giving the point.

Tharwat,

My aim is to give these points on a corridoor survey drawing loaded in AutoCAD and calculate the optimum radius of the circular curve, the optimum length of transition curve (which is a spiral or clothoid) to suit the super elevation within limits and driving comfort depending on the type of road to the design speed, by iteration, all according to the design standards of the country where the road project is to be implemented.

Regards,

Aloy

Edited by aloy

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...