Hi @baraknidam1. Just posting another iLogic rule example for the process you seem to be wanting to do. This version does not bother iterating through drawing sheets or drawing views, but simply uses the drawing's AllReferencedDocuments collection, and filters for parts only (does not process any assemblies, if it finds any). When using 'AllReferencedDocuments', it will look at every level of any assemblies that may be referenced, and process the parts within those levels. If you only want to process top level documents, that have a direct reference to the drawing, you can change that one term on line 7 from 'AllReferencedDocuments' to 'ReferencedDocuments' instead. This export process accesses the translator AddIn directly, allowing you to specify some settings/options, similar to when you do it manually, and choose the Options button, and fill in those options/settings. I left several of those options commented out, because I was not sure if or how you would want them set.
Here is the code:
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oRefDocs As DocumentsEnumerator = oDDoc.AllReferencedDocuments
If oRefDocs.Count = 0 Then Exit Sub
For Each oRefDoc As Document In oRefDocs
'only process parts, not assemblies
If oRefDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
'same path and name as original, but with ".stp" file extension
Dim oStepFileName As String = System.IO.Path.ChangeExtension(oRefDoc.FullFileName, ".stp")
ExportToSTEP(oRefDoc, oStepFileName)
Next
MsgBox("Done exporting all referenced parts to STEP files.", vbInformation, "Export To STEP Done")
End Sub
Sub ExportToSTEP(oDoc As Document, oNewFileName As String)
Dim oSTEP As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById( _
"{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
'create needed variables for translator
oTO = ThisApplication.TransientObjects
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
oDataMedium = oTO.CreateDataMedium
If System.IO.File.Exists(oNewFileName) Then
oAns = MsgBox("A STEP file with this name already exists." & vbCrLf & _
oNewFileName & vbCrLf & _
"Do you want to overwrite it with this new one?",vbYesNo + vbQuestion + vbDefaultButton2, "STEP FILE EXISTS")
If oAns = vbNo Then Exit Sub
End If
oDataMedium.FileName = oNewFileName
If oSTEP.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
oOptions.Value("ApplicationProtocolType") = 3
oOptions.Value("IncludeSketches") = True
oOptions.Value("export_fit_tolerance") = .000393701 'minimum
'oOptions.Value("Author") = ThisApplication.GeneralOptions.UserName
'oOptions.Value("Authorization") = ""
'oOptions.Value("Description") = oDoc.PropertySets.Item(3).Item("Description").Value
'oOptions.Value("Organization") = oDoc.PropertySets.Item(2).Item("Company").Value
Try
oSTEP.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
Catch
MsgBox("Your attempt to export the following document:" & vbCrLf & _
oDoc.FullFileName & vbCrLf & _
"as the following STEP file:" & vbCrLf & _
oDataMedium.FileName & vbCrLf & _
"FAILED!", vbExclamation, "Export to STEP Error")
End Try
End If
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)