Jump to content

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


nj1105nj

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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" "\\")

 

Link to comment
Share on other sites

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