AnsweredAssumed Answered

Automatic rendering all Configuration to file

Question asked by Aviev Akhmad on Apr 3, 2015
Latest reply on Mar 8, 2017 by Andreas Wegmueller



I  use sldwork api to render multiple defined configuration.

The macro is working pretty well when i put msgbox between configuration rendering, as I have 320 configurations I would not put this msgbox.

unfortunately when I remove the msgbox the script didnt work..

anyone know what would be the problem?

do you think timed msgbox will solve the problm? (so far I could not find any working timed msgbox in solidworks API)

or is there any function in solidworks API that able to wait render process before execute next script?

and here is the script


Sub RenderAllConfig()

    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    Dim swModelView As SldWorks.ModelView

    Dim vConfNameArr As Variant

    Dim sConfigName As String

    Dim start As Single

    Dim i As Long

    Dim bShowConfig As Boolean

    Dim brefresh As Boolean

    Dim bRebuild As Boolean

    Dim rendering As Boolean

    Dim bRet As Boolean

    Dim Ioutfile As String

    Dim swRayTraceRenderer As SldWorks.RayTraceRenderer

    Dim swRayTraceRenderOptions As SldWorks.RayTraceRendererOptions


    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swModelView = swModel.ActiveView


    ' Access PhotoView 360

    Set swRayTraceRenderer = swApp.GetRayTraceRenderer(swPhotoView)

    ' Get and set rendering options

    Set swRayTraceRenderOptions = swRayTraceRenderer.RayTraceRendererOptions

    ' Display render window

    'rendering = swRayTraceRenderer.InvokeFinalRender

    'Debug.Print "File = " + swModel.GetPathName


    vConfNameArr = swModel.GetConfigurationNames

    For i = 0 To UBound(vConfNameArr)

        sConfigName = vConfNameArr(i)

        bShowConfig = swModel.ShowConfiguration2(sConfigName)


        'bRebuild = swModel.ForceRebuild3(False)

        'brefresh = swModelView.EnableGraphicsUpdate

        MsgBox ("Rendering :" & sConfigName)

        start = Timer

        Ioutfile = "d:\render output\" & sConfigName

        rendering = swRayTraceRenderer.RenderToFile(Ioutfile, 0, 0)

        Debug.Print "  Configuration    = " & sConfigName

        Debug.Print "  File name        = " & Ioutfile

        Debug.Print "  Rendering        = " & rendering

        Debug.Print "  Time             = " & Timer - start & " seconds"

     Next i

    ' Close render

    rendering = swRayTraceRenderer.CloseRayTraceRender



End Sub