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

Lisp Routine Functions Differently From the CUI vs. Tool Palette

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
276 Views, 2 Replies

Lisp Routine Functions Differently From the CUI vs. Tool Palette

Hello:

I have a simple "shadow box" LISP routine that will function normally when invoked from my Custom User Interface (CUI) menu - but will not fuction when I create a tool for it in a Tool Palette. As you can see below, the routine is fairly simple . . . it saves the current layer (clayer); creates a custom layer for the shadow-box; draws the shadow-box with only two inputs; and restores the original layer.

(defun C:Shdw_Box (/ clayer ll ur ul lr tx pw ll2 lr2 ur2)

(setq clayer (getvar "CLAYER"))

(command "-LAYER" "M" "G-Symb-Shdw-Box" "C" "YELLOW" "" "LW" "0.35" "" "Lt" "Continuous" "" "")

(setq ll (getpoint "\nPick Lower-Left Corner: ")
ur (getpoint "\nPick Upper-Right Corner: ")
ul (list (car ll) (cadr ur))
lr (list (car ur) (cadr ll))
tx (getvar "TEXTSIZE") pw (/ tx 3.0) ll2 (list (+ (min (car ll) (car lr) (car ul) (car ur)) (* pw 2.0))
(- (min (cadr ll) (cadr lr) (cadr ul) (cadr ur)) (* pw 0.75)))
lr2 (list (+ (max (car ll) (car lr) (car ul) (car ur)) (* pw 0.75))
(- (min (cadr ll) (cadr lr) (cadr ul) (cadr ur)) (* pw 0.75)))
ur2 (list (+ (max (car ll) (car lr) (car ul) (car ur)) (* pw 0.75))
(- (max (cadr ll) (cadr lr) (cadr ul) (cadr ur)) (* pw 2.0))))

(command "PLINE" ll "W" 0 "" lr ur ul "C"
"PLINE" ll2 lr2 ur2 "" "PEDIT" "L" "W" (* pw 1.5) "")

(command "-LAYER" "S" clayer "")

(princ))

I execute the routine with the following: ^c^c^p(Load "Shdw_Box") shdw_box;^p

When executed from the CUI menu, I am prompted for both inputs (lower left and upper right).

However, when executed from the tool palette it skips past the "Pick Lower-Left Corner" without allowing an input and pauses on the "Pick Upper-Right Corner" selection. Afterwhich, I get the following error message:
Pick Upper-Right Corner: bad argument type: numberp: nil

Can anyone help me with this issue? I am not an experienced LISP programmer and am baffled why the routine works flawlessly when executed from one source and not another.

Cheers! Edited by: mikem@themcdermottgroup.com on Jan 14, 2009 3:00 AM
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

I had some time to play with your problem. I was surprised that the
problem showed up on my system as well. I experimented with some
solutions. I started putting all the setq's in separate lists but no
help. I didn't bother to remove them. I then added some error checking
with a while loop to "hold" the system until a valid response is given
for the first prompt. On the request for the second point I put an (if
test to check that the first point was valid and changed it to
(getcorner ll to make it draw a temporary rectangle - just for cosmetic
purposes.

You could investigate the use if the (initdia function to do more error
checking if you wish.

My code which worked was

(while (not(setq ll (getpoint "\nPick Lower-Left Corner: "))))
(if ll(setq ur (getcorner ll "\nPick Upper-Right Corner: ")))

(remember my list per setq function when you look at the brackets above.

You might like to make the routine a little more robust and general
purpose by calculating the width of the shadow pline based on the size
of the rectangle rather than making it fixed width. You could for
instance calculate the length of the diagonal line (distance ll ur) and
make the width say 0.05 of that length.

George Drayton CD-CAD Ltd Christchurch New Zealand
Message 3 of 3
Anonymous
in reply to: Anonymous

Thanks Goerge . . . your "while" and "if" codes worked great! It nice being able to use the Shadow-Box routine from the the CUI and Tool Palette.

Cheers!

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

Post to forums  

Autodesk Design & Make Report

”Boost