Jump to content

Create MLeader Using Visual LISP


ksperopoulos

Recommended Posts

Can someone give me an idea how to create a mleader style using Visual LISP? Please don't do it for me. I would like to do it myself. I just need a finger to point me in the right direction.

Link to comment
Share on other sites

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • ksperopoulos

    15

  • Tharwat

    10

  • Lee Mac

    3

Top Posters In This Topic

Hi,

 

The Mleader styles lay in each document dictionary and NOT in tables as for Blocks, Layer, Test Styles ... etc.

So you can retrieve the dictionary entity name with the use of the following codes:

 

(cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")))

Then you should search for your Mleader Style name if it is not already existed in the current document' s dictionary then after that you could safely add your MLStyle by converting the Dictionary entity name to VLA-Object then use the vla-add-object function to add your desired MLStyle then after that , with the newly created VLA-object that represents the MLS you can set the properties of the style as best as you looking forward, Like Text Height , Text Style , Arrow Size .... etc.

 

Hope this clear enough for you to start with.

Link to comment
Share on other sites

Thank you Tharwat. I had already gotten to that point of searching the dictionary by doing just what you said. But when I try to add the style, I am not sure what to use for the vla-add function. According to the examples within the help file, they use vla-get-(something) and set that to a variable before adding anything new to the dictionary. I'm not sure what (something) is after the vla-get. I have tried 'mleaderstyle(s)', 'acadmleaderstyle(s)', and 'acad_mleaderstyle(s)'. None of which work.

Link to comment
Share on other sites

Happy that my explanations were understood.

 

As I said before you should use the function vla-add-object and you can not use the function vla-add in this case because vla-add is to add a member to a COLLECTION and NOT to a DICTIONARY.

 

And to ease the issue a bit , you'd better use vlax-invoke 'AddObject "AcDbMLeaderStyle" and as I said before the vla-object should represent the dictionary entity name.

 

Good luck.

Edited by Tharwat
missing the word NOT
Link to comment
Share on other sites

Oops! I thought you when you said vla-add-object, the "object" part of the function name was referring to the converted entity. I will test this out with the correct method now. Thank you.

Link to comment
Share on other sites

FYI - I had a little trouble finding vla-add-object in the help file. Just so nobody else gets confused, the function name is actually vla-addobject (no hyphen between "add" and "object").

 

Thanks again Tharwat!

Link to comment
Share on other sites

I don't understand the vlax-invoke-method function. I was able to add the mleader style without it. Why is this necessary in your opinion?

Link to comment
Share on other sites

I don't understand the vlax-invoke-method function. I was able to add the mleader style without it. Why is this necessary in your opinion?

 

It is not necessary, both are with the same result.

Link to comment
Share on other sites

FWIW - Instead of using dictsearch to find something in the dictionary and then converting the entity into a vla-object, I wanted to find a way to make it work using the Active X method. It seems that if I use the following, I am able to receive the same results:

 

(setq acadobj (vla-get-acad-object)
       doc (vla-get-activedocument acadobj)
       dict (vla-item (vla-get-dictionaries doc) "ACAD_MLEADERSTYLE")
)

 

...and then I can search for the mleader style name I'm looking for by doing this:

 

(vla-item dict "[i]mleader style name[/i]")

 

If this is not correct, would one of the more experienced coders let me know so I don't provide inaccurate information for someone else to use?

Link to comment
Share on other sites

(setq acadobj (vla[color=red][b]x[/b][/color]-get-acad-object) [color=blue];; the char x was missing [/color]
       doc (vla-get-activedocument acadobj)
       dict (vla-item (vla-get-dictionaries doc) "ACAD_MLEADERSTYLE")
)

 

Yes that is correct and better than converting to vla-object. But did you try to search for your MLStyle name while it is not existed into your drawing your codes as follows?

 

...and then I can search for the mleader style name I'm looking for by doing this:

 

(vla-item dict "[i]mleader style name[/i]")

Link to comment
Share on other sites

Oh.:oops:

 

I guess I would have to have a vl-catch-all-apply and vl-catch-all-error-p functions to accommodate for this. Right?

Link to comment
Share on other sites

For me I retrieve all MLStyle names first into a list then use member function to search if a specific MLStyle name is found then do the stuff ...

 

eg.

(vlax-for x dict
 (setq lst (cons (vla-get-name x) lst))
 )

Link to comment
Share on other sites

Yeah, I was using.....

 

(setq dict (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE"))))

 

and then.....

 

(null (dictsearch dict "[i]mleader style name[/i]"))

 

.....to find out if it existed within the drawing. But I wanted to investigate another way of doing it as well. I guess there isn't a "best" way.

Link to comment
Share on other sites

AFAIK, there is not a VL function to search for a specific item in Table, Dictionary ... etc

 

...well, at least not a quick, direct way.

Link to comment
Share on other sites

AFAIK, there is not a VL function to search for a specific item in Table, Dictionary ... etc

 

There is vla-item; the difference is that whilst most Vanilla AutoLISP functions will simply return nil when something doesn't work/isn't found, ActiveX methods will throw an exception under such circumstances.

 

Though, writing a wrapper to emulate the behaviour of Vanilla functions isn't too difficult.

Link to comment
Share on other sites

There is vla-item

 

Doesn't vla-item return an object and not a list? I knew vl-catch-all-apply and vl-catch-all-error-p would be the solution to what Tharwat was warning me about based on examples you have given me before. I am curious though - doesn't vl-catch-all-apply require a list and not an object?

Link to comment
Share on other sites

Doesn't vla-item return an object and not a list?

 

Yes - the object residing at the given index in the collection.

 

doesn't vl-catch-all-apply require a list and not an object?

 

Yes, a list of arguments against which the supplied function will be applied; vl-catch-all-apply operates in the same way as the apply function, however, will catch any exceptions thrown by the function being evaluated.

Link to comment
Share on other sites

Ok. So in this case, would the vl-catch-all-apply function be applied like this?

 

(vl-catch-all-apply 'vla-item (vla-item (vla-get-dictionaries doc) "ACAD_MLEADERSTYLE") ([i]mleader style name[/i]))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...