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
Solved! Go to Solution.
Solved by p_mcknight. Go to Solution.
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.
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
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.
What value type is returned by (getvar "CTAB")? Is that compatible as an argument to the (assoc ...) function, via the Layoutinfo variable?
@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