Jump to content

Symbols and Folder Locations


Recommended Posts

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 .

 

 

Link to comment
  • 2 months later...

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.

 

 

Link to comment

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)


 

Link to comment

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)    

 

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