Hello
A real embarrassing mistake. In line 44 I call the ExportIGES Sub with folder and filename, but the sub awaits both informations in reverse order. Have tested and should work now. Added a short "Done" message at end. Remove it when not needed.
Option Explicit On
Imports System.Windows.Forms
Sub Main
If Not ThisDoc.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("Function available only in assemblies", MsgBoxStyle.Critical, "iLogic - Save as IGES")
Exit Sub
End If
Dim openDoc As AssemblyDocument
openDoc = ThisDoc.Document
Dim oFileDlg As FolderBrowserDialog = New System.Windows.Forms.FolderBrowserDialog()
oFileDlg.SelectedPath=ThisDoc.WorkspacePath() 'Workspace path in active project
oFileDlg.Description="Select target folder for IGES Export"
Dim result As DialogResult = oFileDlg.ShowDialog
Dim sfolder As String
If result = DialogResult.OK Then
sfolder = oFileDlg.SelectedPath
Else
MsgBox("Function aborted by user.", MsgBoxStyle.Information, "iLogic - Save as IGES")
Exit Sub
End If
'Look at all of the files referenced in the open document
Dim sfilename As String
Dim docFile As Document
Dim docPart As PartDocument
Dim param As Inventor.Parameter
For Each docFile In openDoc.AllReferencedDocuments
If docFile.DocumentType=DocumentTypeEnum.kPartDocumentObject Then
docPart=DirectCast(docFile,PartDocument)
Try
param = docPart.ComponentDefinition.Parameters.UserParameters.Item("PART_TAG")
Catch
MsgBox("Parameter 'PART_TAG' not found in part " & docPart.DisplayName & vbCrLf & "Skipping this part and try next one.", MsgBoxStyle.Exclamation, "iLogic - Save as IGES")
Continue For
End Try
sfilename = param.Value
ExportIGES(docFile, sfilename, sfolder)
End If
Next
MsgBox("Done",MsgBoxStyle.Information,"iLogic - Export to IGES")
End Sub
Private Sub ExportIGES(ByVal oDoc As PartDocument, ByVal sFileName As String, sFolder As String)
Dim oIGESTranslator As TranslatorAddIn
oIGESTranslator = ThisApplication.ApplicationAddIns.ItemById _
("{90AF7F44-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
If oIGESTranslator.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
' Set geometry type for wireframe.
' 0 = Surfaces, 1 = Solids, 2 = Wireframe
'oOptions.Value("GeometryType") = 1
' To set other translator values:
' oOptions.Value("SolidFaceType") = n
' 0 = NURBS, 1 = Analytic
' oOptions.Value("SurfaceType") = n
' 0 = 143(Bounded), 1 = 144(Trimmed)
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
oData.FileName = sFolder & "\" & sFileName & ".igs"
oIGESTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData)
End If
End Sub
R. Krieg
RKW Solutions
www.rkw-solutions.com