Python Sample Import Images as Symbols: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{LocationMain|category=LocationPYSpecial|specific=}} <div class="rightmenu"> __TOC__ </div> == How to install == Create a new Vectorworks document and add a new Script resour...") |
No edit summary |
||
Line 35: | Line 35: | ||
name, ext = os.path.splitext( fileName ) | name, ext = os.path.splitext( fileName ) | ||
if ext.lower() == '.png': | if ext.lower() == '.png' or ext.lower() == '.jpg': | ||
imagePath = os.path.join( dirPath, fileName ) | imagePath = os.path.join( dirPath, fileName ) | ||
Latest revision as of 16:14, 19 June 2014
.Python|Python ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix ..Python Debugging|Debugging with Python
How to install
Create a new Vectorworks document and add a new Script resource in the resource browser. Use the text below for the script and make sure you select Python language.
How the sample works
import os major, minor, maintenance, platform = vs.GetVersion() isMac = False if platform == 1: isMac = True # define a location to import the images importPt = (0,0) symCreatedCnt = 0 err, dirPath = vs.GetFolder( 'Select a Folder' ) if err == 0: # no-error hsfDirPath = dirPath if isMac: ok, hsfDirPath = vs.ConvertPosix2HSFPath( dirPath ) fileIndex = 1 while True: # loop the files fileName = vs.GetFilesInFolder( hsfDirPath, fileIndex ) fileIndex += 1 if fileName == '': # no more files break name, ext = os.path.splitext( fileName ) if ext.lower() == '.png' or ext.lower() == '.jpg': imagePath = os.path.join( dirPath, fileName ) vs.BeginSym( name ) hImage = vs.ImportImageFile( imagePath, importPt ) vs.EndSym() symCreatedCnt += 1 vs.AlrtDialog( 'Done! Created ', symCreatedCnt , ' symbols.' )
See Also
Python basic information: Python