Option Explicit On Sub Main If Not TypeOf ThisDoc.Document Is AssemblyDocument Then MsgBox("Not an Assy!", vbCritical) : RETURN Dim sw As New StopWatch invApp = ThisApplication aDoc = ThisDoc.Document Dim aDef As AssemblyComponentDefinition = aDoc.ComponentDefinition ' Logger.Info(".AllLeafOccurrences: " & aDef.Occurrences.AllLeafOccurrences.Count) Dim prBar = invApp.CreateProgressBar(False, aDef.Occurrences.AllLeafOccurrences.Count, "Exporting components to IGES..") Dim aDocPath As String = ThisDoc.Document.FullFileName igesDirPath = aDocPath & "---to-IGES" If System.IO.Directory.Exists(igesDirPath) Then System.IO.Directory.Delete(igesDirPath, recursive := True) System.IO.Directory.CreateDirectory(igesDirPath) Dim occDef As ComponentDefinition Dim ptDoc As PartDocument Dim name As String Dim withAssyFeatures As MsgBoxResult = MsgBox("Export with assembly features?", vbQuestion + vbYesNo) If withAssyFeatures = vbNo Then sw.Start For Each occ As ComponentOccurrence In aDef.Occurrences.AllLeafOccurrences prBar.UpdateProgress occDef = occ.Definition ptDoc = occDef.Document name = System.IO.Path.GetFileNameWithoutExtension(ptDoc.FullFileName) ExportToIges(ptDoc, name) Next Else Dim toggleVisibilityOfOneComponent As MsgBoxResult = MsgBox("Switch visibility of just one component (don't use Isolate Command)?", vbQuestion + vbYesNo) sw.Start If toggleVisibilityOfOneComponent = vbNo Then Dim sSet As SelectSet = aDoc.SelectSet Dim cmdMgr As CommandManager = invApp.CommandManager invApp.ScreenUpdating = False For Each occ As ComponentOccurrence In aDef.Occurrences.AllLeafOccurrences prBar.UpdateProgress occDef = occ.Definition ptDoc = occDef.Document name = System.IO.Path.GetFileNameWithoutExtension(ptDoc.FullFileName) sSet.Clear sSet.Select(occ) cmdMgr.ControlDefinitions("AssemblyIsolateCmd").Execute ExportToIges(aDoc, name) cmdMgr.ControlDefinitions("AssemblyIsolateUndoCmd").Execute Next invApp.ScreenUpdating = True Else aDef.RepresentationsManager.DesignViewRepresentations(1).Activate For Each occ As ComponentOccurrence In aDef.Occurrences occ.Visible = False Next For Each occ As ComponentOccurrence In aDef.Occurrences.AllLeafOccurrences prBar.UpdateProgress occDef = occ.Definition ptDoc = occDef.Document name = System.IO.Path.GetFileNameWithoutExtension(ptDoc.FullFileName) occ.Visible = True ExportToIges(aDoc, name) occ.Visible = False Next For Each occ As ComponentOccurrence In aDef.Occurrences occ.Visible = True Next End If End If prBar.Close Dim igesQty As Integer = System.IO.Directory.GetFiles(igesDirPath).Count MsgBox(String.Format("{0} IGES files created within {1} seconds", igesQty, Round(sw.Elapsed.TotalSeconds, 1)), vbInformation) Process.Start(New ProcessStartInfo(igesDirPath) With {.UseShellExecute = True}) End Sub Sub ExportToIGES(modelDoc As Document , fileName As String) If System.IO.File.Exists(igesDirPath + "\" + fileName + ".igs") Then fileName += Now.ToString(" (yyyyMMddHHmmssfff)") Dim igesPath As String = igesDirPath + "\" + fileName + ".igs" ' Logger.Info(vbTab & "igesPath: " & igesPath) modelDoc.SaveAs(igesPath, True) ' SaveCopyAs := True End Sub Private invApp As Inventor.Application Private aDoc As AssemblyDocument Private igesDirPath As String