VS:Implementing Installation Script
.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix
What's that
If we follow the basic installation, each time we install a plug-in we need to edit our workspace to be able to use the plug-in functionality: Either we have to edit the menu bar or our tool set.
Fortunately Vectorworks has the ability to save any edited workspace and it can be loaded if it is put either in the Vectorworks or user workspace folder. So the best way to remove the burden of editing workspace each time a plug-in is installed, is that we can save our workspace once and put it in user workspace folder. However basic installation is unable to do that since it only copy the files to user plug-in folder. And that's where writing an installation script becomes useful:
Each time a new plug-in is installed, Vectorworks looks for a installation script (install.py) and runs it befor concluding the installation. Following is an example of such installation script written in python:
import shutil import os import vs # Set a name for a better folder organization plugin_name = "Sample1" # Use negative number to get user path and positive number to get application path VW_USER_LIBARY_PATH = vs.GetFolderPath(-13) VW_USER_WORKSPACE_PATH = vs.GetFolderPath(-4) VW_USER_PLUGINs_PATH = vs.GetFolderPath(-2) if not os.path.exists(os.path.join(VW_USER_LIBARY_PATH , plugin_name )): os.makedirs(os.path.join(VW_USER_LIBARY_PATH , plugin_name )) if not os.path.exists(os.path.join( VW_USER_WORKSPACE_PATH )): os.makedirs(os.path.join( VW_USER_WORKSPACE_PATH )) for file in os.listdir(VW_USER_PLUGINs_PATH): if file.endswith(".vww"): shutil.move(os.path.join(VW_USER_PLUGINs_PATH , file ), os.path.join(VW_USER_WORKSPACE_PATH , file )) elif file.endswith(".vwx"): shutil.move(os.path.join(VW_USER_PLUGINs_PATH , file ), os.path.join(VW_USER_LIBARY_PATH , plugin_name, file ))
This script simply looks for all workspace and drawing files (.vww and .vwx) and, if they existed, it moves them to their appropriate folder.
Now, having this script, all we have to do is just simply put this script in the root folder of our zip file package and install it from Vectorworks:
...
See also
VS:Basic Installation VS:A more Complicated Installation Script
User Comments
Peter Vandewalle 04-01-2018: On Mac the shutil seem to generate a lot of errors. Here's an alternative script (Mac & Win) without shutil commands:
import os import vs # Set a name for a better folder organization -- don't forget the / at the end of the name sPlugin = "PluginName/" sLibSubFolder = "FolderName/" def install (): # Use negative number to get user path and positive number to get application path sLibSubFolderPath = pathconvert (vs.GetFolderPath(-14) + sLibSubFolder) sTemplPath = pathconvert (vs.GetFolderPath(-7)) sWorkspacePath = pathconvert (vs.GetFolderPath(-4)) sRenoPluginPath = pathconvert (vs.GetFolderPath(-2) + sPlugin) bResult = vs.CreateFolder (sLibSubFolderPath) bResult = vs.CreateFolder (sTemplPath) bResult = vs.CreateFolder (sWorkspacePath) iCnt = 1 while True: # loop the files sFilePath = vs.GetFilesInFolder (sRenoPluginPath, iCnt) if sFilePath == '': # no more files break sFileName, sExt = os.path.splitext (sFilePath) sPath, sName = os.path.split (sFilePath) if sExt.lower () == '.vww': os.rename (sRenoPluginPath + sName, sWorkspacePath + sName) elif sExt.lower () == '.vwx': os.rename (sRenoPluginPath + sName, sLibSubFolderPath + sName) elif sExt.lower () == '.xml': os.rename (sRenoPluginPath + sName, sLibSubFolderPath + sName) elif sExt.lower () == '.sta': os.rename (sRenoPluginPath + sName, sTemplPath + sName) else: iCnt += 1 def pathconvert (lsPath): major, minor, maintenance, platform = vs.GetVersion() bMac = False if platform == 1: bMac = True if bMac: lsPath = lsPath[lsPath.index (':'):] lsPath = lsPath.replace (":", "/") pathconvert = lsPath return pathconvert install ()