Jump to content

Recommended Posts

Posted

Is there a better way of giving the coordinates to a command than what I've been using?

 

(setq pnt-list (assoc 10 ent))

(setq pnt-x (rtos (nth 0 pnt-list)))

(setq pnt-y (rtos (nth 1 pnt-list)))

(setq pnt-z (rtos (nth 2 pnt-list)))

(command "_.CIRCLE"

(strcat pnt-x "," pnt-y "," pnt-z)

radius

)

Posted
Is there a better way of giving the coordinates to a command than what I've been using?

 

(setq pnt-list (assoc 10 ent))

(setq pnt-x (rtos (nth 0 pnt-list)))

(setq pnt-y (rtos (nth 1 pnt-list)))

(setq pnt-z (rtos (nth 2 pnt-list)))

(command "_.CIRCLE"

(strcat pnt-x "," pnt-y "," pnt-z)

radius

)

 

 

(setq pnt-list (cdr (assoc 10 ent)))

 

The ASSOC return a list , whose first element is the code itself [10]

and the following are the 3 point´s coordinates , in this case

 

From this site

 

http://ronleigh.info/autolisp/acatalog.htm

 

assoc ..... Searches an association list for a key element and returns the sublist starting including the key element. After (setq carlist (list (list "year" "1940") (list "make" "buick") (list "model" "sedan")))

(assoc "make" carlist) returns ("make" "buick")

 

Cdr , strip the first element of a list

 

 

cdr ..... Returns a list containing all elements but the first. See note below. (cdr (list 2 4 6 8)) returns (4 6 8)

(cdr (list (list 1 2) (list 3 4) (list 5 6) (list 7 8))) returns ((3 4) (5 6) (7 8))

(cdr (list 9)) returns nil

Posted

thanks devitg

 

I can see that my nth's should have started at 1 to miss the first list member (which I have been doing - typo) but I am happier that I can use cdr.

Posted

You can send a list to the command, you don't have to put in text format. So the following shorter code should work:

 

(setq pnt-list (assoc 10 ent))

(setq pnt-xyz (cdr pnt-list))

(command "_.CIRCLE" pnt-xyz radius)

Posted

I think extra variables no need:

 

(command "_.CIRCLE" (cdr(assoc 10 ent))radius)

 

If you need variable in other place of your program:

 

(command "_.CIRCLE" (setq pnt-xyz(cdr(assoc 10 ent)))radius)

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...