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

IF or COND statement ---- need help

15 REPLIES 15
Reply
Message 1 of 16
hcanas
720 Views, 15 Replies

IF or COND statement ---- need help

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

 

DC
15 REPLIES 15
Message 2 of 16
Anonymous
in reply to: hcanas

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

 

 

 

Message 3 of 16
dbroad
in reply to: hcanas

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

 

Architect, Registered NC, VA, SC, & GA.
Message 4 of 16
hcanas
in reply to: Anonymous

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

DC
Message 5 of 16
hcanas
in reply to: hcanas

Thank you dyoung and dbroad

I still having the probelm, paper_sz2 turn NIL.... see attachment

I did try both of you sugestion...

 

DC
Message 6 of 16
Anonymous
in reply to: hcanas

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

 

Message 7 of 16
Lee_Mac
in reply to: Anonymous

dyoung wrote:

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")
)
Message 8 of 16
hcanas
in reply to: Anonymous

NO, is not working, thank you guys...

 

DC
Message 9 of 16
Anonymous
in reply to: Lee_Mac


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

 

 

Message 10 of 16
Anonymous
in reply to: hcanas


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

 

 

Message 11 of 16
hmsilva
in reply to: hcanas


@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

 

EESignature

Message 12 of 16
hcanas
in reply to: hcanas

thank you Lee_Mac

let me try those methods....

 

DC
Message 13 of 16
hcanas
in reply to: Anonymous

Thank you  Lee_Mac I will try your sugestions... I will let you know..

 

DC
Message 14 of 16
hcanas
in reply to: Anonymous

thank you Lee Mac, I will try your suggestions...
 
 
DC
Message 15 of 16
hcanas
in reply to: Anonymous

I will try your sugestion LEE MAC... thanks...Smiley Happy

DC
Message 16 of 16
Lee_Mac
in reply to: hcanas

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

Post to forums  

Autodesk Design & Make Report

”Boost