Ilogic rule reset all BOM structure to Normal

Ilogic rule reset all BOM structure to Normal

morrenengineering
Contributor Contributor
861 Views
6 Replies
Message 1 of 7

Ilogic rule reset all BOM structure to Normal

morrenengineering
Contributor
Contributor

hi, I am working with Inventor Pro 2021. I want to make different part lists with different levels. 

 

1. Rule1 - reset all parts and assembly 's in the main assembly to "normal"

2. Rule2 - set all sub assembly' s with containing a L (netherlands for the first letter of Lassen (welding)) to Inseperatable.

 

Maybe it could be a short code. 

0 Likes
Accepted solutions (1)
862 Views
6 Replies
Replies (6)
Message 2 of 7

bhavik4244
Collaborator
Collaborator

@morrenengineering 

 

This could help you.

 

For normal BOM:

'Rule:1

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences

'set BOM Structure to Normal
Try

oOccurrence.BOMStructure = BOMStructureEnum.kNormalBOMStructure

Catch
End Try

 

For Inseperable BOM:

 

'Rule:2

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
	
'set BOM Structure as Inseparable
Try
	
oOccurrence.BOMStructure = BOMStructureEnum.kInseparableBOMStructure

Catch
End Try

 


Bhavik Suthar
0 Likes
Message 3 of 7

morrenengineering
Contributor
Contributor

@bhavik4244 

 

I tried, but it gave a compile error, line 6, For must end with an Next instruction.

 

Excuses that I am not a real programmer.

0 Likes
Message 4 of 7

bhavik4244
Collaborator
Collaborator

@morrenengineering 

 

you're right just place "Next" at the end of the rule, I missed it while copying from my system 🙂


Bhavik Suthar
0 Likes
Message 5 of 7

morrenengineering
Contributor
Contributor

@bhavik4244 

 

The rules changed nothing so far as I can see. the intention was to check all compositions in the entire tree and set them all to "Normal". The rule does not return an error message, but it seems that it does not go all the way down the entire tree.

 

I have another ilogic rule that makes a STP file out of the whole tree. I want to do that at the same way, each IAM setting the BOM structure to "Normal"

0 Likes
Message 6 of 7

morrenengineering
Contributor
Contributor
Accepted solution

The first rule now is running perfectl

 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = ThisDoc.FileName(False) 'without extension


Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments    
Dim oRefDoc As Document
'work the referenced models
For Each oRefDoc In oRefDocs
	Dim oCurFile As Document
	
	oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)       
    oCurFileName = oCurFile.FullFileName 
   
    'defines backslash As the subdirectory separator
    Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
   

    	Try  
		    		
			oCurFile.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure			
	
    	Catch
        			
    	End Try
	oCurFile.Close
	
	Next
0 Likes
Message 7 of 7

morrenengineering
Contributor
Contributor

The second rule for "inseperatable" when a filename containt "L" is nog working yet. Can anyone help me. The code i have now stands below. The problem is

 

If oCurFile.Name.Contains("L") Then

The complete file 

 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = ThisDoc.FileName(False) 'without extension


Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments    
Dim oRefDoc As Document
'work the referenced models
For Each oRefDoc In oRefDocs
	Dim oCurFile As Document
	
	oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)       
    oCurFileName = oCurFile.FullFileName 
   
    'defines backslash As the subdirectory separator
    Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
   

    	Try  
			
			
		    If oCurFile.Name.Contains("L") Then
			
			oCurFile.ComponentDefinition.BOMStructure = BOMStructureEnum.kInseparableBOMStructure			
		
		End If
		
    	Catch
        	'MessageBox.Show("Error processing " & oCurFileName, "ilogic")
		
    	End Try
	oCurFile.Close
	
	Next

 

0 Likes