Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

did a slight change to your code.

it works perfect.

this code is being combined with a trigger ilogic to save custom thumbnails of the part ( you can rotate with spacemouse if you have one )

Open documents code.

Imports System.Threading

Sub Main()
Dim oAsmDoc As AssemblyDocument = ThisDoc.FactoryDocument
Dim oDocs As Documents = ThisApplication.Documents
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
If oRefDocs.Count = 0 Then Exit Sub

For Each oRefDoc As Document In oRefDocs
Dim oDoc As Document = oDocs.Open(oRefDoc.FullDocumentName, True)
Dim startTime As DateTime = DateTime.Now
Do While DateTime.Now.Subtract(startTime).TotalSeconds < 5
' Allow interaction with the model for 5 seconds
ThisApplication.UserInterfaceManager.DoEvents()
Loop

If oDoc.IsModifiable Then oDoc.Save()
oDoc.Close()
Next

Interaction.MsgBox("Success! All referenced documents have been opened, viewed, saved, and closed.", MsgBoxStyle.Information, "iLogic Rule")
End Sub



Code to trigger before save.

Imports System.Drawing
Imports System.Drawing.Imaging
' Rule to run only for IPT and IAM files
Sub MAIN	
    Dim m_Doc As Inventor.Document
    m_Doc = ThisDoc.Document
    
    If m_Doc.DocumentType <> kAssemblyDocumentObject _
        And m_Doc.DocumentType <> kPartDocumentObject Then 
        MessageBox.Show("File is not a model.", "iLogic")
        Return 'exit rule
    End If

    ' Get current color scheme name
    Dim oColorSchemeName As String
    oColorSchemeName = ThisApplication.ActiveColorScheme.Name

    ' Get current color scheme background type
    Dim oBackGroundType As BackgroundTypeEnum
    oBackGroundType = ThisApplication.ColorSchemes.BackgroundType

    ' Change to Deep Blue (Presentation)
    ThisApplication.ColorSchemes.Item("Presentation").Activate

    ' Set to use one color background type
    ThisApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kOneColorBackgroundType

    ' Save the active view as an image directly
    Dim m_Camera As Inventor.Camera = ThisApplication.ActiveView.Camera
    Dim m_TO As Inventor.TransientObjects = ThisApplication.TransientObjects
    Dim m_CV As Inventor.View = ThisApplication.ActiveView

    Dim m_PrevMode As Integer = m_CV.DisplayMode
    Dim m_Disp3D As Boolean = ThisApplication.DisplayOptions.Show3DIndicator

    m_CV.DisplayMode = Inventor.DisplayModeEnum.kShadedWithEdgesRendering
    ThisApplication.DisplayOptions.Show3DIndicator = False

    m_CV.Update

    ' Set the image path and name
    Dim oPath As String = "folder to save\IMAGES\"
    Dim oFileName As String = System.IO.Path.GetFileNameWithoutExtension(m_Doc.FullFileName) ' Get the file name without extension
    Dim oFile As String = oPath & oFileName & ".png"

    ' Save the image
    m_Camera.SaveAsBitmap(oFile, 800, 600, m_TO.CreateColor(255, 255, 255))

    m_CV.DisplayMode = m_PrevMode
    ThisApplication.DisplayOptions.Show3DIndicator = m_Disp3D
    m_CV.Update

    ' Change back to the original color scheme using the name
    ThisApplication.ColorSchemes.Item(oColorSchemeName).Activate

    ' Change back to the original background type
    ThisApplication.ColorSchemes.BackgroundType = oBackGroundType

End Sub