I'm setting up a scene with an assembly that will contain 300 parts or more and I'll have each part in their own config, with a camera setup that will render all parts to a similar scale with regard to each other.
I'm wondering if anyone has ever tried to automate this render--change configs--render type operation?
' snipped-for-privacy@studiozwaard.nl '
****************************************************************************** Dim swApp As SldWorks.SldWorks Dim Part As SldWorks.ModelDoc2 Dim config As Object 'SldWorks.Configuration Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim FeatureData As Object Dim Feature As Object Dim Component As Object Sub main() On Error Resume Next Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc currentfile = Part.GetTitle targetpath = "C:\temp\"
For i = 0 To Part.GetConfigurationCount - 1 configname = Part.GetConfigurationNames(i) Part.ShowConfiguration configname
result = swApp.CallBack("pworks@MiEval", 0, "RenderToFile Filename ""C:\Temp\rendering.bmp""") result = swApp.CallBack("pworks@MiEval", 0, "RenderToFile Size 1280
1024") result = swApp.CallBack("pworks@MiEval", 0, "RenderToFile Format bmp") result = swApp.CallBack("pworks@MiEval", 0, "RenderToFile Render")
Next i MsgBox "Files have been saved in " & targetpath End Sub
' snipped-for-privacy@studiozwaard.nl ' '**************************************************************************=
*=AD*** Dim swApp As SldWorks.SldWorks Dim Part As SldWorks.ModelDoc2 Dim config As Object 'SldWorks.Configuration Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim FeatureData As Object Dim Feature As Object Dim Component As Object Sub main() On Error Resume Next Set swApp =3D Application.SldWorks Set Part =3D swApp.ActiveDoc currentfile =3D Part.GetTitle targetpath =3D "C:\Documents and Settings\Schrom00\My Documents\My Pictures\"
For i =3D 0 To Part.GetConfigurationCount - 1 configname =3D Part.GetConfigurationNames(i) Part.ShowConfiguration configname
result =3D swApp.CallBack("pworks@MiEval", 0, "RenderToFile Filename ""C:\Documents and Settings\Schrom00\My Documents\My Pictures\rendering.tif""") result =3D swApp.CallBack("pworks@MiEval", 0, "RenderToFile Size 1280
1024") result =3D swApp.CallBack("pworks@MiEval", 0, "RenderToFile Format tif ") result =3D swApp.CallBack("pworks@MiEval", 0, "RenderToFile Render")
Next i MsgBox "Files have been saved in " & targetpath End Sub
There are new photoworks apis that make this a bit more intuitive and easier to understand. Here is similar code for that. Most of this code was created by recording the rendering of a file with the appropriate settings.
Dim swApp As SldWorks.SldWorks Dim Part As SldWorks.ModelDoc2 Dim config As Object 'SldWorks.Configuration Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim FeatureData As Object Dim Feature As Object Dim Component As Object Sub main() On Error Resume Next Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc currentfile = Part.GetTitle targetpath = "C:\.......\My Pictures\"
'There are new Photoworks APIs we first need to connect to Photoworks use them Dim pwPhotoWorks As PhotoWorks.PhotoWorks Set pwPhotoWorks = swApp.GetAddInObject("PhotoWorks.PhotoWorks") Dim pwOpt As PhotoWorks.PwOptions Set pwOpt = pwPhotoWorks.PwOptions swApp.ActiveDoc.ActiveView.FrameState = 1
'True overwrites existing files of the same name false doesn't bOverWrite = False
'Recurse through the configurations of the document For i = 0 To Part.GetConfigurationCount - 1 configname = Part.GetConfigurationNames(i) Part.ShowConfiguration configname
'Set all the rendering options
'set the file name to that of the configuration pwPhotoWorks.RenderFilename = TargetPath & configname & ".tif""" 'set the file format. pwPhotoWorks.RenderFileFormat = PW_RenderFileFormat.pwFileFormatTIF 'set the current units pwPhotoWorks.RenderFileUnits = PW_RenderFileUnits.pwInches 'Height in the current units which is inches pwPhotoWorks.RenderFileHeight = 1 'Width in the current units which is inches pwPhotoWorks.RenderFileWidth = 1 'DPI of render file. pwPhotoWorks.RenderFileDotsPerUnit = 1200
'Start the render process pwPhotoWorks.RenderToFile (bOverWrite)
Next i MsgBox "Files have been saved in " & targetpath End Sub
PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.