Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

This rule assumes view #1 (normally the first view you placed) has the assembly you want to export .stp files from. It also assumes there are only parts, no subassemblies.

Imports System.Windows.Forms

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = sheet.DrawingViews.Item(1)
Dim assembyDoc As AssemblyDocument = view.ReferencedDocumentDescriptor.ReferencedDocument

' Get current location of this file
Dim ExportPath As String = ThisDoc.Path

' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
	MsgBox("This file has not yet been saved and doesn't exist on disk!")
	Return
End If

Dim dialog = New FolderBrowserDialog()

dialog.SelectedPath = ExportPath

If dialog.ShowDialog() = DialogResult.OK Then
	For Each occurrence As ComponentOccurrence In assembyDoc.ComponentDefinition.Occurrences
		If (occurrence.DefinitionDocumentType = kPartDocumentObject) Then
			Dim partDoc As PartDocument = occurrence.Definition.Document
			
			' Get the STEP translator Add-In.
			Dim stepTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
			Dim translatorContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
			Dim translatorOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

			If stepTranslator.HasSaveCopyAsOptions(partDoc, translatorContext, translatorOptions) Then
				translatorOptions.Value("ApplicationProtocolType") = 3
				translatorContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

				Dim translatorData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
				translatorData.FileName = dialog.SelectedPath & "\" & System.IO.Path.ChangeExtension(partDoc.DisplayName, ".stp")

				stepTranslator.SaveCopyAs(partDoc, translatorContext, translatorOptions, translatorData)
			End If 
		End If
	Next
	
	
End If