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

VLISP to determine annotative status of current MLeaderStyle

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
dmfrazier
677 Views, 9 Replies

VLISP to determine annotative status of current MLeaderStyle

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.

9 REPLIES 9
Message 2 of 10
pbejse
in reply to: dmfrazier

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.

 

Message 3 of 10
dmfrazier
in reply to: pbejse

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.

Message 4 of 10
Jeff_M
in reply to: dmfrazier

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

 

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 10
Ian_Bryant
in reply to: dmfrazier

Hi,

(cdr (assoc 296
   (dictsearch
       (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")))
       (getvar "CMLEADERSTYLE")
   )
))

returns 1, when current the mleaderstyle is annotative

and returns 0 when it is not.

 

Ian

 

Message 6 of 10
pbejse
in reply to: dmfrazier


@dmfrazier wrote:

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 Smiley Very Happy

 

Cheers

 

Message 7 of 10
dmfrazier
in reply to: pbejse

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.

Message 8 of 10
dmfrazier
in reply to: Jeff_M

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.

Message 9 of 10
dmfrazier
in reply to: Ian_Bryant

Thank you.  Your code works just as well.

Message 10 of 10
pbejse
in reply to: dmfrazier


@dmfrazier wrote:

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.

 

Cheers

 

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

Post to forums  

Autodesk Design & Make Report

”Boost