Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoLISP: Retrieving atoms from lists 2

Status
Not open for further replies.

trssr

Mechanical
Jan 21, 2002
1
I have written an autolisp program where i generate a list of points that i would like to connect with the SPLINE command. The problem I am having is that I have been only able to get the spline command to recognize the first element of the list automatically. Following is the basic code:

code:
Code:
--------------------------------------------------------------------------------

(repeat 5   
(setq pt2 (getpoint ("\n enter point")))
(setq l1 (append l1 (list pt2)))
(command "spline" (car l1)
)

--------------------------------------------------------------------------------

As you can see above, this routine will get me the first point in the list l1, however, if I try to loop to get futher points in the list, I am not able to get further in. Does anyone know how to go about this process? Thanks!
Tom
 
Replies continue below

Recommended for you

(command "spline" (car pnts))
(setq no 0)
(repeat (length pnts)
(setq no (1+ no))
(command (nth no pnts))
)

As you can see, you only call the spline command once, then successively use (command point) until you are at the end of the spline. One note however, the third to the last point must be an empty carriage return for example:

(setq pnts (list
'(1072.25 844.75 0.0) ;start point
'(901.875 872.25 0.0) ;next point
'(984.313 1152.19 0.0);next point
'(1182.13 1327.81 0.0);next point
'(1610.75 1437.63 0.0);etc
'(2281.13 1509.0 0.0) ;etc
'(2676.75 1338.81 0.0);etc
'(3000.94 1157.69 0.0);etc
'(3105.31 1503.5 0.0) ;etc
'"" ;close point selection
'(3814.19 1607.81 0.0);start tangent
'(4072.44 949.063 0.0);end tangent
))

Hope this helps....
 
You are building a list and running "spline" at the same time. You could do what you want without building a list like this:

;;-------------------------------------
(command "spline")
(while (setq pt (getpoint Enter point: "))
(command pt)
)
(command "" "") ;this is to exit out of spline command
;;-----------------------------

Another way is to build a pointlist:
;;----------------------------------
(setq ptlist nil)
(while (setq pt (getpoint Enter point: "))
(setq ptlist (cons pt ptlist))
)
(setq ptlist (reverse ptlist))
(command "spline")
(foreach x ptlist (command x))
(command "" "")
;;---------------------------------

Hope this helps,
Carl

 
looks like a good case to try
mapcar lambda
but I could never make good use of these. Maybe someone will post here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor