sandertb Posted December 20, 2021 Share Posted December 20, 2021 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? Quote Link to comment
Jayme McColgan Posted December 20, 2021 Share Posted December 20, 2021 Hmmm that's in intresting one. I have a workflow for importing symbols bit I haven't done it though workgroups. I've never actually used workgroups. Let me do some testing today and I'll get back to you. 1 Quote Link to comment
JBenghiat Posted December 21, 2021 Share Posted December 21, 2021 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. Quote Link to comment
sandertb Posted January 4, 2022 Author Share Posted January 4, 2022 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? Quote Link to comment
DomC Posted March 10, 2022 Share Posted March 10, 2022 (edited) 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 March 10, 2022 by DomC Quote Link to comment
DomC Posted March 10, 2022 Share Posted March 10, 2022 (edited) 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 March 10, 2022 by DomC 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.