I have some automation that (among other things) sets the MLEADERSCALE based on a selected scale factor. It works fine when the current MLeaderStyle is not annotative, but the routine crashes prematurely when it is annotative (because MLEADERSCALE can only be set to zero when the current MLeaderStyle is annotative.) What I would like to be able to do is determine the annotative status of the current MLeaderStyle ahead of time so that the routine can either proceed or skip setting MLEADERSCALE. Determining the name of the current MLeaderStyle is easy, but how can I tell (with VLISP) if that style is annotative?
Thanks in advance.
Solved! Go to Solution.
I can see your predicament. If MleaderScale system variable is 0.0 it still NOT a guarantee current Mleaderstyle is Annotative
One way to prvent the code from crashing when setting Mleaderscale to a new value is to use a snippet similar to this
(cond ((and (vl-catch-all-error-p (vl-catch-all-apply 'setvar (list "MleaderScale" val))) (setvar 'cmleaderstyle "Standard") ;<--- a None Annotative Mleader style (setvar 'MleaderScale val) ) ) )
The snippet will first set the Mleaderstyle it to the desired scale factor, if the current Mleaderstyle is indeed Annotative instead of prematurely ending the function it will instead set the currrent mleadertstyle to a KNOWN None annotative Mleaderstyle.
Of course you may need to test for the existence of that Mleaderstyle, but i'm pretty sure you c an hanlde that.
Thanks for the suggestion. That might've made for a nice "work-around", but unfortunately it doesn't work due to an incorrect assumption. The MLeaderStyle "Standard" is not guaranteed to be "non-annotative". (The drawing that brought the issue to my attention happens to have that MLeaderStyle defined as annotative.)
I suppose I could create a temporary (dummy) non-annotative MLeaderStyle, make it current, set the MLeaderScale to a non-zero value, and then change MLeaderStyle back to its original, potentially annotative setting (just to be the considerate programmer that I try to be), but then, if it is annotative, MLeaderScale would spontaneously return to zero. A bit of a conundrum, eh?
What I really “need” is a way to tell when the current MLeaderStyle is annotative. I know that the properties of an MLeaderStyle are stored in a dictionary, and one of these properties is the annotative status, but AutoCAD’s help is very vague on how to access it.
This should help:
(setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq mldr_dict (vla-item (vla-get-dictionaries doc) "ACAD_MLEADERSTYLE")) (setq mldr_style (vla-item mldr_dict 0)) ;;replace 0 with the name of the style (setq isAnnotative (vla-get-annotative mldr_style))
(cdr (assoc 296
(cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")))
returns 1, when current the mleaderstyle is annotative
and returns 0 when it is not.
Thanks for the suggestion. That might've made for a nice "work-around", but unfortunately it doesn't work due to an incorrect assumption. The MLeaderStyle "Standard" is not guaranteed to be "non-annotative".
That is correct, it is a workaround.but its not an assumption but a suggestion and i did say
........ currrent mleadertstyle to a KNOWN None annotative Mleaderstyle.
Of course you may need to test for the existence of that Mleaderstyle........
and the comment that goes with it
;<--- a None Annotative Mleader style
Anyhoo .. you are right, my bad . its not what you asked for
Thank you for pointing out my misinterpretation. Perhaps my tone struck you as critical, but my comments in reply were not meant to be "destructive", merely explanatory. If it were not for my preference to retain or restore the user's current MLeaderStyle when the routine is finished (something I did not indicate in my original post), your suggestion would have been fine.
Again, thanks for your input.
Yes, it does help. It is exactly what I needed. (I had a bunch of the pieces, but the "vla-item" was the part I wasn't able to figure out.)
Thanks for your help.
Thank you for pointing out my misinterpretation.
No worries dmfrazier, I misunderstood your question really..
Like i said. my bad. Jeff_M & Ian_Bryant helped you out after all.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.