Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Print Message and cmdecho help request.

5 REPLIES 5
Reply
Message 1 of 6
rogweb
268 Views, 5 Replies

Print Message and cmdecho help request.

Hello all,

I have written a simple lisp routine for layer management. It works great, except for two areas.

1) I would like it to print a message when the "If" statement is not true. (ex. if the layer R4Roof does not exits, then print "Layer Group Does Not Exist", before the command exits.

2.) Currently, I have cmdecho set to 0, which is great if all the layers are there, or if the command exits. However; if R4Roof does exist, but any of the remaining layers in the "on" portion of the command are absent, the layer command scrolls on the command line.

I would like the command line not to echo the layer command in this instance, but I am not sure it is possible...at least, I can't seem to find a way to make it work.

In both of these cases I have tried several methods. The first, I think I am missing something simple, the second, I am not sure it is possible.

The following is the lisp as it sits currently.

(defun R4()
(setvar "cmdecho" 0)
(if (tblsearch "layer" "R4Roof")
(progn
(command "._layer"
"set" "0"
"off" "*" "No"
"on" "R4*,F4Wall,F4WallsAbv,F4WallsBel,Viewports,PS-*"
"off" ""
"set" "R4Roof"
"")
)
)
(setvar "cmdecho" 1)
(princ)
)


Any and help / suggestions are tremendously appreciated!

Thank you,

Roger Message was edited by: RogWeb
5 REPLIES 5
Message 2 of 6
Tom Smith
in reply to: rogweb

1) [code]
(defun R4()
(setvar "cmdecho" 0)
(if (tblsearch "layer" "R4Roof")
(progn
;;your stuff
)
(princ "\nLayer Group Does Not Exist") ;why initial caps?
)
(priinc)
)
[/code]

2) I can't reproduce that behavior.

Note that the routine assumes an EXPERT setting of 0 and will fail otherwise.
Message 3 of 6
rogweb
in reply to: rogweb

Thank you Tom.

1.) That solved my problem...I tried the same line several times with no luck. I think I may have left out the " \n " doh.

Not sure why I "capped" all the words....

2.) Now I can't get it to repeat the behavior either. temporary gremlin perhaps...

Appreciate the help!

Thank you!

Roger
Message 4 of 6
Tom Smith
in reply to: rogweb

The "\n" simply prints a newline character. Otherwise princ would put the message on the last used line of the command prompt. Maybe you were putting the message inside the progn instead of after it.

In cases where a routine depends on a variable setting (as in EXPERT here) it's often easiest to simply set the variable to a known value and then restore it, as you did with CMDECHO. Setting EXPERT=1 or more would eliminate the prompt about turning off the current layer.
Message 5 of 6
rogweb
in reply to: rogweb

Ahhh, thank you VERY much for that explaination. I was wracking my brain on the "Expert" variable.

I am reasonably new to LISP. Starting to get my feet under me though. I appreciate the help from this site and am damn glad it is here!

Thank you again,

Roger
Message 6 of 6
Tom Smith
in reply to: rogweb

You're quite welcome. One thing lisp will do is teach you a lot of Acad variables. It's easy to take your "normal" settings for granted, but then you may find your routine crashes when someone else runs it.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost