ksperopoulos Posted January 29, 2016 Share Posted January 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 29, 2016 Share Posted January 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 29, 2016 Author Share Posted January 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 29, 2016 Share Posted January 29, 2016 (edited) 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 January 29, 2016 by Tharwat missing the word NOT Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 29, 2016 Author Share Posted January 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 29, 2016 Author Share Posted January 29, 2016 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! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 29, 2016 Share Posted January 29, 2016 Opps I am sorry , my memory did not serve me this time. Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 29, 2016 Author Share Posted January 29, 2016 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? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 29, 2016 Share Posted January 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 31, 2016 Author Share Posted January 31, 2016 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? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 31, 2016 Share Posted January 31, 2016 (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]") Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 31, 2016 Author Share Posted January 31, 2016 Oh. I guess I would have to have a vl-catch-all-apply and vl-catch-all-error-p functions to accommodate for this. Right? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 31, 2016 Share Posted January 31, 2016 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)) ) Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 31, 2016 Author Share Posted January 31, 2016 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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 31, 2016 Share Posted January 31, 2016 AFAIK, there is not a VL function to search for a specific item in Table, Dictionary ... etc Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 31, 2016 Author Share Posted January 31, 2016 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 31, 2016 Share Posted January 31, 2016 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. Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 31, 2016 Author Share Posted January 31, 2016 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? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 31, 2016 Share Posted January 31, 2016 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. Quote Link to comment Share on other sites More sharing options...
ksperopoulos Posted January 31, 2016 Author Share Posted January 31, 2016 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])) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.