Visual LISP, AutoLISP and General Customization

Reply
*Pro
Posts: 2,487
Registered: ‎05-13-2003
Message 1 of 10 (407 Views)
Accepted Solution

VLISP to determine annotative status of current MLeaderStyle

407 Views, 9 Replies
01-13-2012 12:46 PM

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.

*Expert Elite*
Posts: 2,369
Registered: ‎11-24-2009
Message 2 of 10 (396 Views)

Re: VLISP to determine annotative status of current MLeaderStyle

01-13-2012 08:18 PM 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.

 

*Pro
Posts: 2,487
Registered: ‎05-13-2003
Message 3 of 10 (368 Views)

Re: VLISP to determine annotative status of current MLeaderStyle

01-16-2012 06:11 AM 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.

*Expert Elite*
Jeff_M
Posts: 3,950
Registered: ‎07-22-2003
Message 4 of 10 (350 Views)

Re: VLISP to determine annotative status of current MLeaderStyle

01-16-2012 04:27 PM 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
Valued Mentor
Posts: 362
Registered: ‎06-02-2005
Message 5 of 10 (349 Views)

Re: VLISP to determine annotative status of current MLeaderStyle

01-16-2012 04:44 PM 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

 

*Expert Elite*
Posts: 2,369
Registered: ‎11-24-2009
Message 6 of 10 (338 Views)

Re: VLISP to determine annotative status of current MLeaderStyle

01-16-2012 08:05 PM 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 :smileyvery-happy:

 

Cheers

 

*Pro
Posts: 2,487
Registered: ‎05-13-2003
Message 7 of 10 (330 Views)

Re: VLISP to determine annotative status of current MLeaderStyle

01-17-2012 05:22 AM 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.

*Pro
Posts: 2,487
Registered: ‎05-13-2003
Message 8 of 10 (328 Views)

Re: VLISP to determine annotative status of current MLeaderStyle

01-17-2012 05:43 AM 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.

*Pro
Posts: 2,487
Registered: ‎05-13-2003
Message 9 of 10 (327 Views)

Re: VLISP to determine annotative status of current MLeaderStyle

01-17-2012 05:47 AM in reply to: Ian_Bryant

Thank you.  Your code works just as well.

*Expert Elite*
Posts: 2,369
Registered: ‎11-24-2009
Message 10 of 10 (318 Views)

Re: VLISP to determine annotative status of current MLeaderStyle

01-17-2012 06:09 AM 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

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community