Assembly Loop to pass sub assembly name to parts

Assembly Loop to pass sub assembly name to parts

NachoShaw
Advisor Advisor
571 Views
8 Replies
Message 1 of 9

Assembly Loop to pass sub assembly name to parts

NachoShaw
Advisor
Advisor

Hi

 

is there any code about that would help me do the following from the top level assembly?

loop assembly

identify each sub assembly & get the part number

identify each part within that sub assembly and add the part number to a custom property

 

cant seem to figure it out...

 

 

Thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
572 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

There is a way but it's a bit complicated (rule based adjustment of the partname and replacing the old part with the new part in the main assembly). I want to create a guide on how to do it along with other usefull information on programming inside assembly's with iLogic and include custom snippets to it. Take for example making assembly's endless with the use of multiple standard and variable parts.

 

The other side is that it will take me about 2 weeks fulltime to complete and i want the information that more people are interested in this to make it worth my time.

0 Likes
Message 3 of 9

NachoShaw
Advisor
Advisor

Hi

I should mention that im not looking to rename any parts or assemblies, i just want to get the parent assembly part number and place the value in a custom field field in the child parts / assemblies

 

Thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 4 of 9

machiel.veldkamp
Collaborator
Collaborator

Hey!

 

You can loop through the whole assembly like this:

 

https://forums.autodesk.com/t5/inventor-customization/recursive-bom-need-some-help/m-p/8823958#M9791...
(last post in the link)

 

in SetRowProps() you can add another argument where you just pass the name of the parents name in RecurseBOMRow()

 

So for example:

 

Sub SetRowProps(oCompDef As ComponentDefinition, QTY As Integer, oTotalDict As Dictionary(Of String, Integer), ParentQTY As Integer, ParentName As String)

 

You'd have to enter that information when you call it of course:

Call SetRowProps(oCompDef, oBOMRow.TotalQuantity, oTotalDict, newParentQTY, <a Dim that holds the name of the parent>)

Note: for what you're doing it's probable (definitely is) way overkill to do it like this but you can do it like this.

 

 

But here's a question:

What are you going to do when one part occurs in multiple assemblies?

also... How are you going to use it? (why do you need the info there in the first place?)

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 5 of 9

NachoShaw
Advisor
Advisor

Hi

 

Its mainly for documentation. i need to add the name of the parent assembly into the sub parts / assemblies so that we can get the parent assembly listed in the titleblock. Also, if the parent assembly name already exists, than i will add to it so that it becomes a list. we have a large field that shows the result. It would be very similar to 'Where Used' in Vault.

 

so, it would be best to be a combination of occurrence & reference (because an occurrence loop takes longer)

 

From Top Level

get assembly part number

    loop assembly

    add part number in iproperty for each component part / assembly

        if component = assembly, get part number of that assembly, loop that assembly and add part number

 

the reason i say reference over occurrence is because the reference will return 1 result per component whereas the occurrence will return all instances which would take longer

 

so as a set of results;

 

top level = 1234-0670

-part 1 = 1234-8566 (Parent = 1234-0670)

-Part 2 = 1234-5833 (Parent = 1234-0670)

-Assy2 = 1234-2855 (Parent = 1234-0670)

--Part 3 = 1234-6355 (Parent = 1234-2855)

--Part 4 = 1234-9144 (Parent = 1234-2855)

--Assy 3 = 1234-6994 (Parent = 1234-2855)

---Part 5 = 1234-7455 (Parent = 1234-6994)

---Part 6 = 1234-5345 (Parent = 1234-6994)

--Part 7 = 1234-0451 (Parent = 1234-2855)

-Part 8 = 1234-4222 (Parent = 1234-0670)

 

unless we can access the WhereUsed property in a part?

 

 

Thanks

 

    

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 6 of 9

Anonymous
Not applicable

Try this:

 

Sub main()
	
	
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

Call createcostumprop(oDoc)
Dim occ As ComponentOccurrence
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	For Each occ In oDoc.ComponentDefinition.Occurrences
		If occ.Name = "" Then GoTo 1 :
		
		Call createcostumprop(occ.definition.document)
		If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
			Call processubassembly(occ)
		End If
		1 :
	Next
End If

End Sub

 Sub processubassembly(occ As ComponentOccurrence)
oDoc = occ.Definition.Document

Dim Subocc As ComponentOccurrence
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	For Each Subocc In oDoc.ComponentDefinition.Occurrences
		If Subocc.Name = "" Then GoTo 1 :
		
		Call createcostumprop(Subocc.definition.document)
		If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
			Call processubassembly(subocc)
		End If
		1 :
	Next
End If
	 
 End Sub
 
 
 
Sub createcostumprop(Odoc As Document)

customPropertySet = Odoc.PropertySets.Item("Inventor User Defined Properties")

Try
	customPropertySet.Item("Costum Property").Value=Odoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
Catch
	
    customPropertySet.Add("","Costum Property")
End Try
	
End Sub
0 Likes
Message 7 of 9

machiel.veldkamp
Collaborator
Collaborator

Do you output that to a textfile?

 

Also.... can you post it when you are done? I like the idea!

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 8 of 9

NachoShaw
Advisor
Advisor

Hi

 

no im actually checking each component during the loop for a custom iproperty. if it doesnt exist, it will get created and then the part number of the parent assembly will be placed into the custom field. Then when the part / assembly is placed onto the sheet, the parent assembly / assemblies are listed so that fabrication can refer to the documentation. The part number is the same as the drawing number.

 

Thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 9 of 9

Anonymous
Not applicable

Then change the code to get the assembly part number in a ipropertie to:

 

Sub createcostumprop(Odoc As Document)

customPropertySet = Odoc.PropertySets.Item("Inventor User Defined Properties")

mainOdoc= Thisapplication.ActiveDocument

Try
customPropertySet.Item("Costum Property").Value=mainOdoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
Catch

    customPropertySet.Add("","Costum Property")

  customPropertySet.Item("Costum Property").Value=mainOdoc.PropertySets.Item("Design Tracking properties").Item("Part Number").Value
End Try

End Sub

0 Likes