Jump to content

Draw circles


marc578

Recommended Posts

Hi, this is my first post.

 

I am trying to draw five circles, one in the centre (x=0, y=0) and the other four, located in each quadrant of circle located in (0,0).

 

I have written the script below but, I does not work. The circles with negative coordinates are drawn on top of the other with positive coordinates.

 

I do not understand, why is this behavior, if you know please let me know.

(defun C:he ()
  (setq r 10.0)
  (command "circle" (list 0 0) r "")
  (command "circle" (list 5 0) r "")
  (command "circle" (list -5 0) r "")
  (command "circle" (list 0 5) r "") 
  (command "circle" (list 0 -5) r "")  
	   )

Thanks

 

Link to comment
Share on other sites

Thank you for the prompt response. I have not seen this type of detail in reference guide neither the developer guide.

Is there any source of information that goes to that level of detail, I recall that the autolisp reference 2000 is more complete that the current one (2013).

Regards,

Link to comment
Share on other sites

1 hour ago, marc578 said:

Thank you for the prompt response. I have not seen this type of detail in reference guide neither the developer guide.

Is there any source of information that goes to that level of detail, I recall that the autolisp reference 2000 is more complete that the current one (2013).

Regards,

 

Running a (command "???") within lisp differs slightly from running it on the command line. Your error is likely caused by an osnap being set and snapping to the same point regardless of the coordinates fed in. This can be overcome by storing the current osnap setting (stored in system vaiable "osmode"), turning off osnaps by setting the system variable to 0 (zero) and restoring the old value when finished.

 

You are also inadvertently setting the "circlerad" system variable by passing the circle command a radius (repeatedly). 

 

Finally the circle command, when activated from lisp doesn't require a return after each item. This is implied. If we put all these together, and localise all variables so that they are reset when the program finishes, you lisp could be rewritten as :

 

(defun c:he ( / osm crad)
  (cond ( (/= 0 (getvar "osmode")) (setq osm (getvar "osmode")) (setvar "osmode" 0)))
  (cond ( (/= 10 (getvar "circlerad")) (setq crad (getvar "circlerad")) (setvar "circlerad" 10.0)))
  (command "circle" (list 0 0) ""); since we have set the circle radius via the circlerad system variable we just need to return through the radius prompt = ""
  (command "circle" (list 5 0) "")
  (command "circle" (list -5 0) "")
  (command "circle" (list 0 5) "")
  (command "circle" (list 0 -5) "")
  (if crad (setvar "circlerad" crad)); reset to entry state if changed
  (if osm (setvar "osmode" osm)); reset to entry state if changed
  (princ)
)

 

If you want to refine it further so that it will do a list of points

 

(defun c:he ( / osm crad)
  (cond ( (/= 0 (getvar "osmode")) (setq osm (getvar "osmode")) (setvar "osmode" 0)))
  (cond ( (/= 10 (getvar "circlerad")) (setq crad (getvar "circlerad")) (setvar "circlerad" 10.0)))

  (foreach pt (list (list 0 0) (list 5 0) (list -5 0) (list 0 5) (list 0 -5))
    (command "circle" pt "")
  )

  (if crad (setvar "circlerad" crad)); reset to entry state if changed
  (if osm (setvar "osmode" osm)); reset to entry state if changed
  (princ)
)

 

 

 

Link to comment
Share on other sites

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