BOM Structure - Component Pattern Elements

BOM Structure - Component Pattern Elements

DewayneH
Advocate Advocate
1,143 Views
6 Replies
Message 1 of 7

BOM Structure - Component Pattern Elements

DewayneH
Advocate
Advocate

I need to set the BOMStructure of all the elements of a component pattern to reference or default depending on a parameter. 

Initially, I thought it would be as easy as setting the BOMStructure for the pattern:

 

If Parameter("Belt", "BucketRowQ") = 1 Then
Component.InventorComponent("Double-Buckets and Hardware").BOMStructure = BOMStructureEnum.kReferenceBOMStructure

Apparently that does nothing.

Based on my digging, it looks like I have to deal with each element individually.

The quantities are changing so I need to be able to affect all the elements in the pattern regardless of the quantity.

 

Basically if the parameter = 1, the BOMStructure of all elements will be reference.

If it = 2 they they will be set to default.

 

I have found some examples dealing with pattern visibility and BOM structure, but not exactly what I need.

I've tried patching some code together but I'm far from experienced. Can't find solutions, but I can find errors.

 

Thanks in advance.

 

 

Dewayne
Inventor Pro 2023
Vault Pro 2023
0 Likes
Accepted solutions (1)
1,144 Views
6 Replies
Replies (6)
Message 2 of 7

Sergio.D.Suárez
Mentor
Mentor

Hi, here I share an idea to access each occurrence within each element of a pattern of components in an assembly. You will have to put the name of your pattern of components in the string that I have highlighted in green.

 

Dim oPatName As String = "Component Pattern 1:1"

Dim doc As AssemblyDocument = ThisDoc.Document
Dim oCD As AssemblyComponentDefinition = doc.ComponentDefinition

Dim oPatt As RectangularOccurrencePattern = oCD.OccurrencePatterns.Item(oPatName)


If Parameter("Belt", "BucketRowQ") = 1 Then
	For Each oEl As Inventor.OccurrencePatternElement In oPatt.OccurrencePatternElements
		For Each oCC As ComponentOccurrence In oEl.Occurrences
			oCC.BOMStructure = 51972
		Next
	Next
End If

 Please note that this change is made at the assembly level, not at the component level. you can place the same component as a reference in one element and the same component is not a reference in another element of the pattern if you access in this way.   Also keep in mind that the code you provide works for a rectangular pattern. If you have a circular pattern you should change the definition of the pattern to  CircularOccurrencePattern

I hope this helps with your work. Cheers!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 7

DewayneH
Advocate
Advocate

Sergio,

 

I put in the pattern name as instructed and ran the rule but got the following errror:

 

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.RectangularOccurrencePattern'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A8E2C150-78E9-4E97-A4A0-BF43936B2A45}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

Thank you for the suggestion. Any idea what caused the error?

 

 

Dewayne
Inventor Pro 2023
Vault Pro 2023
Message 4 of 7

Sergio.D.Suárez
Mentor
Mentor

could you share a simple test assembly? you do not need to disclose confidentiality of your files. Just a simple example with a testing parameter. It could be an assembly with a single component and a pattern of this single component. Be sure to share the assembly and this assembly component. Cheers!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 5 of 7

DewayneH
Advocate
Advocate

I put together an example. It is greatly simplified, but it should convey the issue. No pun intended.

The example is attached and here is a link to a screencast that displays it in action.

https://autode.sk/2KjhsgC

 

To summarize:

Basically I have a one or two rows of buckets configuration.

In reality the buckets need to follow a path so in the example I set it up the same.

 

For a one row configuration the second row qty is set to one, BOM structure changed to reference, and the visibility is turned off.

For a two row configuration the required quantity is set, BOM structure is changed to default, and the visibility is turned back on.

 

The issue is presented when the second row is activated.

The BOM structure of the first bucket element is changed to default via ilogic. The problems is by then the other elements of the pattern have been patterned based on the initial reference BOM Structure of the first element.

This is the reason I need to change the BOM structure for all the elements.

 

In my example there is a form in the Belt.ipt to configure the holes, select one of the two options.

In the assembly there is a form that will present one of two rules:

Set bucket - Sets the bucket visibility and was intended to set the bom structure.

BOM Structure fix - This is the rule you supplied displaying the error.

Dewayne
Inventor Pro 2023
Vault Pro 2023
0 Likes
Message 6 of 7

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, excuse me for being late to answer. It is a heavy week for me.
The first defect in what I proposed to you previously is the type of generated pattern. for that reason the code will not work for you.
Your pattern is driven by feature, so you should use the definition "FeatureBasedOccurrencePattern"

Dim oPatName As String = "Double Row Buckets"

Dim doc As AssemblyDocument = ThisDoc.Document
Dim oCD As AssemblyComponentDefinition = doc.ComponentDefinition

Dim oPatt As Inventor.FeatureBasedOccurrencePattern = oCD.OccurrencePatterns.Item(oPatName)

For Each oEl As Inventor.OccurrencePatternElement In oPatt.OccurrencePatternElements
	If BucketTrigger = 14 Then
		For Each oCC As ComponentOccurrence In oEl.Occurrences
			oCC.BOMStructure = 51969 
			oCC.Visible = True
		Next
	End If 
	If BucketTrigger = 6 Then
		For Each oCC As ComponentOccurrence In oEl.Occurrences
			oCC.BOMStructure = 51972
			oCC.Visible = False
		Next
	End If
Next


On the other hand, you are already importing into the assembly a parameter of the part that can serve as control of the assembly. I have entered this parameter inside the For - next instruction
Please check the assembly and make sure it meets your needs. I hope this helps with your work. Cheers


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 7 of 7

DewayneH
Advocate
Advocate

 

Sergio,

 

The data set worked beautifully.

I did initially have some issues when I updated the new code in my production model.

It was all due to some naming differences between the two model sets.

Once I corrected, it runs like a charm.

 

Thanks so much for the help.

 

Dewayne
Inventor Pro 2023
Vault Pro 2023