Mass Convert Script

This python script will convert between two 3d formats using Vue to do the hard work. If you are using Vue 6 (Build 289182 or later) or Vue 7 you can convert to the Vue vob file format using it. It supports the import of 3dmf, 3ds, cob, dxf, lwo, obj, pz3, raw, shd, skp and vob. It can use vue to export 3ds, c4d, dxf, lwo, obj, shd and vob. Two versions are available. The most recent version has a Graphical User Interface (GUI). To use it you’ll need to have wxPython installed for Vue on your computer.

Vue 9 Important Notes: All versions of Vue from 9 include wxPython so you don’t need to install it. Installing it will break the installed wxPython and probably result in having to re-install Vue. I’ve not had time yet tested this script with Vue 9.

Before Vue 9 Important Notes: I’ve not packaged wxPython with MassConvert yet so for now you’ll need to have either SkinVue or the VueToolbar installed which both include wxPython. The other version doesn’t have a graphical user interface and doesn’t require wxPython but will require editing of the script to use to set the input and output paths for the files.

Python Code – Mass Convert (GUI)

  1. ######################################################################################################
  2. # Convert between 3d object formats using Vue
  3. #
  4. # - massconvert.py
  5. # - By Mark Caldwell
  6. # - Version 0.5.1
  7. # - 17th June 2007
  8. # - Copyright Mark Caldwell 2007
  9. # - Tested with Vue 6 Infinite on a PC
  10. #
  11. # Requires wxPython to be installed in to Vue to use.
  12. #
  13. # How to use in 2 easy steps
  14. #
  15. # 1. Download this file onto your computer
  16. #
  17. # 2. Run the script then follow the in script help for
  18. # more information
  19. #
  20. # Conversion options are those currently selected under
  21. # File -> Export As
  22. #
  23. ######################################################################################################
  24.  
  25. ######################################################################################################
  26. #
  27. # Set up by importing libraries
  28. #
  29. ######################################################################################################
  30.  
  31. import os # import os libraries
  32. import sys
  33. VuePythonPath = sys.path[1] # get the Vue python path
  34. VuePythonFolder = os.path.abspath(os.path.join(VuePythonPath[0:VuePythonPath.find("Python")],"Python"))
  35. wxPythonFolder = os.path.abspath(os.path.join(VuePythonFolder,"PythonLib/wx"))
  36. os.chdir(wxPythonFolder)
  37.  
  38. import wx # import the wx libraries
  39. import wx.html # import the wx html libraries
  40. import string # import string libraries
  41. import time # import time
  42.  
  43. # get the Vue Python Folder
  44. VuePythonFolder,junk = os.path.split(VuePythonPath)
  45.  
  46. # Get the Vue Root Path
  47. VueRootPath,junk = os.path.split(VuePythonFolder)
  48.  
  49. ######################################################################################################
  50. #
  51. # Create lists of file types that can be imported and exported
  52. #
  53. ######################################################################################################
  54.  
  55. InExtensions=['3dmf','3ds','cob','dxf','lwo','obj','pz3','raw','shd','skp','vob']
  56. OutExtensions=['3ds','c4d','dxf','lwo','obj','shd','vob']
  57.  
  58. ######################################################################################################
  59. #
  60. # Class for the Main GUI
  61. #
  62. ######################################################################################################
  63.  
  64. class MassConvertApp(wx.Frame):
  65. def __init__(self):
  66. wx.Frame.__init__(self, parent = None, id = -1,
  67. title = "MassConvert",
  68. size = (600,400),
  69. style = (wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX)))
  70.  
  71. self.SetFont(wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.NORMAL)) # Set Default Font
  72.  
  73. BoldFont=wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.BOLD) # Create Bold Font for later use
  74.  
  75. self.ClearBackground()
  76.  
  77. # Set Some variables to use later
  78.  
  79. self.inFilepath = VueRootPath
  80. self.outFilepath = VueRootPath
  81. self.out_vob=0
  82. self.InExtensionsBox=[]
  83. self.OutExtensionsBox=[]
  84.  
  85. panel = wx.Panel(self) # Create Panel
  86. panel.SetBackgroundColour('White')
  87. statusBar = self.CreateStatusBar() # Create Status Bar
  88.  
  89. # Create Menu Structure
  90.  
  91. menuBar = wx.MenuBar()
  92. menu1 = wx.Menu()
  93. in_dir=menu1.Append(wx.NewId(), "&Import...", "Directory to import files from")
  94. self.Bind(wx.EVT_MENU, self.OnIn, in_dir)
  95. out_dir=menu1.Append(wx.NewId(), "&Export...", "Directory to export files to")
  96. self.Bind(wx.EVT_MENU, self.OnOut, out_dir)
  97. menu1.AppendSeparator()
  98. exit=menu1.Append(wx.NewId(), "Exit")
  99. self.Bind(wx.EVT_MENU, self.OnExit, exit)
  100. menuBar.Append(menu1, "&File")
  101. menu2 = wx.Menu()
  102. helpmenu=menu2.Append(wx.NewId(), "&Help", "Help using MassConvert")
  103. self.Bind(wx.EVT_MENU, self.OnHelp, helpmenu)
  104. about=menu2.Append(wx.NewId(), "&About", "About MassConvert")
  105. self.Bind(wx.EVT_MENU, self.OnAbout, about)
  106. menuBar.Append(menu2, "&Help")
  107.  
  108. self.SetMenuBar(menuBar)
  109.  
  110. CheckBoxSize=(90, 20)
  111. InColumnX=35
  112. OutColumnX=180
  113. inc=20
  114. StartY=60
  115.  
  116. # Create File Path Text Display
  117.  
  118. text=wx.StaticText(panel,-1,"Import File Path:",(10,10))
  119. text.SetFont(BoldFont)
  120. self.InFilePathText=wx.StaticText(panel,-1,self.inFilepath,(120,10))
  121. text=wx.StaticText(panel,-1,"Export File Path:",(10,10+inc))
  122. text.SetFont(BoldFont)
  123. self.OutFilePathText=wx.StaticText(panel,-1,self.outFilepath,(120,10+inc))
  124.  
  125. # Create File Import / Export Count Display
  126.  
  127. self.NumberOfFilesImportedLabel=wx.StaticText(panel,-1,'',(300,60))
  128. self.NumberOfFilesImportedLabel.SetFont(BoldFont)
  129. self.NumberOfFilesImported=wx.StaticText(panel,-1,'',(470,60))
  130. self.NumberOfFilesExportedLabel=wx.StaticText(panel,-1,'',(300,80))
  131. self.NumberOfFilesExportedLabel.SetFont(BoldFont)
  132. self.NumberOfFilesExported=wx.StaticText(panel,-1,'',(470,80))
  133. self.ConvertTimeLabel=wx.StaticText(panel,-1,'',(300,100))
  134. self.ConvertTimeLabel.SetFont(BoldFont)
  135. self.ConvertTime=wx.StaticText(panel,-1,'',(470,100))
  136.  
  137. # Create Check Boxes for Import Types
  138.  
  139. y=StartY
  140.  
  141. text=wx.StaticText(panel,-1,'Input File Types: ',(10,y))
  142. text.SetFont(BoldFont)
  143.  
  144. y=y+inc
  145. x=InColumnX
  146.  
  147. for Extension in InExtensions:
  148. Box=wx.CheckBox(panel, -1, Extension, (x, y), CheckBoxSize)
  149. self.InExtensionsBox.append((Extension,Box))
  150. y=y+inc
  151.  
  152. yBottom=y+inc+inc
  153.  
  154. # Create Check Boxes for Output Type
  155.  
  156. y=StartY
  157. x=OutColumnX
  158.  
  159. text=wx.StaticText(panel,-1,'Output File Types: ',(155,y))
  160. text.SetFont(BoldFont)
  161.  
  162. y=y+inc
  163.  
  164. for Extension in OutExtensions:
  165. Box=wx.CheckBox(panel, -1, Extension, (x, y), CheckBoxSize)
  166. self.OutExtensionsBox.append((Extension,Box))
  167. y=y+inc
  168.  
  169. y=y+inc+inc
  170.  
  171. # Create Convert Button
  172.  
  173. self.button = wx.Button(panel, -1, 'Convert', pos=(OutColumnX, y))
  174. self.Bind(wx.EVT_BUTTON, self.OnClickConvert, self.button)
  175. self.button.SetDefault()
  176.  
  177. self.CenterOnParent() # Center the GUI on the Vue Window
  178. self.ClearBackground()
  179. self.Show(True) # Show the GUI
  180.  
  181. ######################################################################################################
  182. #
  183. # When the convert button is clicked
  184. #
  185. ######################################################################################################
  186.  
  187. def OnClickConvert(self, event):
  188. OutExtensionList=[]
  189. InExtensionList=[]
  190. objImportCount=0
  191. objExportCount=0
  192. startTime=time.time()
  193.  
  194. for Extension,Check in self.InExtensionsBox:
  195. if Check.IsChecked():
  196. InExtensionList.append(Extension)
  197.  
  198. for Extension,Check in self.OutExtensionsBox:
  199. if Check.IsChecked():
  200. OutExtensionList.append(Extension)
  201.  
  202. filenames=os.listdir(self.inFilepath)
  203.  
  204. for filename in filenames:
  205. for extensionin in InExtensionList:
  206. if '.'+extensionin in filename:
  207. fullPath=self.inFilepath+'/'+filename
  208. obj=ImportObject(fullPath)
  209. if obj:
  210. objImportCount=objImportCount+1
  211. for extensionout in OutExtensionList:
  212. newFileName=self.outFilepath+'/'+filename.replace('.'+extensionin,'.'+extensionout)
  213. if os.path.exists(newFileName)!=True:
  214. SelectOnly(obj)
  215. ExportObject (newFileName)
  216. objExportCount=objExportCount+1
  217. SelectOnly(obj)
  218. Delete()
  219. endTime=time.time()
  220.  
  221. elapsedTime=endTime-startTime
  222.  
  223. self.NumberOfFilesImportedLabel.SetLabel('Number of Files Imported:')
  224. self.NumberOfFilesExportedLabel.SetLabel('Number of Files Exported:')
  225. self.ConvertTimeLabel.SetLabel('Time:')
  226. self.NumberOfFilesImported.SetLabel(str(objImportCount))
  227. self.NumberOfFilesExported.SetLabel(str(objExportCount))
  228. self.ConvertTime.SetLabel(str(int(elapsedTime))+' seconds')
  229.  
  230. self.Raise()
  231.  
  232. ######################################################################################################
  233. #
  234. # When exit and close are clicked
  235. #
  236. ######################################################################################################
  237.  
  238. def OnExit(self, event):
  239. self.Close()
  240.  
  241. def OnCloseMe(self, event):
  242. self.Close(True)
  243.  
  244. def OnCloseWindow(self, event):
  245. self.Destroy()
  246.  
  247. ######################################################################################################
  248. #
  249. # Read the Input Directory
  250. #
  251. ######################################################################################################
  252.  
  253. def OnIn(self, event):
  254. dialog = wx.DirDialog(None, "Choose a directory to import from:",self.inFilepath,
  255. style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
  256. if dialog.ShowModal() == wx.ID_OK:
  257. self.inFilepath = dialog.GetPath()
  258. self.InFilePathText.SetLabel(self.inFilepath)
  259. dialog.Destroy()
  260.  
  261. ######################################################################################################
  262. #
  263. # Read the Export Directory
  264. #
  265. ######################################################################################################
  266.  
  267. def OnOut(self, event):
  268. dialog = wx.DirDialog(None, "Choose a directory to export to:",self.outFilepath,
  269. style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
  270. if dialog.ShowModal() == wx.ID_OK:
  271. self.outFilepath=dialog.GetPath()
  272. self.OutFilePathText.SetLabel(self.outFilepath)
  273. dialog.Destroy()
  274.  
  275. ######################################################################################################
  276. #
  277. # When About is clicked
  278. #
  279. ######################################################################################################
  280.  
  281. def OnAbout(self, event):
  282. dialog = MassConvertAbout(self)
  283. dialog.ShowModal()
  284. dialog.Destroy()
  285.  
  286. ######################################################################################################
  287. #
  288. # When Help is clicked
  289. #
  290. ######################################################################################################
  291.  
  292. def OnHelp(self, event):
  293. dialog = MassConvertHelp(self)
  294. dialog.ShowModal()
  295. dialog.Destroy()
  296.  
  297. ######################################################################################################
  298. #
  299. # About Window
  300. #
  301. ######################################################################################################
  302.  
  303. class MassConvertAbout(wx.Dialog):
  304. text = '''
  305. <html>
  306. <body bgcolor="#ffffff">
  307. <center><table bgcolor="#ffffff" width="100%" cellspacing="0"
  308. cellpadding="0" border="1">
  309. <tr>
  310. <td align="center"><h1>MassConvert</h1></td>
  311. </tr>
  312. </table>
  313. </center>
  314. <p align="center">Version 0.5.0</p>
  315. <p align="center">http://www.impworks.co.uk/</p>
  316. <p align="center">Copyright Mark Caldwell 2007</p>
  317. <p align="center">Tested with Vue 6 Infinite on a PC</p>
  318.  
  319. </body>
  320. </html>
  321. '''
  322.  
  323. def __init__(self, parent):
  324. wx.Dialog.__init__(self, parent, -1, 'About MassConvert',
  325. size=(440, 300) )
  326.  
  327. html = wx.html.HtmlWindow(self)
  328. html.SetPage(self.text)
  329. button = wx.Button(self, wx.ID_OK, "Okay")
  330.  
  331. sizer = wx.BoxSizer(wx.VERTICAL)
  332. sizer.Add(html, 1, wx.EXPAND|wx.ALL, 5)
  333. sizer.Add(button, 0, wx.ALIGN_CENTER|wx.ALL, 5)
  334.  
  335. self.SetSizer(sizer)
  336. self.Layout()
  337.  
  338. ######################################################################################################
  339. #
  340. # Help Window
  341. #
  342. ######################################################################################################
  343.  
  344. class MassConvertHelp(wx.Dialog):
  345. text = '''
  346. <html>
  347. <body bgcolor="#ffffff">
  348. <center><table bgcolor="#ffffff" width="100%" cellspacing="0"
  349. cellpadding="0" border="1">
  350. <tr>
  351. <td align="center"><h1>MassConvert Help</h1></td>
  352. </tr>
  353. </table>
  354. </center>
  355. <p>This Vue python script reads 3d object files from a selected import directory and saves them in new formats to
  356. a selected export directory. If it finds a file of the same name as one it is trying to create already exists in the
  357. export directory it doesn't export the file.</p>
  358.  
  359. <p>Select the directory to import files from in the <em>File</em> menu with <em>Import...</em>.</p>
  360. <p>Select the directory to export files from in the <em>File</em> menu with <em>Export...</em>.</p>
  361. <p>Select the types of file to import and the types of file to export with the check boxes.</p>
  362. <p>Once you've made your selections click the <em>Convert</em> button and Vue will import the selected files
  363. and export them in the selected formats.</p>
  364. <p>The export will use the settings from the last export you did with Vue.</p>
  365. <p>When converting some file formats (such as poser) Vue will ask you to make choices during the import.</p>
  366. </body>
  367. </html>
  368. '''
  369.  
  370. def __init__(self, parent):
  371. wx.Dialog.__init__(self, parent, -1, 'MassConvert Help',
  372. size=(440, 550) )
  373.  
  374. html = wx.html.HtmlWindow(self)
  375. html.SetPage(self.text)
  376. button = wx.Button(self, wx.ID_OK, "Close")
  377.  
  378. sizer = wx.BoxSizer(wx.VERTICAL)
  379. sizer.Add(html, 1, wx.EXPAND|wx.ALL, 5)
  380. sizer.Add(button, 0, wx.ALIGN_CENTER|wx.ALL, 5)
  381.  
  382. self.SetSizer(sizer)
  383. self.Layout()
  384.  
  385. ######################################################################################################
  386. #
  387. # Start of Program
  388. #
  389. ######################################################################################################
  390.  
  391. app = None # Clear out any previous instances of app
  392. del app # destroy it completely
  393. app = wx.PySimpleApp() # Create a new wx application instance
  394. frame = MassConvertApp() # Create the GUI instance
  395. app.MainLoop() # Execute wx
  396.  
  397. Refresh()

Python Code – Mass Convert (No GUI)

  1. #******************************************************
  2. # Convert between two formats using Vue
  3. #
  4. # - massconvert.py
  5. # - By Mark Caldwell
  6. # - Version 0.5.1 (No GUI)
  7. # - 6th August 2007
  8. # - Copyright Mark Caldwell 2007
  9. # - Tested with Vue 6 Infinite Pre Release
  10. #
  11. # How to use in 4 easy steps
  12. #
  13. # 1. Download this file onto your computer
  14. #
  15. # 2. Place the files to be converted in the same directory
  16. # as the script
  17. #
  18. # 3. Edit the script to change output_directory. This is
  19. # the directory the files will be put in and is relative
  20. # to the root directory of your vue installation.
  21. # eg if Vue python is in to:
  22. # C:\Program Files\e-on software\Vue 6 Infinite\Python
  23. # and you want to save the files to:
  24. # C:\Program Files\e-on software\Vue 6 Infinite\Python\Scripts\outfiles
  25. # Change output directory to:
  26. # output_directory='\Scripts\outfiles'
  27. #
  28. # Make sure the directory you want to save to exists.
  29. # If it doesn't the files will not be saved.
  30. #
  31. # 4. Then run script and wait for it to work supplying
  32. # responses when prompted.
  33. #
  34. # To run it go to Python -> Run Python Script
  35. # Then locate the file on your computer
  36. #
  37. # Do not run using quick load options
  38. #
  39. # Available input formats are:
  40. # 3dmf
  41. # 3ds
  42. # cob
  43. # dxf
  44. # lwo
  45. # obj
  46. # pz3
  47. # raw
  48. # shd
  49. # skp
  50. # vob
  51. #
  52. # Available output formats are:
  53. # 3ds
  54. # c4d
  55. # dxf
  56. # lwo
  57. # obj
  58. # shd
  59. # vob
  60. #
  61. # Conversion options are those currently selected under
  62. # File -> Export As
  63. #
  64. #******************************************************
  65.  
  66. #----------------------------------------------
  67. # Configuration: Set these to alter end result
  68. #----------------------------------------------
  69.  
  70. # Change the line below to change where files are saved
  71. # see instructions above for more details
  72.  
  73. output_directory='/scripts/massconvert'
  74.  
  75. #----------------------------------------------
  76. # Internal Variables Set Up: Don't alter these
  77. #----------------------------------------------
  78.  
  79. import os
  80. import string
  81.  
  82. # get the Vue python path
  83. VuePythonPath = sys.path[1]
  84.  
  85. # get the Vue Python Folder
  86. VuePythonFolder,junk = os.path.split(VuePythonPath)
  87.  
  88. # Get the Vue Root Path
  89. VueRootPath,junk = os.path.split(VuePythonFolder)
  90.  
  91. # Set where to put the output files
  92.  
  93. output_path=VuePythonFolder+output_directory
  94.  
  95. obj=[]
  96. objectlist=[]
  97. extensionin='obj'
  98. extensionout='3ds'
  99.  
  100. #---------------------------------------------------
  101. # Get User Input
  102. #---------------------------------------------------
  103.  
  104. extensionin=Prompt('File extension of files to import\nobj 3ds lwo c4d cob dxf pz3 shd vob',extensionin,true,'Input File Extension')
  105. extensionout=Prompt('File extension on files to output\nobj 3ds lwo c4d cob dxf shd vob',extensionout,true,'Output File Extension')
  106.  
  107. #---------------------------------------------------
  108. # Main Script Body
  109. #---------------------------------------------------
  110.  
  111. # Load objects
  112.  
  113. filenames=os.listdir(os.curdir)
  114.  
  115. for filename in filenames:
  116. if '.'+extensionin in filename:
  117. obj=ImportObject(filename)
  118. newfilename=output_path+'/'+filename.replace('.'+extensionin,'.'+extensionout)
  119. print filename+" to "+newfilename
  120. SelectOnly(obj)
  121. print ExportObject (newfilename)
  122. Delete()
  123.  
  124. Refresh()

impworks © Copyright Mark Caldwell 1996 - 2017