0 Replies Latest reply on Aug 21, 2013 4:04 PM by Dan D

    save photoview 360 alpha channel

    Dan D

      Hi,

      I know how to render my images progrematically.

      What i want is to be able to saev the renderd alpha channel as well.

      How can i do that?

       

      The simple routine i use fro saving the rendered views is below and the outout file (jpeg) is created with:

      lOutFile = TASK_WORKING_DIR & "render_" & $$$FILE_NAME$$$ & FILE_SUF & lCameraId

       

      The $$$VAR$$$ is for the solidworks task scheduler input fields - it can be replace by any string.

       

       

      Dim swApp As Object
      '------------------------------------------
      '
      ' Preconditions: SolidWorks model is open and contains at least one camera.
      '
      ' Postconditions: The cameras are turned on and off.
      '
      '------------------------------------------
      
      Option Explicit
      
      '
      ' Utility struct to combine the name and ID of a camera
      '
      Type Camera_t
          Name As String
          Id   As Long
      End Type
      
      'Dim swApp As SldWorks.SldWorks
      
      ' TASK_WORKING_DIR 
      ' IS_PART -> (Y/y) => SLDPRT otherwise SLDASM
      ' FILE_PATH
      ' FILE_NAME.
      
      Sub main()
          Dim swModel                 As SldWorks.ModelDoc2
          Dim swModelView             As SldWorks.ModelView
          Dim swCamera                As SldWorks.Camera
          Dim lNumCameras             As Long
          Dim lCameraId               As Long
          Dim swFeature               As SldWorks.Feature
          Dim aCameras()              As Camera_t
          Dim bValue                  As Boolean
          Dim sFeatureName            As String
          Dim lTypeOfCamera           As Long
          Dim lTypeOfCameraPosition   As Long
          
          Dim longstatus As Long
          Dim dummyRet As Long
          
          Dim fullPath As String
          Dim docType As Integer
          Dim TASK_WORKING_DIR As String
          Dim FILE_TYPE As String
          Dim FILE_SUF As String
      
          'Dim FILE_NAME As String
          'Dim IS_PART As String
          'FILE_PATH = "c:\Users\Chupi\Documents\Solid\Other\Bottle\Wine bottle\" 
          'FILE_NAME = "flatScreen"
          'IS_PART = "n"
      
          TASK_WORKING_DIR = "c:\Users\Chupi\Pictures\Solid\" 
          If ($$$FILE_SUFFIX$$$ <> "") Then
             FILE_SUF = "_" + $$$FILE_SUFFIX$$$
          Else
             FILE_SUF = ""
          End If
      
          If ($$$IS_PART$$$ = "Y" Or $$$IS_PART$$$ = "y") Then
             FILE_TYPE = "SLDPRT"
             docType = 1
          Else
             FILE_TYPE = "SLDASM"
             docType = 2
          End If
          
          fullPath = $$$FILE_PATH$$$ + $$$FILE_NAME$$$ + "." + FILE_TYPE
          
          Set swApp = Application.SldWorks            ' Connect to SolidWorks
          Set swModel = swApp.OpenDoc6(fullPath, docType, 1, "", dummyRet, longstatus)
          'Set swModel = swApp.ActiveDoc               ' Get active document
          Set swModelView = swModel.ActiveView        ' Get the active model view for the active document
          
          ' Get current directory (destination of render)
      
          ' Check if a camera view is active
          Set swCamera = swModelView.Camera
          Debug.Print
          If (swCamera Is Nothing) Then
              Debug.Print "No active camera."
          Else
              Debug.Print "Camera is active."
              Debug.Print "  Name = " & swCamera.Id
          End If
          
          
          swModelView.Camera = Nothing                ' Turn off camera view
         
          Dim lOutFile As String
          Dim status As Boolean
          Dim swRayTraceRenderer, swRayTraceRenderOptions As Object
          Set swRayTraceRenderer = swApp.GetRayTraceRenderer(swPhotoView)             ' Access PhotoView 360
          Set swRayTraceRenderOptions = swRayTraceRenderer.RayTraceRendererOptions    ' Get and set rendering options
          
          ' Get the number of cameras
          lNumCameras = swModel.Extension.GetCameraCount
          Debug.Print
          Debug.Print "Number of cameras = " & lNumCameras
          
          ReDim aCameras(lNumCameras - 1)
          
          For lCameraId = 0 To (lNumCameras - 1)
      
              ' Valid ID:
              '
              '  0 <= ID <= (ModelDocExtension::GetCameraCount - 1)
              '
              ' IDs are reassigned if a camera is deleted
              aCameras(lCameraId).Id = lCameraId
                
              Set swCamera = swModel.Extension.GetCameraById(lCameraId)   ' Get the camera
              Set swFeature = swCamera
              
              sFeatureName = swFeature.Name                           ' Get the names of the feature and camera
              aCameras(lCameraId).Name = sFeatureName
              
              lTypeOfCamera = swCamera.Type                           ' Get the type of camera
              lTypeOfCameraPosition = swCamera.PositionType           ' Get the type of camera position
          Next lCameraId
          
          ' Now switch the view to each camera
          For lCameraId = 0 To (lNumCameras - 1)
              bValue = swModelView.SetCameraByName(aCameras(lCameraId).Name)
              If (bValue = False) Then
                  Debug.Print "Failed to set model view to use camera " & aCameras(lCameraId).Name
              Else
                  Debug.Print "Model view set to use camera " & aCameras(lCameraId).Name
                  'status = swRayTraceRenderer.InvokeFinalRender                               ' Invoke final render window
                  'status = swRayTraceRenderer.AbortFinalRender                                ' Abort final render window
                  lOutFile = TASK_WORKING_DIR & "render_" & $$$FILE_NAME$$$ & FILE_SUF & lCameraId
      '            lOutFile = "render_" & lCameraId    'don't know where this is written
      
                  status = swRayTraceRenderer.RenderToFile(lOutFile, 0, 0)      ' Render
              End If
              swModelView.Camera = Nothing
          Next lCameraId
              
          'MsgBox "Done"
      End Sub
      'Set swApp = Application.SldWorks
      'End Sub