I have a plot data file where everybody write in at the point that they make a plot,
but I have a problem where the paper size is reported, I did try with a COND and IF statement
but still reporting the plotter paper size in the form of "USER2307", I trying to get on the form
that a human can understand like "17x11"
my lisp look like this....
=========================
(setq Paper_sz (vla-get-CanonicalMedianame (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object)))))
;(cond
(if (= Paper_sz "user1282")(setq Paper_sz2 "8.5x11" ))
(if (= Paper_sz "user2307")(setq Paper_sz2 "17x11" ))
(if (= Paper_sz "user2308")(setq Paper_sz2 "22x17" ))
(if (= Paper_sz "user2309")(setq Paper_sz2 "34x22" ))
😉
Please help, really apreciate you time...
You're using 2 different variable names "Paper_sz" and "Paper_sz2". Without seeing the rest of your code, I'm speculating you're writing out the wrong variable.
The other thing is you're testing a lower case string against whatever Autodesk throws your way. It's best practice to take AutoCAD's value and force it upper/lower (doesn't matter which) and test against that expected state of the string. You can't be certain that AutoCAD will always return the information one way. It may very well return the same way all the time but 1 new programmer on the next release could render your code "Broke" in a future upgrade. This insulates your code from those situations.
(if (= (strcase Paper_sz) "USER1282")(setq Paper_sz2 "8.5x11" )) (if (= (strcase Paper_sz) "USER2307")(setq Paper_sz2 "17x11" )) (if (= (strcase Paper_sz) "USER2308")(setq Paper_sz2 "22x17" )) (if (= (strcase Paper_sz) "USER2309")(setq Paper_sz2 "34x22" ))
One way that it might work. Very quickly looked at and not tested. I also agree with Darren's concerns and solution.
(setq Paper_sz (vla-get-CanonicalMedianame (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object)) ) ) ) (setq Paper_sz2 (cond ((= Paper_sz "user1282") "8.5x11") ((= Paper_sz "user2307") "17x11") ((= Paper_sz "user2308") "22x17") ((= Paper_sz "user2309") "34x22") ) )
Thank you Darren,
you are right with the 2 different variable names, I was triying diferent ways to get what I need, I shoul post it this....
(setq Paper_sz (vla-get-CanonicalMedianame (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object)))))
(if (= Paper_sz "user1282")(setq Paper_sz "8.5x11" ))
(if (= Paper_sz "user2307")(setq Paper_sz "17x11" ))
(if (= Paper_sz "user2308")(setq Paper_sz "22x17" ))
(if (= Paper_sz "user2309")(setq Paper_sz "34x22" ))
Why my paper size always report "user2307" for 17x11 paper size, what I doing wrong.?
thank you..
Thank you dyoung and dbroad
I still having the probelm, paper_sz2 turn NIL.... see attachment
I did try both of you sugestion...
COND is not going to return the value to the SETQ function.
(cond ((= (strcase Paper_sz) "USER1282")(setq Paper_sz2 "8.5x11")) ((= (strcase Paper_sz) "USER2307")(setq Paper_sz2 "17x11")) ((= (strcase Paper_sz) "USER2308")(setq Paper_sz2 "2217")) ...etc... (T (setq Paper_sz2 nil)) ) (if Paper_sz2 (Alert "Error: Unknown Condition") (Alert (strcat Paper_sz " = " Paper_sz2)) )
COND is not going to return the value to the SETQ function.
Yes it will.
Here are various ways to approach the task:
(if (setq Paper_sz2 (cond ( (= (strcase Paper_sz) "USER1282") "8.5x11") ( (= (strcase Paper_sz) "USER2307") "17x11") ( (= (strcase Paper_sz) "USER2308") "2217") ) ) (alert (strcat Paper_sz " = " Paper_sz2)) (alert "Error: Unknown Condition") )
(if (setq Paper_sz2 (cdr (assoc (strcase Paper_sz) '( ("USER1282" . "8.5x11") ("USER2307" . "17x11") ("USER2308" . "2217") ) ) ) ) (alert (strcat Paper_sz " = " Paper_sz2)) (alert "Error: Unknown Condition") )
(if (setq Paper_sz2 (vl-some '(lambda ( a b ) (if (= a (strcase Paper_sz)) b)) '("USER1282" "USER2307" "USER2308") '("8.5x11" "17x11" "2217") ) ) (alert (strcat Paper_sz " = " Paper_sz2)) (alert "Error: Unknown Condition") )
(if (setq Paper_sz2 (if (= (strcase Paper_sz) "USER1282") "8.5x11" (if (= (strcase Paper_sz) "USER2307") "17x11" (if (= (strcase Paper_sz) "USER2308") "2217" ) ) ) ) (alert (strcat Paper_sz " = " Paper_sz2)) (alert "Error: Unknown Condition") )
@Lee_Mac wrote:@Anonymous wrote:COND is not going to return the value to the SETQ function.
Yes it will.
Correct you are. Last time I freehand a COND statement into the command line. Not sure what I was thinking. However I tend not to do that as many of my COND statements have muliple things going on and it's only going to return the last one for the sub that's evaluated true.
@hcanas wrote:NO, is not working, thank you guys...
Really hard to troubleshoot without more feedback than "No".
Sprinkle a few alert functions in the code to display the values as the code runs so you can see what's going on or to verify if it's hitting the condition you expect.
You could also walk through the VLIDE and do the same with a watch window if you're familiar with it.
@hcanas wrote:
I have a plot data file where everybody write in at the point that they make a plot,
but I have a problem where the paper size is reported, I did try with a COND and IF statement
but still reporting the plotter paper size in the form of "USER2307", I trying to get on the form
that a human can understand like "17x11"
Something like this perhaps.
(setq aclyt (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object))) cmname (vla-get-CanonicalMedianame aclyt) Paper_sz (vla-GetLocaleMediaName aclyt cmname) )
hope that helps
Henrique