3 Replies Latest reply on Mar 8, 2017 2:41 AM by Andreas Wegmueller

    Automatic rendering all Configuration to file

    Aviev Akhmad

      Hi,

       

      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

        • Re: Automatic rendering all Configuration to file
          Keith Rice

          I have never had to create a pause when rendering configurations, so I am not exactly certain what the problem is. However instead of using a message box you can sleep the thread like this:

           

          #If VBA7 Then
          Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
          #Else
          Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
          #End If
          
          Sub Sleep()
              Sleep 1000 'Implements a 1 second delay
          End Sub
          

           

          This code only works in VBA. If you're in .NET, then you need to use System.Threading.Thread.Sleep().

           

          Keith

          SolidWorks API Tutorials

          • Re: Automatic rendering all Configuration to file
            Mikle Kov

            Not a very elegant solution, but eventually worked.

            Move the starting and closing PhotoView 360 app in cycle.

             

            ....

            For i = 0 To UBound(vConfNameArr)

            ....

            Set swRayTraceRenderer = swApp.GetRayTraceRenderer(swPhotoView) ' Access PhotoView 360

            Set swRayTraceRenderOptions = swRayTraceRenderer.RayTraceRendererOptions ' Get and set rendering options

            '******** RENDER

            rendering = swRayTraceRenderer.RenderToFile(Ioutfile & ".png", 0, 0)

            '******** Close render

            rendering = swRayTraceRenderer.CloseRayTraceRender

            ....

            Next i

            ....

             

            =========

            By the way, if the configuration name has a point.

            Do you have problems with the correct name in your case.

            For example the configuration name: 2GN12.5K

             

            You use: rendering = swRayTraceRenderer.RenderToFile(Ioutfile, 0, 0)

            You'll get: 2GN12.png

             

            I use:  rendering = swRayTraceRenderer.RenderToFile(Ioutfile & ".png", 0, 0)

            I get: 2GN12.5K.png

            • Re: Automatic rendering all Configuration to file
              Andreas Wegmueller

              I had the same problem, but with this timed msgbox it works.

              The first part

              #If Win64 Then '64?
                Private Declare PtrSafe Function MsgBoxTimeout _
                Lib "user32" _
                Alias "MessageBoxTimeoutA" ( _
                ByVal hwnd As LongPtr, _
                ByVal lpText As String, _
                ByVal lpCaption As String, _
                ByVal wType As VbMsgBoxStyle, _
                ByVal wlange As Long, _
                ByVal dwTimeout As Long) _
                As Long
              #Else
                Private Declare Function MsgBoxTimeout _
                Lib "user32" _
                Alias "MessageBoxTimeoutA" ( _
                ByVal hwnd As Long, _
                ByVal lpText As String, _
                ByVal lpCaption As String, _
                ByVal wType As VbMsgBoxStyle, _
                ByVal wlange As Long, _
                ByVal dwTimeout As Long) _
                As Long
              #End If
              

              The second part

              Sub btnMsgbox()
                Call MsgBoxTimeout(0, "This message box will be closed after 1 seconds ", "SolidWorks BatchRenderer", vbInformation, 0, 1000)
              End Sub