Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Promote component with iLogic

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
waynehelley
1520 Views, 10 Replies

Promote component with iLogic

Hi there,

 

does anybody know if it is possible to promote components using iLogic.

 

If so, I would like to write some ilogic code which promotes all components from a sub-assembly into the top level assembly.

 

i.e.

 

For each component in Sub-Assembly

Promote component

Next

Delete Sub-Assembly (since it is now empty)

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Tags (2)
10 REPLIES 10
Message 2 of 11
LukeDavenport
in reply to: waynehelley

Hello Wayne,

I believe our fearless leader Brian Ekins has answered this question here:

 

http://modthemachine.typepad.com/my_weblog/2010/03/flattening-an-assembly.html

 

Does that work?

Message 3 of 11
waynehelley
in reply to: LukeDavenport

Thanks Luke.  It's along the right lines but I don't need to flatten the assembly completely, just bring everything up a level and I would like to stick to iLogic, not VBA.

 

Basically I want our engineers to be able to open a blank template (lets call it template1).  When opening the template, the user will be met with either a user form or message box. Depending on the user selection, iLogic will get an existing assembly (lets call one of them assembly1).

 

So now assembly1 is sitting as a sub-assembly within template1.  I don't want it as a sub-assembly as I need my iLogic code to swap parts in and out of this assembly dependant on the user selection.

 

My idea was that all the parts and sub-assemblies in assembly1 would get promoted so that they can be swapped/changed without assembly1 having to be editted.

 

I could have maybe made it so that my ilogic code opens assembly1 and saves a copy of it which would then become my active document.  The problem with this would be that all my ilogic would be left behind in template1.

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 4 of 11
waynehelley
in reply to: waynehelley

Basically I want to copy & Paste all components from one assembly to my active assembly.  It is important that I keep the Component names in the browser tree though as my iLogic code will use them

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 5 of 11
LukeDavenport
in reply to: waynehelley

 

Hi Wayne,

I think you may be overcomplicating it. The following should work fine:

 

1) Place the subassembly into the new assembly as you are currently

2) Replace/Suppress/Resize the components in the subassembly as required. This will require that the browser nodes of the subassembly have been 'stabilised'  beforehand - see this blog of mine for details - the good news is that this only has to be performed once.

 

 

http://www.cadlinecommunity.co.uk/Blogs/Blog.aspx?ScoId=4c497393-05a4-410e-841c-bcf51639a770&returnT...

 

(Note that you will also need to 'stabilise' the name of the subassembly itself beforehand - this would be the 'Assembly1' name in the screenshot below)

Capture.JPG

 

Editing the parts in the sub-assembly is very simple - there's dozens of posts on this forum to help.

Does this help?

 

Message 6 of 11
waynehelley
in reply to: waynehelley

Not quite. It is essential that 'Assembly1' remains unedited so I would have a problem unless I added some code to duplicate it.

I would much rather have all the components appear in the top-level instead of having a sub-assembly.
Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 7 of 11
LukeDavenport
in reply to: waynehelley

 

Do you need to make a copy of all the subassembly parts, or just the top level of the subassembly? If the latter then it might be easiest to save the subassembly as a template and then use that template to create the new subassembly, then programmatically place it into the top-level assembly.

 

This code will create a new assembly from the template 'MYTEMPLATENAME.iam'. You might want to try changing the 'False' to 'True' at the end, as this will create the new assembly invisibly (before you place it into your top level).

 

If you are really set on placing all the components individually into a new assembly that might be more effort, and not sure what you gain - perhaps making the subassembly 'Phantom' BOM to promote the parts instead will be enough for you?

 

ThisApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, _
ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath & "MYTEMPLATENAME.iam", True)

Message 8 of 11
waynehelley
in reply to: LukeDavenport

Basically I would like the user to only have one assembly to save and put through our PLM system.  That is why I want to be working in a copy of 'Assembly1' but with all my iLogic and parameters from 'Template1'.

 

If its not possible to achieve this by placing Assembly1 into Template1 and promoting the components, I will probably go for a different method.  I could use my iLogic code to locate the correct assembly (e.g. Assembly1), save a copy of it, the assembly will be altered by the ilogic code base on the users choices.

 

The disadvantage of this method will be that the ilogic code will be a 'one-shot' and the user won't be able to go back and make further changes via a User form because all my logic will be left behind in Template1.

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 9 of 11
fatih_ulus
in reply to: waynehelley

Hi Wayne,

 

I was looking for a solution too, and stumbled across your post. I did not see a good solution unfortunately, but I figured it out myself with some help of the Inventor 2021 API Help.

' Get the active assembly document
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oDef As AssemblyComponentDefinition
oDef = oDoc.ComponentDefinition

' Get the top level occurrence of an assembly
Dim oSubAssyOcc As ComponentOccurrence

' Insert the name of the subassembly as shown in the modeltree
oSubAssyOcc = oDef.Occurrences.ItemByName("SubAssembly")

' Get the 2nd level occurrence under the assembly occurrence
Dim oSubOcc As ComponentOccurrenceProxy
Dim oPane As BrowserPane
' Keep "Model"
oPane = oDoc.BrowserPanes.Item("Model")

' Get the browser nodes corresponding to the two occurrences
Dim oTargetNode As BrowserNode
oTargetNode = oPane.GetBrowserNodeFromObject(oSubAssyOcc)

' Insert the name of the subassembly as shown in the modeltree again
For Each oSubOcc In oDef.Occurrences.ItemByName("SubAssembly").SubOccurrences
	    Dim oSourceNode As BrowserNode
	    oSourceNode = oPane.GetBrowserNodeFromObject(oSubOcc)

	    ' Reorder the nodes to promote the sub-occurrence to the top level
	    Call oPane.Reorder(oTargetNode, True, oSourceNode)
Next

'Delete the assembly its from
oSubAssyOcc.Delete()

This will maintain the constraints too, and will make it easier to manage than inserting each part individually.

 

I'm 7 years late, but people who are seeking for an answer might find it in this code.

Tags (2)
Message 10 of 11
davis.j
in reply to: fatih_ulus

@fatih_ulus 

Good work.

 

I wanted to be able to select the assembly you want to flatten so I made some changes below.

I couldnt figure it out but my only want now is the ability to to select multiple assemblies first and then get them to all flatten at the same time. (Rather than pick, flatten, pick, flatten, pick flatten, .....). 

 

If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule must be run from an Assembly.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1) : Exit Sub

' Get the active assembly document
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument

' Define the active assembly document
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

' Get the top level occurrence of an assembly
Dim oSubAssyOcc As ComponentOccurrence

'User Selections
pick1 : Dim PickThis As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Assembly or Press ESC")
If IsNothing(PickThis) Then Exit Sub 
PickThis.Name = PickThis.Definition.Document.ComponentDefinition.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value

' Insert the name of the subassembly as shown in the modeltree
oSubAssyOcc = oDef.Occurrences.ItemByName(PickThis.Name)

' Get the 2nd level occurrence under the assembly occurrence
Dim oSubOcc As ComponentOccurrenceProxy
Dim oPane As BrowserPane
' Keep "Model"
oPane = oDoc.BrowserPanes.Item("Model")

' Get the browser nodes corresponding to the two occurrences
Dim oTargetNode As BrowserNode
oTargetNode = oPane.GetBrowserNodeFromObject(oSubAssyOcc)

' Insert the name of the subassembly as shown in the modeltree again
For Each oSubOcc In oDef.Occurrences.ItemByName(PickThis.Name).SubOccurrences
	    Dim oSourceNode As BrowserNode
	    oSourceNode = oPane.GetBrowserNodeFromObject(oSubOcc)

	    ' Reorder the nodes to promote the sub-occurrence to the top level
	    Call oPane.Reorder(oTargetNode, True, oSourceNode)
Next

'Delete the assembly its from
oSubAssyOcc.Delete()

 

Message 11 of 11

 Hello All,

fatih_ulus & davis.j great piece of code I was looking for something like that for long time. I tested on my models and it works great when each of the subassembly is a uniqe. Unfortunatelly in my main assembly  I have several of the same subassemblies and in those conditions the is keeping only one instance of the promoted parts. Is there a way (I'm sure there is) that code will promote all the parts from all occurances of the same subassemblies?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report