10-19-2023
07:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-19-2023
07:14 AM
I have rewritten the rule a bit and it should work now. At least it works on my system.
I'm not sure if you noticed but the last part of the script does nothing and could be left out. I left it in because I dont know if you have plans with it.
' Check if an assembly document is active
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("Please open an assembly document first.")
Exit Sub
End If
' Get the active assembly document
Dim originalAssembly As AssemblyDocument = ThisDoc.Document
' Prompt the user for a new file name for the copied assembly
Dim oFileDlg As Inventor.FileDialog
Call ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Drawing Files (*.iam)| *.iam"
oFileDlg.FilterIndex = 1
oFileDlg.DialogTitle = "Select drawing template"
'oFileDlg.InitialDirectory = "c:\"
oFileDlg.MultiSelectEnabled = False
oFileDlg.CancelError = False
oFileDlg.ShowSave()
Dim newFileName As String = oFileDlg.FileName
' Check if the user canceled the input
If newFileName = "" Then
Exit Sub
End If
' Save a copy of the assembly with the new file name
originalAssembly.SaveAs(newFileName, True)
' Close the original assembly
originalAssembly.Close(True)
' Open the copied assembly
Dim copiedAssembly As AssemblyDocument = ThisApplication.Documents.Open(newFileName)
' Iterate through the components in the copied assembly and remove suppressed components
For Each component As ComponentOccurrence In copiedAssembly.ComponentDefinition.Occurrences
If component.Suppressed Then
component.Delete2(True) ' Delete the suppressed component
End If
Next
' Code below this line does nothing!
' List of components to be reused (replace with your own file names)
Dim componentsToReuse As New List(Of String)
componentsToReuse.Add("UHDL13.50CollarPhantom.iam")
componentsToReuse.Add("907926.ipt")
' Iterate through the components in the copied assembly
For Each component As ComponentOccurrence In copiedAssembly.ComponentDefinition.Occurrences
Dim componentName As String
componentName = component.Name
' Check if the component should be reused or copied
If componentsToReuse.Contains(componentName) Then
' Component should be reused
' You can add code here to update the position or configuration if needed
Else
' Component should be copied
' You can add code here to copy the component or replace it with a new version
' For example, you can replace it with a different IPT file using the File.Copy function.
End If
Next
' Inform the user
MsgBox("Assembly copied successfully with a new file name: " & newFileName)
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com