Imports System.Windows.Forms ' Ensure this is included for form elements Sub Main() Try ' Get the active document Dim oDoc As Document = ThisApplication.ActiveDocument ' Check if document is a valid assembly or part If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kPartDocumentObject) Then MessageBox.Show("Please open an assembly or part document to run this rule.") Exit Sub End If ' Access the Component Definition Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition Dim oBIM As BIMComponent = oCompDef.BIMComponent If oBIM Is Nothing Then MessageBox.Show("No BIM Component available in the current document.") Exit Sub End If ' Create a FolderBrowserDialog for folder selection Dim folderBrowser As New FolderBrowserDialog() folderBrowser.Description = "Select the export folder" folderBrowser.ShowNewFolderButton = True ' Show the dialog and get the result If folderBrowser.ShowDialog() = DialogResult.OK Then Dim exportFolder As String = folderBrowser.SelectedPath ' Select UCS using the function Dim masterUCS As UserCoordinateSystem = SelectUCS(oCompDef.UserCoordinateSystems) If masterUCS Is Nothing Then MsgBox("No valid UCS selected. Exiting script.") Exit Sub End If ' Set the UCS oCompDef.UserCoordinateSystem = masterUCS ' Define export file name Dim exportFileName As String = IO.Path.Combine(exportFolder, oDoc.DisplayName & ".rfa") ' Perform export Try oBIM.ExportBuildingComponent(exportFileName) ' Export with the selected UCS MessageBox.Show("Exported to: " & exportFileName) Catch ex As Exception MessageBox.Show("Error during export: " & ex.Message) End Try Else MessageBox.Show("No folder selected. Exiting script.") End If Catch ex As Exception MessageBox.Show("Unexpected error: " & ex.Message) End Try End Sub ' Function to select a UCS Function SelectUCS(oUCSs As UserCoordinateSystems) As UserCoordinateSystem Dim ucsNames As String = "Available UCS: " & vbCrLf Dim i As Integer = 1 Dim selectedUCS As UserCoordinateSystem = Nothing ' List all UCS names For Each ucs As UserCoordinateSystem In oUCSs ucsNames &= i & ": " & ucs.Name & vbCrLf i += 1 Next ' Prompt the user to select a UCS Dim input As String = InputBox(ucsNames & vbCrLf & "Enter the UCS number to use:", "Select UCS") If IsNumeric(input) AndAlso CInt(input) >= 1 AndAlso CInt(input) <= oUCSs.Count Then selectedUCS = oUCSs(CInt(input) - 1) ' Adjust for zero-based index Else MsgBox("Invalid selection.") End If Return selectedUCS End Function