Jump to content
Martin Crawford

Symbols and Folder Locations

Recommended Posts

I am creating a script to create about 100 symbols, I would like to place them into various folders.

 

I have the script working except for putting into the correct folder, is there an easy way to create them in a specific folder?

 

Thanks

 

Martin

Share this post


Link to post

def  vs.InsertSymbolInFolder(targetFolder, symbolDef):

   return None

 

Should do what you want. 

 

You might also what to look at the BeginFolder/EndFolder if you are creating all the symbols that go in a single folder at once.

 

You might also need to look at BeginFolderN/EndFolder and NameObject to create the symbols folders .

 

 

Share this post


Link to post

Thanks

 

Sometimes the answer is right in front of you.

 

Insert worked great,

 

So far I have cut the amount of time to create a drawing from 4-5 hours to about 2 hours. I think I can cut it down more by creating a few more scripts.

 

I like python coding...

 

Thanks for the assistance.

Share this post


Link to post

Hi

Someone knows how to move a symbol folder inside another symbol folder? The folder would be an empty folder

Seems, that vs.GetParent(folder-2), returns folder-1. But if folder-2 is not inside folder-1 vs.SetParent(folder-2, folder-1) does not move the folder.

Also tried vs.InsertSymbolInFolder(folder-1, folder-2). 

 

Maybe to try with nested BefinFolder, but this could be tricky with existing folders and symbols.

 

 

Share this post


Link to post

Solved it for a specific situation this way. Not very elegant but it works. The Error will happen, if one of the folders exists but in this case it was not necessary.

 

sname = 'Symbol-2'
fname1 = 'Folder-1'
fname2 = 'Folder-2' 

sh = vs.GetObject(sname) #Symbol Name
fh1 = vs.GetObject(fname1) #Folder Name Parent
fh2 = vs.GetObject(fname2) #Subfolder Name

if fh1 != vs.Handle(0) or fh2 != vs.Handle(0): #Name1 or Name2 in use
    if fh1 != vs.Handle(0):
        t = vs.GetType(fh1)
        if t != 92: # Object exists but is not a Symbol Folder
            fname1 = fname1+str(uuid.uuid4())[:8]
            vs.Message(fname1+' '+str(t)+' Achtung Name des Ordners existiert schon')
            
            
    if fh2 != vs.Handle(0): #Object altready exists
        t = vs.GetType(fh2)
        if t != 92: # Object exists but is not a Symbol Folder
            fname2 = fname1+str(uuid.uuid4())[:8]
            vs.Message(fname2+' '+str(t)+' Achtung Name des Ordners existiert schon')    
        
else: #Object do not exists
    vs.NameObject(fname1)
    vs.BeginFolderN(16)
    vs.NameObject(fname2)
    vs.BeginFolderN(16)
    vs.EndFolder()
    vs.EndFolder()
    

fh1 = vs.GetObject(fname1) #New to the Objects, which are now Sym Folder for sure
fh2 = vs.GetObject(fname2)
vs.InsertSymbolInFolder(fh2, sh)


 

Share this post


Link to post

The method to do this seems to first create the wanted structure with new folders (nesting begin and end folder). Then move the existing content to the new folders and delete the old folders. After that rename the new folders to the original names. An example, how to create a nested folder structure with a depth of 2 (parent folder, subfolder). It is based on 2 input lists from the same length which build the folder path. Example Input:

fnames1 = ['Folder1','Folder1','Folder2','Folder2','Folder1']

fnames2 = ['SubFolder1','SubFolder1','SubFolder3','SubFolder2','SubFolder1']

 

The build a list of pathes:

Folder1/SubFolder1

Folder1/Subfolder1

Folder2/SubFolder3

Folder2/Subfolder2

Folder1/Subfolder1

 

The Pathes can be duplicated in the List. The Script will fail if a Subfolder with the same name hat two different parent folders.


 

fnames1 = ['Folder1','Folder1','Folder2','Folder2','Folder1']
fnames2 = ['SubFolder1','SubFolder1','SubFolder3','SubFolder2','SubFolder1']
created_folders = []

for i in range(len(fnames1)):
    fname1 = fnames1[i]
    if fname1 not in created_folders: #Folder does not exist
        vs.NameObject(fname1)
        vs.BeginFolderN(16)
        for n in range(len(fnames2)):
            fname2 = fnames2[n]
            parent = fnames1[n]
            if parent == fname1: #the parent folder of the processed subfolder matches
                if fname2 not in created_folders: 
                    vs.NameObject(fname2)
                    vs.BeginFolderN(16)
                    vs.EndFolder()
                    created_folders.append(fname2)    
    vs.EndFolder()
    created_folders.append(fname1)    

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×