Suppressing part within a nested assembly using iLogic

Suppressing part within a nested assembly using iLogic

Mario.van.der.raaf
Enthusiast Enthusiast
249 Views
1 Reply
Message 1 of 2

Suppressing part within a nested assembly using iLogic

Mario.van.der.raaf
Enthusiast
Enthusiast

I am building a parametric model and sometimes subassemlies within that model need to be changed. I do this by suppressing parts in these subassemblies. This all is done using an if statement to determine which product is wanted. My iLogic scripts then suppress certain components, turn mates on or off and set the dimensions used by the model.

 

This all is run through a iLogic script in my main assembly. I call this "run all rules". Within that rule I trigger parts of my assembly to update using the following:

iLogicVb.RunRule("xxxx.iam", "Run all rules") 'description of which subassembly or part this line refers to

This works fine for assemblies where I only change dimensions or mates. But suppressing parts gives me problems.

The problems seem to stem form the fact that a level of detail is required to save suppression states. And when I run this rule from my main assembly it may happen that the assembly is not opened in the right level of detail.

 

I have tried adding this piece of code to trigger before all other rules when the rule within the document is called:

Dim doc As AssemblyDocument = ThisDoc.Document 
Dim oLOD As LevelOfDetailRepresentation 
Dim oAsmCompDef As ComponentDefinition 
oAsmCompDef = doc.ComponentDefinition
Try
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic").Activate(True)
Catch
Dim nLOD As LevelOfDetailRepresentation
nLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
oLOD = nLOD
Finally
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic").Activate(True)
End Try

What this does is it changes the active level of detail to a level of detail called iLogic. This piece of code works when manually running the rule from the subassembly, but also gives errors when run through the main assembly.

 

Now for the fun part. When I open the subassembly and manually trigger my rule all parts get suppressed and the model works. When i run the same rule from the main assembly, I get the following errors (in order):

Mariovanderraaf_0-1667832803570.png

Mariovanderraaf_1-1667832834759.pngMariovanderraaf_2-1667832848003.png

Mariovanderraaf_3-1667832873427.png

 

000076255.iam is the subassembly where i want to change dimensions, suppress components and change mates.

First opening the part using and then running the rule as if i where to trigger it myself has also yielded no results.

What I would like to know is what happens when inventor executes this piece of code: 

iLogicVb.RunRule("000076255.iam", "Run all rules")

And how can I influence which level of detail it uses. Any help is greatly appreciated.

 

 

 

 

 

0 Likes
250 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @Mario.van.der.raaf.  Just wanted to point out that the bit of code you posted, which contains a Try...Catch block, does not appear to be in proper order.  You are apparently trying to accomplish 2 things with it: set the value of your oLOD variable, and activate that specific LOD.  But it looks like you are trying to both set the variable's value, and activate the LOD in the same line of code, which will never work.  You need to attempt to set the value of your variable on one line, then try to activate that LOD on another line.  Here is an example of a corrected version of that code:

Dim doc As AssemblyDocument = ThisDoc.Document 
Dim oAsmCompDef As ComponentDefinition = doc.ComponentDefinition
Dim oLOD As LevelOfDetailRepresentation 
Try
	'try to set value to variable, if item is found
	oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic")
Catch
	'item not found, so create it to set value to this variable
	oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
End Try
oLOD.Activate(True)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes