sully8391 Posted June 21, 2020 Share Posted June 21, 2020 Hi all, I have some plugin objects that I would like to use predefined symbols instead of drawing their geometry for each instance, but I'm having a lot of trouble figuring out how to import a symbol from a user library. It looks like the functions under "Document List Handling" might hold the key, but I can't make any sense out of them. Is what I'm trying to do possible? What would a basic script for this look like? Thanks! Quote Link to comment
Pat Stanford Posted June 21, 2020 Share Posted June 21, 2020 You seem to be on the right track with Document List Handling. Basically you need to build a resource list. Since there are your symbols and you should know the name, I would start with BuildResourceListN. This will return a ListID into a LongInt that you will use to identify the list in the laters calls. Then iterate throughout the resource list using GetNamefromResourceList and checking that against the symbol name you want. Once you locate the index of the symbol you want, import it into the current file with ImportResoucetoCurrentFile. And as there are a multiple versions of most of the above functions/procedures, you will have to read the manual and experiment with what works best for you. Ask again if you need more help. Quote Link to comment
sully8391 Posted June 21, 2020 Author Share Posted June 21, 2020 Thanks for this! I finally got it working. GetNameFromResourceList, and variations on that, will return empty strings/handles if called before ImportResourceToCurrentFile. In my case that's no big deal, because I intend to import all of the symbols anyway. It's also worth noting that the resource list starts its indices at 1. 1 Quote Link to comment
JBenghiat Posted June 22, 2020 Share Posted June 22, 2020 You should be able to get the name of the resource before you import. You cannot get handles to objects outside of the current document, as only objects from open documents get loaded into memory. Generally, I will use GetObject for each name on the list, and if the handle is nil, import the resource. 1 Quote Link to comment
sully8391 Posted June 25, 2020 Author Share Posted June 25, 2020 Thanks for the clarification! I'll have to take a look again. Quote Link to comment
The Hamma Posted October 16, 2021 Share Posted October 16, 2021 On 6/21/2020 at 3:54 PM, sully8391 said: Thanks for this! I finally got it working. GetNameFromResourceList, and variations on that, will return empty strings/handles if called before ImportResourceToCurrentFile. In my case that's no big deal, because I intend to import all of the symbols anyway. It's also worth noting that the resource list starts its indices at 1. Can you share your working script? Quote Link to comment
Jayme McColgan Posted November 4, 2021 Share Posted November 4, 2021 it might be solved at this point but here is how i handle importing symbols from a cad that lives in the favorites folder. be aware the only limitation to this is theres no current way of adding a folder inside of a symbol folder. ### list of symbols i need to bring in for the plugin speaker_stuff = ["JBL A8", "JBL A8-Bumper", "JBL A8-Sub", "JBL VT4886", "JBL VT4886-Bumper"] ### function to import and create folder if needed def importaudiofolder(): speakerfolder = "Audio" audiopluginfolder = "Audio Plugin Stuff" ### see if the folder(and the symbols) already exist in the drawing foldername = vs.GetObject(speakerfolder) ### make the folder if it doesnt exist (because i like clean drawings) if foldername == "0": vs.NameObject(speakerfolder) vs.BeginFolder() vs.NameObject(audiopluginfolder) vs.BeginFolder() vs.EndFolder() vs.EndFolder() audiopartsfolderrname = vs.GetObject(audiopluginfolder) ### import the symbols from the list into the folder from above for i in range(len(speaker_stuff)): vs.CopySymbol('Libraries\Favorites\{insert_cad_name_here}.vwx', speaker_stuff[i]) name = vs.GetObject(speaker_stuff[i]) vs.InsertSymbolInFolder(audiopartsfolderrname, name) return None 1 Quote Link to comment
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.