ilogic for save as assembly including child parts into new location
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
iLogic for save as the assembly includes the child parts into a new Location. After doing this, the new child parts should be referenced or linked with the new assembly.
The Following will used for Save as the assembly and child parts into a new location, but the parts wouldn't linked with the new assembly.
' iLogic rule to copy an assembly and its referenced files to a new location
' Ensure the current document is an assembly
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
If oAsmDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MessageBox.Show("This rule only works on assembly documents.", "Error")
Return
End If
' Prompt user to select a new target folder
Dim fbd As New System.Windows.Forms.FolderBrowserDialog
fbd.Description = "Select the folder where the assembly and its parts will be copied"
If fbd.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return
Dim targetFolder As String = fbd.SelectedPath
' Prompt for new assembly name
Dim newAsmName As String = InputBox("Enter the new assembly file name (without extension):", "Save As", "NewAssembly")
If String.IsNullOrWhiteSpace(newAsmName) Then Return
Dim fso As Object = CreateObject("Scripting.FileSystemObject")
' === 1. Copy all referenced documents ===
Dim refDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
For Each refDoc As Document In refDocs
If Not String.IsNullOrEmpty(refDoc.FullFileName) Then
Dim srcPath As String = refDoc.FullFileName
Dim destPath As String = System.IO.Path.Combine(targetFolder, System.IO.Path.GetFileName(srcPath))
If Not System.IO.File.Exists(destPath) Then
System.IO.File.Copy(srcPath, destPath)
End If
End If
Next
' === 2. Copy the assembly file itself with the new name ===
Dim newAsmPath As String = System.IO.Path.Combine(targetFolder, newAsmName & ".iam")
Dim currentAsmPath As String = oAsmDoc.FullFileName
System.IO.File.Copy(currentAsmPath, newAsmPath, True)
' === 3. Open the new assembly in Inventor ===
Dim newDoc As AssemblyDocument = ThisApplication.Documents.Open(newAsmPath, True)
MessageBox.Show("Assembly and components saved to: " & targetFolder, "Success")