Hi @jwoutersJC4LN. I am not sure what options you want set to which values when exporting those parts out as STP files, so I left all the options in this code example commented out for now. You can still see them in the code, down within the 'ExportToSTEP' Sub routine (Lines 40 through 46), so you can delete the apostrophe from the front of any of those lines that you want to use, and can change the value being set to them however you want. When checking the iProperties of regular (not sheet metal) parts, I was not sure if both properties need have that same "laser" value before exporting, or if only one of them has that value, it is OK to export it. You were not very clear there.
Sub Main
Dim oInvApp As Inventor.Application = ThisApplication
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
For Each oRefDoc As Inventor.Document In oADoc.AllReferencedDocuments
If (Not TypeOf oRefDoc Is PartDocument) Then Continue For
Dim oRefPDoc As PartDocument = oRefDoc
Dim sSTP_File As String = System.IO.Path.ChangeExtension(oRefPDoc.FullFileName, ".stp")
If (TypeOf oRefPDoc.ComponentDefinition Is SheetMetalComponentDefinition) Then
ExportToSTEP(oRefPDoc, sSTP_File)
Else 'a part, but not sheet metal
Dim sProject As String = oRefPDoc.PropertySets.Item(3).Item(3).Value 'Project
Dim sAuthority As String = oRefPDoc.PropertySets.Item(3).Item(26).Value 'Authority
If sProject = "laser" Or sAuthority = "laser" Then
ExportToSTEP(oRefPDoc, sSTP_File)
End If
End If
Next
End Sub
Sub ExportToSTEP(oDoc As Document, sNewFullFileName As String)
Dim oSTEP As TranslatorAddIn
oSTEP = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oDataMedium As DataMedium = oTO.CreateDataMedium
If System.IO.File.Exists(sNewFullFileName) Then
Dim oAns As MsgBoxResult = MsgBox("A STEP file with this name already exists." & vbCrLf &
sNewFullFileName & vbCrLf & _
"Do you want to overwrite it with this new one?", vbYesNo + vbQuestion + vbDefaultButton2, "STEP FILE EXISTS")
If oAns = MsgBoxResult.No Then Exit Sub
End If
'<<< this is where the full path and file name of the exported file is set >>>
oDataMedium.FileName = sNewFullFileName
If oSTEP.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
' 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(14).Value 'Description
'oOptions.Value("Organization") = oDoc.PropertySets.Item(2).Item(3).Value 'Company
Try
oSTEP.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
Catch
Logger.Error("Error exporting following document to STEP:" & vbCrLf & oDoc.FullDocumentName)
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)