ILOGIC RULE TO SET ALL OCCURRENCES BOM TO REFERENCE IN WELDMENT

ILOGIC RULE TO SET ALL OCCURRENCES BOM TO REFERENCE IN WELDMENT

OTHOCLOUD
Participant Participant
2,228 Views
7 Replies
Message 1 of 8

ILOGIC RULE TO SET ALL OCCURRENCES BOM TO REFERENCE IN WELDMENT

OTHOCLOUD
Participant
Participant

I have a Weldment that I want to change the BOM Structure from default to Reference on all occurrences in the assembly tree. 

 

Here is the code that I have that works on an Assembly File but does not work on a Weldment Assembly File. 

 

' set a reference to the assembly component definintion
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
oOccurrence.BOMStructure = BOMStructureEnum.kReferenceBOMStructure

Next

If I run this on a Weldment File I get this error

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

If I take it a step further and single out just the Parts in the Tree it runs fine, but if I single out just the assemblies in the tree the same error comes up.  

 

I'm wanting to turn all of the parts and assemblies in the tree to Reference.  Thank You for any help.

0 Likes
Accepted solutions (1)
2,229 Views
7 Replies
Replies (7)
Message 2 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @OTHOCLOUD 

 

From memory the issue is that the weld beads are "seen" as occurrences also, but have no BOM structure property, there fore we get an error.

 

You might search the Inventor Customization forum for something on this as a solution (that's the better forum for programming questions):
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

But I'll try to find an example based on something I have on hand and post back as well.

 

Edit: It occurred to me right after I posted that I just used the occurrence name to filter out welds in the past, see the example below.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

' set a reference to the assembly component definintion
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
	If  Not oOccurrence.Name.Contains("_Weld")
		oOccurrence.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	End If

Next


 

EESignature

0 Likes
Message 3 of 8

OTHOCLOUD
Participant
Participant

I tried your code there but still come up with the same Error.

 

I have also manually changed the BOM Structure to reference on the assembly parts then changed the code to change them to back to default using the code below.  It works without issue,  but for some reason it will change them from reference to default.  But will error out when changing them from default to reference.

 

' set a reference to the assembly component definintion
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
		oOccurrence.BOMStructure = 51969  'Default 

Next
0 Likes
Message 4 of 8

Curtis_Waguespack
Consultant
Consultant

@OTHOCLOUD wrote:

 

If I take it a step further and single out just the Parts in the Tree it runs fine, but if I single out just the assemblies in the tree the same error comes up.  

 


Hi @OTHOCLOUD , 

 

Hmmmm, I missed this part previously... but I'm stumped... in testing your code from the first post, it works for me on a weldment assembly with parts and subassemblies . I don't see any errors, and can change the occurrences from normal to reference or the other way around.

 

Can you try the code on another assembly? Also, if you restart Inventor and try it does it work?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 5 of 8

OTHOCLOUD
Participant
Participant

I tried restarting Inventor and still have the error.  I even created a new Assembly with parts and subassemblies and ran the rule on it.  It works.  but after I convert that assembly over to a Weldment and run the rule, it comes up with the error.  I have tried it on different Computers, with the same result. 

 

We are using

Autodesk Inventor Professional 2018

Build: 284, Release: 2018.3.5

 

have also tried it on Inventor 2017 and have the same error.

 

Starting to wonder if it is an issue with NET Framework

0 Likes
Message 6 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @OTHOCLOUD 

 

The restart suggestion was just to clear the memory, sometimes when working with ilogic an error seems to get something "stuck" in memory and it makes it seem as if the code has an error ever though we've fixed, etc.

 

I am using Inventor 2020 to test, but I see it working on a weldment? can you create a weldment assembly with a simple part in it, maybe just place that part in the assembly 3 times, etc. and then post it here, for others to test with?

 

Other than that I don't have any other guesses.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 7 of 8

JelteDeJong
Mentor
Mentor
Accepted solution

@Curtis_Waguespackwas correct in thinking that "the issue is that the weld beads are "seen" as occurrences" there for when you loop over all occurences you need to test if the occurence is a weld. Try this iLogic rule.

Dim doc As AssemblyDocument = ThisDoc.Document

For Each occ As ComponentOccurrence In doc.ComponentDefinition.Occurrences
    If (occ.Definition.Type = ObjectTypeEnum.kWeldsComponentDefinitionObject) Then
        Continue For
    End If

    occ.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
Next

I also want to note that you change the BOMStructure of the occurrences here and not of the parts. I dont know if that is what you realy want.

Also if you have a sub-assembly in your weldment then the parts of the sub-assembly will not be changed.

 

Jelte de Jong
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.

EESignature


Blog: hjalte.nl - github.com

Message 8 of 8

Darkforce_the_ilogic_guy
Advisor
Advisor

maybe you can just use this code

 

' set a reference to the assembly component definintion

Dim doc = ThisDoc.Document
	Dim sDocumentSubType As String = doc.SubType
	

'Undersøger Document type"
	
	If sDocumentSubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then	' = "Sheet Metal"
		
	End  If
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
Try
oOccurrence.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
Catch
	
End Try
Next
0 Likes