Save and replace selection on BOM-Structure iLogic

Save and replace selection on BOM-Structure iLogic

Anonymous
Not applicable
773 Views
5 Replies
Message 1 of 6

Save and replace selection on BOM-Structure iLogic

Anonymous
Not applicable

Good morning!

 

I've been trying to get my head around this for a long time but can't get it to work. I've been trying to Save and Replace certain parts from my assembly which have the normal BOM-structure. 

Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager

Dim oControlDef As ControlDefinition
oControlDef = oCommandMgr.ControlDefinitions.Item("AssemblyBonusTools_SaveAndReplaceComponentCmd")


Dim oDoc As Inventor.AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oSS As SelectSet
oSS = oDoc.SelectSet

Dim oAsmCompDef As InventorAssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oCompDef As Inventor.ComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oOcc As ComponentOccurrence
oOcc = oAsmCompDef.ComponentOccurrence

For Each oOcc In oAsmCompDef
If ThisDoc.Document.BOMStructure = BOMStructureEnum.kNormalBOMStructure
	
		oSS.Clear
       oSS.Select(oOcc)
       oControlDef.Execute

	
	End If
	Next

 

0 Likes
Accepted solutions (1)
774 Views
5 Replies
Replies (5)
Message 2 of 6

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, try to execute the following ilogic rule from your assembly.

 

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

For Each oOcc As ComponentOccurrence In oCD.Occurrences
	If oOcc.Definition.BOMStructure = BOMStructureEnum.kNormalBOMStructure Then
	Dim refDoc As Document = oOcc.Definition.Document
	refDoc.Save
	End If
Next

 Note, this rule will read the structure of the file from the file properties, not from the bill of materials in the assembly file. To be clearer, a part may be to have a normal structure, but to be as a reference component in the assembly, this rule will then read the normal structure.

 

I hope this helps with your problem. 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 3 of 6

Anonymous
Not applicable

Thanks for your reaction!

 

This code just saves the parts with the BOM-structure tho. I need to Save and Replace the parts because I need to generate a INV-number and give the parts different dimensions.

0 Likes
Message 4 of 6

Anonymous
Not applicable

I'm still not quite sure how to continue on this. Hopefully you can give me another tip.

0 Likes
Message 5 of 6

Sergio.D.Suárez
Mentor
Mentor

Excuse me, I don't understand your question well.
Could you explain a little more? To see if we can help you. 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 6 of 6

Anonymous
Not applicable

Started today with my mind fresh again and I got it to work on first try. My gratitude!

 

For people interested:

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oACD As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
For Each oOcc  In oACD.Occurrences
	If oOcc.Definition.BOMStructure = BOMStructureEnum.kNormalBOMStructure Then
		
		Dim oSS As SelectSet
oSS = oDoc.SelectSet

Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager

Dim oControlDef As ControlDefinition
oControlDef = oCommandMgr.ControlDefinitions.Item("AssemblyBonusTools_SaveAndReplaceComponentCmd") 

oSS.Clear
        oSS.Select(oOcc)
        oControlDef.Execute
    End If
Next

My next problem is that there pop's up a message saying it's unable to properly terminate selection. I'm trying to save and replace all the strips( see picture). It didn't grab one from the part which is basicly the same.

0 Likes