Jump to content

make keyboard command to set specific layer


NoelStalker

Recommended Posts

Greetings!

 

I came up with this lisp file to create commands to set the current layer. They are not working though and I am wondering why. Is there any problem with my code?

 

 

(defun c:s0 ()

(command "-layer" "s" "0" "" "")

)

(defun c:sd ()

(command "-layer" "s" "dim" "" "")

)

 

Thanks for your assistance.

Link to comment
Share on other sites

I think you could do it this way:

(defun c:s0 ()

(command "-layer" "s" "0" "" "")(PRINC))

(defun c:sd ()

(command "-layer" "s" "dim" "" "")(PRINC))

Link to comment
Share on other sites

Ghost Rider,

What is the (princ) function? I have seen it before but I don't know what it does.

 

I changed my lisp file and restarted AutoCAD but the command still does not work. Here is the error it returns:

 

"Unknown command "S0". Press F1 for help."

Link to comment
Share on other sites

I typed "appload" and then clicked on "contents" in the startup suite and added the lisp file to my startup suite. Then I restarted AutoCAD. What's funny is that the other commands that I define in that lisp file work fine.

Link to comment
Share on other sites

I agree lpseifert, it sounds like the lisp hasn't been loaded before the syntax was called.

 

Either load the LISP during an AutoCAD session: "_appload"

 

Or either use the "Start-up Suite", (can be temperamental sometimes) or include a call to your LISP in the acaddoc.lsp script.

 

Hope this helps! :)

Link to comment
Share on other sites

You guys are right. The code is good. And the command works - it sets the layer correctly. For some reason though, on the "s0" command, it still says "unknown command" even though it works.

Link to comment
Share on other sites

Try this Noel - it may be why you are receiving 'unknown command':

(defun c:s0 ()
(command "-layer" "s" "0" "")(PRINC))
(defun c:sd ()
(command "-layer" "s" "dim" "")(PRINC))

 

Hope this works! :P

Link to comment
Share on other sites

Noel, glad you got it working, I actually can't answer your question of "What is the (princ) function?" I don't understand it all myself either, lpseifert and Lee Mac can I'm sure, I follow all their post trying to learn every chance I get...

I use commands similar to yours for layer control also my lisp is set up as I posted, though I have all those command on my ACAD.lsp file to load everytime, you may want to look into loading yours that way ...

Link to comment
Share on other sites

Hi guys,

 

A little explanation of "princ"

 

princ is used just to print a line of text on the command line:

 

i.e.

 

(princ "Lee") will just print the text "Lee" on the command line.

 

And so, by finishing the LISP with:

 

(princ) -- there is nothing after the "princ" function therefore:

 

the LISP will print a new line on the command line and so the expression from the last function is suppressed, and so you have what is known as a 'clean exit'.

Hope this is helpful in some way :)

Link to comment
Share on other sites

If your have searched and don't have one you can create it and place it in your search path. custom commands and lisp can be loaded all at once.

There's alot of discusssion here about customizations if you search. I'm still learning myself..

Link to comment
Share on other sites

Try this Noel - it may be why you are receiving 'unknown command':

(defun c:s0 ()
(command "-layer" "s" "0" "")(PRINC))
(defun c:sd ()
(command "-layer" "s" "dim" "")(PRINC))

 

Hope this works! :P

 

LeeMac,

I tried your code and it worked! Thanks so much. I don't understand how your code was different than mine though. But yours does not produce the error

 

Regards

Noel

Link to comment
Share on other sites

Hi Noel,

 

Your code was slightly different in the fact that it had a few too many "" terms. And so AutoCAD was trying to repeat the last command before finishing what it was doing (as if the user had hit enter too many times). :P

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