Jump to content

Import Symbol from User Libraries


Recommended Posts

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!

Link to comment

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.

Link to comment

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.

 

  • Like 1
Link to comment

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.

  • Like 1
Link to comment
  • 1 year later...
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?

 

Link to comment
  • 3 weeks later...

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

 

  • Like 1
Link to comment

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