- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I was reviewing the original post by @Anonymous in which I interpreted that he wanted to create a new assembly and then add components to it.
@HermJan.Otterman explained how to create a new assembly. @MechMachineMan explained how to add components to an existing assembly.
My question - how do you make the new assembly as the existing (active) assembly in which to add the new components?
Here is the code I have so far. You will need to substitute your template path and component as needed:
Sub Main()
' Create and activate new assembly
Dim oTemplatePath = "Z:\Inventor_Data\Templates\"
Dim oAssembly As AssemblyDocument
oAssembly = ThisApplication.Documents.Add(kAssemblyDocumentObject, oTemplatePath & "MY_ASSEMBLY.iam", True)
oAssembly.Activate
' Insert and name Comp_01
Dim componentA = Components.Add("Comp_01", "ABC123.ipt", position := Nothing, grounded := False, visible := True, appearance := Nothing)
End Sub
The above code errors if run from a part:
Error in rule: ThisAssembly: This document "Part2" is not an assembly.
When run from an open assembly, a new assembly is created, but the component is added in the first assembly document, NOT the new assembly.
I hope someone can offer a solution. A workaround would be to ask the user to create a new assembly with the required template before running the code.
Thanks for your time. I look forward to the responses.
Regards,
Jerry
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional