Jump to content

Import Symbol from Workgroup Libraries


Recommended Posts

Hi All,

 

I'm looking to import some symbols from our Workgroup Library into a drawing using a script. As the script will become available to everyone in our organization, i'd like to use a relative path, instead of absolute paths. 

 

I'm looking for something like this. However, copySymbol requires the path relative to the application folder, thus making it impossible to use this function (as far as I know). 

vs.CopySymbol('Workgroup/Libraries/Defaults/Festoon Strings.vwx', symbol_to_import)

 

Does anybody know how to import a symbol from the workgroup library?

 

Link to comment

You have a few options, depending on what the workgroup folder is relative to.

 

Note, some of the docs are out of date: the commands should all now take POSIX paths, not the old Mac notation.

 

You can get relative paths via the ../ syntax, which could let you find the path anywhere on your system. It's been a while since I've used CopySymbol, so you may want to confirm that the path is still relative to the application folder and not the user folder.

 

If you're on a Mac, you should be able to use ~/ as an absolute path from the user's home folder.

 

You can also use GetFolderPath() and then use the various python path utilities to parse and build an absolute path to the workgroup folder.

 

Finally, you can look at the BuildResourceList commands. Those should allow you to access resources in the Workgroup folder if they are filed correctly. If the workgroup folder is relative to your user folders, you can also possibly construct a relative path to pass as a subfolder.

Link to comment
  • 2 weeks later...

I've tried using BuildResourceListN as well as straight up calling CopySymbol with the following path which points to the workgroup folder: 

 

~/Google Drive/Shared drives/VWX/Defaults/Festoon Strings/Festoon Strings.vwx

I have not been able to find any resources using BuildResourceList, and no luck with CopySymbol either.
I have also tried GetFolderPath as suggested, but I couldnt get this to work unfortunately, perhaps because of the location of the workgroup folder?


Does anybody have a clue to what I could do?

Link to comment
  • 2 months later...

It should work with something like this:
(Not tested but should work)
 

import os

res_file = "Path/to/your/file.vwx"
if os.path.isfile(res_file) == False:
	vs.AlrtDialog('Path error')
	
else:    
	listID, symDefNum = vs.BuildResourceListN( 16, res_file )
	for index in range(1, symDefNum+1):
		vs.ImportResourceToCurrentFile(listID, index)
    


 

To grab several res files in a folder and his sub-folders:

 

import unicodedata
import os
def get_res_files(folder):
	file_list = []
	for path, subdirs, files in os.walk(folder):
		path = unicodedata.normalize('NFC', path) ## Valid values for form are ‘NFC’, ‘NFKC’, ‘NFD’, and ‘NFKD’.
		for name in files:
			filename, file_extension = os.path.splitext(name)
			if file_extension == '.vwx':
				fullpath = os.path.join(path, name)
				fullpath_string = unicodedata.normalize('NFC', fullpath)
				file_list.append(fullpath_string)
                
	return file_list             


	


Then you could loop through several res files:
 

res_file_list = get_res_files('Folder/to/Libraries')  
for res_file in res_file_list:
    listID, symDefNum = vs.BuildResourceListN( 16, res_file )
    for index in range(1, symDefNum+1):
        vs.ImportResourceToCurrentFile(listID, index)


 
If you have issues with the path, maybe try:
 

from pathlib import Path
home = str(Path.home())   

filepath = home+'/google/yourpath/yourfile.vwx'

#to be cross-platform always use something like this:
filepath = os.path.join(folder,folder,folder,file)

 

Edited by DomC
Link to comment

Just read the initial post. "Workgroup folder"
OK, now it is getting interesting. It depends on platform you work and workgroup folder is stored in the system I think (plist or registry). 

But I would not use this it is digging deep and it may not work anymore with newer versions etc. maybe hard to get it to work again. Also I did not checked if this is still working. 
 

#Windows

import getpass
import shutil

HSFPath = vs.GetFPathName()
vs.AlrtDialog(HSFPath)
#Application	1
#User App Data	12
target = 'Users/dominiquecorpataux/Desktop'

from winreg import *
aReg = ConnectRegistry(None,HKEY_CURRENT_USER)
aKey = OpenKey(aReg, r"Software\Nemetschek\Vectorworks 24\General")
WGF_Path = QueryValueEx(aKey, "Workgroup Folder 0")
#vs.Message(WGF_Path[0]) 
target = WGF_Path[0]

vs.AlrtDialog(str(target))


#on mac

import plistlib
#MacFile = 'Users/dominiquecorpataux/Library/Preferences/net.nemetschek.vectorworks.2019.plist'
pl = {}
with open(file, 'rb') as fp:
    pl = plistlib.load(fp)
    
vs.AlrtDialog(str(pl.get("NNA Workgroup Folders")))
vs.AlrtDialog(pl["NNA Workgroup Folders"])

 

Edited by DomC
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...