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

Lisp code for getting Layout Name

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
1944 Views, 5 Replies

Lisp code for getting Layout Name

Hey guys,

 

Im having trouble trying to get the code below to work, and currently when i run it the program stops at this point and returns an error through my error handler. im trying to see if the layout name has either the string "detailed" or "stacked" in it and then sign a variable a specific number to use in a calculation later. if anyone can show me where I am going wrong that would be great! Note, ive made it so the drawing only has one layout tab.

 

 (setvar "TILEMODE" 0)

 (setq LayoutInfo (getvar "CTAB"))

 

 (if (wcmatch (setq LayoutName (strcase (cdr (assoc 2 LayoutInfo)))) "*DETAILED*")

 (progn

 (setq DetailedAdj 34.7)

 (setq StackAdj 0)  

 );progn

 

 (progn

  (setq DetailedAdj 0)

  (if (wcmatch (setq LayoutName (strcase (cdr (assoc 2 LayoutInfo)))) "*STACK*")  

   (setq StackAdj 34.7)  

   (setq StackAdj 0)

  );if  

 );progn

);if

 

 

5 REPLIES 5
Message 2 of 6
p_mcknight
in reply to: Anonymous

I didn't really look too much to see why yours is failing.  Personally though I would use vl-string-search rather than the wcmatch to keep things clean.  In addition I would use a cond rather than the nested ifs

 

(setvar "TILEMODE" 0)
(setq LayoutInfo (strcase (getvar "CTAB")))

(cond

((vl-string-search "DETAILED" LayoutInfo)

(setq DetailedAdj 34.7)

(setq StackAdj 0)

)

((vl-string-search "STACK" LayoutInfo)

(setq DetailedAdj 0)

(setq StackAdj 34.7)

(setq StackAdj 0)

)

)

 

The above is untested of course.

Message 3 of 6
Anonymous
in reply to: p_mcknight

Ill give that a try and see what happens, though I dont have very much understanding of any of the functions that start with "vl" so i usually dont use them

Message 4 of 6
p_mcknight
in reply to: Anonymous

I used to not do much on the vl side either but once I took some time to get familiar with how it all works I found that my code became much simpler and more powerful as a result.  Just some friendly advice, try it out, you'll like what you can do.

Message 5 of 6
dgorsman
in reply to: Anonymous

What value type is returned by (getvar "CTAB")?  Is that compatible as an argument to the (assoc ...) function, via the Layoutinfo variable?

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 6 of 6
Gary_J_Orr
in reply to: Anonymous


@Anonymous wrote:

Hey guys,

 

Im having trouble trying to get the code below to work, and currently when i run it the program stops at this point and returns an error through my error handler. im trying to see if the layout name has either the string "detailed" or "stacked" in it and then sign a variable a specific number to use in a calculation later. if anyone can show me where I am going wrong that would be great! Note, ive made it so the drawing only has one layout tab.

 

 (setvar "TILEMODE" 0)

 (setq LayoutInfo (getvar "CTAB"))

 

 (if (wcmatch (setq LayoutName (strcase (cdr (assoc 2 LayoutInfo)))) "*DETAILED*")

 (progn

 (setq DetailedAdj 34.7)

 (setq StackAdj 0)  

 );progn

 

 (progn

  (setq DetailedAdj 0)

  (if (wcmatch (setq LayoutName (strcase (cdr (assoc 2 LayoutInfo)))) "*STACK*")  

   (setq StackAdj 34.7)  

   (setq StackAdj 0)

  );if  

 );progn

);if

 

 


I'm currently on my workstation with 2012 and can't easily verify that the return is the same on the newer releases but, to the best of my knowledge the "ctab" variable still returns a string, not a list...

 

therefore:
 (setq LayoutInfo (getvar "CTAB"))

will return a string...

and:

(cdr (assoc 2 LayoutInfo))

will return nil because there is no list from which to get an Assoc from and therefore nothing to get the CDR from...

therefore strcase will return an error because you are trying to case the symbol nil...

 

Change your wcmatch call (I removed the redundant setq call) to:

(wcmatch (strcase LayoutInfo) "*DETAILED*")

 

-Gary

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)

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

Post to forums  

Autodesk Design & Make Report

”Boost