iLogic Code for STEP Export of Assembly

iLogic Code for STEP Export of Assembly

noakes_eng
Advocate Advocate
264 Views
2 Replies
Message 1 of 3

iLogic Code for STEP Export of Assembly

noakes_eng
Advocate
Advocate

Dear Forum,

 

I am having problems with the following code to export STEP files to a file of my choice.

 

Please see code snippet below:

Public Sub ExportToSTEP()
    ' Get the STEP translator Add-In.
    Dim oSTEPTranslator As TranslatorAddIn
        oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")

    If oSTEPTranslator Is Nothing Then
        MsgBox "Could not access STEP translator."
       Exit Sub
    End If

Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

SavePath = "F:\Noakes Engineering\Design\Vault Inventor\$WorkingFolder\Engineering Data\EX Range\DHX\DHX2.5-5.0 Mast Assembly Files\DHX 2550 Mast Assemby V2.0\DHX2550 Mast Assembly APPROVED MFG"

If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
    ' Set application protocol.
    ' 2 = AP 203 - Configuration Controlled Design
    ' 3 = AP 214 - Automotive Design
    oOptions.Value("ApplicationProtocolType") = 3
    ' Other options...
    'oOptions.Value("Author") = ""
    'oOptions.Value("Authorization") = ""
    'oOptions.Value("Description") = ""
    'oOptions.Value("Organization") = ""
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    Dim oData As DataMedium
     oData = ThisApplication.TransientObjects.CreateDataMedium
    oData.FileName = SavePath & ThisDoc.FileName(False) & ".stp"
       Call oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
   End If
End Sub
0 Likes
Accepted solutions (1)
265 Views
2 Replies
Replies (2)
Message 2 of 3

noakes_eng
Advocate
Advocate

I have now added a Sub main() as requested by Ilogic:

Sub Main()

    Call ExportToSTEP()

End Sub


Public Sub ExportToSTEP()
    ' Get the STEP translator Add-In.
    Dim oSTEPTranslator As TranslatorAddIn
        oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")

    If oSTEPTranslator Is Nothing Then
        MsgBox ("Could not access STEP translator.")
       Exit Sub
    End If

Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

SavePath = "F:\Noakes Engineering\Design\Vault Inventor\$WorkingFolder\Engineering Data\EX Range\DHX\DHX2.5-5.0 Mast Assembly Files\DHX 2550 Mast Assemby V2.0\DHX2550 Mast Assembly APPROVED MFG"

If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
    ' Set application protocol.
    ' 2 = AP 203 - Configuration Controlled Design
    ' 3 = AP 214 - Automotive Design
    oOptions.Value("ApplicationProtocolType") = 3
    ' Other options...
    'oOptions.Value("Author") = ""
    'oOptions.Value("Authorization") = ""
    'oOptions.Value("Description") = ""
    'oOptions.Value("Organization") = ""
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    Dim oData As DataMedium
     oData = ThisApplication.TransientObjects.CreateDataMedium
    oData.FileName = SavePath & ThisDoc.FileName(False) & ".stp"
       Call oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
   End If
End Sub
0 Likes
Message 3 of 3

noakes_eng
Advocate
Advocate
Accepted solution

Hello Forum,

 

I am pleased to say I have solved this myself here it is.

 

The below code works to export .iam as multiple STEP files to the file of your choice:

 

Does not export the sub-assemblies if anyone can help?

 

Sub Main()
Call ExportPartsToSTEP()
End Sub

Public Sub ExportPartsToSTEP()
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")

If oSTEPTranslator Is Nothing Then
MsgBox ("Could not access STEP translator.")
Exit Sub
End If

Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

SavePath = "****(FILE OF YOUR CHOICE LEAVE \ AT END TO PUT IN THE FILE****)\"

' Get the active assembly document
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Iterate through each component in the assembly
Dim oComp As ComponentOccurrence
For Each oComp In oAsmDoc.ComponentDefinition.Occurrences
' Check if the component is a part (not another assembly)
If oComp.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
' Get the part document
Dim oPartDoc As PartDocument
oPartDoc = oComp.Definition.Document

If oSTEPTranslator.HasSaveCopyAsOptions(oPartDoc, oContext, oOptions) Then
' Set application protocol.
oOptions.Value("ApplicationProtocolType") = 2

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium

' Create the file name using the part number
oData.FileName = SavePath & oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value & ".stp"

Call oSTEPTranslator.SaveCopyAs(oPartDoc, oContext, oOptions, oData)
End If
End If
Next
End Sub