Jump to content
Sign in to follow this  
nj1105nj

Seem to be getting a CLayer Nil return on this very simple Lisp code. Any ideas?

Recommended Posts

nj1105nj

This is just a lisp to draw a 6' circle on our no plot layer, set the line weight, and change the color to magenta, and finally change back all the set variables

(princ)
(defun C:mrs
    (progn
      (setvar "clayer" nplt)
      (setvar "celweight" -2)
      (setvar "cecolor" magenta)
      (command "circle" "6")
      (setvar "clayer" 0)
      (setvar "cecolor" bylayer)
      (setvar "celweight" bylayer)
  )
  (princ)
)

Share this post


Link to post
Share on other sites
Tharwat

You set the current layer with nil variable but if that is the name of the layer then you need to wrap it with two strings all around. eg: "nplt"

Share this post


Link to post
Share on other sites
nj1105nj
31 minutes ago, Tharwat said:

You set the current layer with nil variable but if that is the name of the layer then you need to wrap it with two strings all around. eg: "nplt"

so it should be like this? It's still saying the Clayer Nil was a rejected variable

 

(defun C:mrs
    (progn
      (setvar "clayer" "nplt")
      (setvar "celweight" -2)
      (setvar "cecolor" magenta)
      (command "circle" "6")
      (setvar "clayer" "0")
      (setvar "cecolor" bylayer)
      (setvar "celweight" bylayer)
  )
  (princ)
)

Share this post


Link to post
Share on other sites
Tharwat

Is this what you are after?

(defun c:mrs nil
  (if (tblsearch "LAYER" "nplt")
    (progn
      (setvar "clayer" "nplt")
      (setvar "celweight" -2)
      (setvar "cecolor" "6")
      (command "circle" "6" "\\")
      (setvar "clayer" "0")
      (setvar "cecolor" "bylayer")
      (setvar "celweight" -1)
    )
    (alert "Layer name <nplt> was not found <!>")
  )
  (princ)
)

 

  • Thanks 1

Share this post


Link to post
Share on other sites
nj1105nj
21 minutes ago, Tharwat said:

Is this what you are after?


(defun c:mrs nil
  (if (tblsearch "LAYER" "nplt")
    (progn
      (setvar "clayer" "nplt")
      (setvar "celweight" -2)
      (setvar "cecolor" "6")
      (command "circle" "6" "\\")
      (setvar "clayer" "0")
      (setvar "cecolor" "bylayer")
      (setvar "celweight" -1)
    )
    (alert "Layer name <nplt> was not found <!>")
  )
  (princ)
)

 

That seems to have done the trick, thank you!

Share this post


Link to post
Share on other sites
Tharwat

You need to disable the OSNAP system variable to ensure is that the center point of the circle would be positioned in the right destination as follows.

 (command "circle" "_none" "6" "\\")

 

Share this post


Link to post
Share on other sites
Roy_043

Hmm, have the prompts of the circle command really been changed around in AutoCAD?

Edited by Roy_043
Typo.

Share this post


Link to post
Share on other sites
BIGAL

Note also (setvar "cecolor" magenta) magenta would be expected to be a lisp value called Magenta, hence Tharwat's code using a string number.

Edited by BIGAL

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Sign in to follow this  

×
×
  • Create New...