I logic rule in sub assembly wont trigger with I properties because true false?

I logic rule in sub assembly wont trigger with I properties because true false?

t_fransman
Advocate Advocate
3,064 Views
40 Replies
Message 1 of 41

I logic rule in sub assembly wont trigger with I properties because true false?

t_fransman
Advocate
Advocate

I need an identical rule forced to run in a sub assembly when true or false is changed in the form. I have to go to the sub-assembly and run the rule it's annoying. Node is Named "BottomWeldment". Rule runs in the top level assembly but not "BottomWeldment". The rule has same name and basically does same thing, turns stuff on vis and ref or default. Just can't seem to trigger it from top level. Rule name is "Door Hand".

0 Likes
Accepted solutions (1)
3,065 Views
40 Replies
Replies (40)
Message 2 of 41

Curtis_Waguespack
Consultant
Consultant

Hi @t_fransman 

 

You should be able to do this by using something like this, where "Test" is the name of a true/false parameter in the top level assembly.

 

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

 

If Test = True Then
	iLogicVb.RunRule("Sub_assembly1:1", "Rule0")
End If

 

 

EESignature

Message 3 of 41

t_fransman
Advocate
Advocate
If LHDoorTrueRHDoorFalse = True Then
	iLogicVb.RunRule("BottomWeldment", "LHDoorTrueRHDoorFalse")
End If
If LHDoorTrueRHDoorFalse = False Then
		iLogicVb.RunRule("BottomWeldment", "LHDoorTrueRHDoorFalse")
End If

 So I tried this and I get  Error in rule Cannot find rule with name "LHDoorTrueRHDoorFalse"

Even though the rule is in there not sure why but doesn't seem to work . 

 

0 Likes
Message 4 of 41

t_fransman
Advocate
Advocate

I think it may be that my form need to be in the Top Level assembly. Because I am controlling many weldments a multi body skeleton etc. 

0 Likes
Message 5 of 41

t_fransman
Advocate
Advocate
Parameter("BottomWeldment", "LHDoorTrueRHDoorFalse") = LHDoorTrueRHDoorFalse

Also using this to make them the same.  

0 Likes
Message 6 of 41

Curtis_Waguespack
Consultant
Consultant

@t_fransman wrote:
If LHDoorTrueRHDoorFalse = True Then
	iLogicVb.RunRule("BottomWeldment", "LHDoorTrueRHDoorFalse")
End If
If LHDoorTrueRHDoorFalse = False Then
		iLogicVb.RunRule("BottomWeldment", "LHDoorTrueRHDoorFalse")
End If

 So I tried this and I get  Error in rule Cannot find rule with name "LHDoorTrueRHDoorFalse"

Even though the rule is in there not sure why but doesn't seem to work . 

 


Hi @t_fransman 

 

I don't know what the problem could be, but you can run this rule from the top level to list the rules in each component occurrence... maybe that will help you find the problem.

 

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

 

 

Dim iLogicAuto As Object
iLogicAuto = iLogicVb.Automation

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
For Each oOcc In oDoc.ComponentDefinition.Occurrences
	iDoc = oOcc.Definition.Document

	'get collection of rules
	Dim oRuleName As String
	Dim oRules As Object
	oRules = iLogicAuto.Rules(iDoc)

	oMsg = "Rules found in " & oOcc.name & vbLf

	'make sure there are rules in the file
	If Not (oRules Is Nothing) Then
		'get each rule name
		For Each oRule In oRules
			oRuleName = oRule.Name
			oMsg = oMsg & vbLf & Chr(149) & " " & oRuleName
		Next
	End If

	MsgBox(oMsg, , "iLogic")

Next

EESignature

0 Likes
Message 7 of 41

t_fransman
Advocate
Advocate

Sorry I had renamed rule and that was operator error due to exhausting all else. So no more error still wont fir rule I also have many event triggers trying to run it parameter chg etc. Just wont fir i still have to go back to the sub and run it manually so annoying. Not sure why it wont work it changes the parameter based on this 

Parameter("BottomWeldment", "LHDoorTrueRHDoorFalse") = LHDoorTrueRHDoorFalse

Parameter.UpdateAfterChange = True

But the Rule "Door Hand" wont fire even though i have this going 

 

If LHDoorTrueRHDoorFalse = True Then
	iLogicVb.RunRule("BottomWeldment", "Door Hand")
End If
If LHDoorTrueRHDoorFalse = False Then
        iLogicVb.RunRule("BottomWeldment", "Door Hand")
End If
iLogicVb.UpdateWhenDone = True
0 Likes
Message 8 of 41

t_fransman
Advocate
Advocate

this does find it btw. That is cool . Still wont trigger. Rule in Sub assy call Door Hand

 

If LHDoorTrueRHDoorFalse = True Then
	iLogicVb.RunRule("BottomWeldment", "Door Hand")
End If
If LHDoorTrueRHDoorFalse = False Then
        iLogicVb.RunRule("BottomWeldment", "Door Hand")
End If
iLogicVb.UpdateWhenDone = True

 

0 Likes
Message 9 of 41

Curtis_Waguespack
Consultant
Consultant

Hi @t_fransman 

Unless there is a compelling reason to keep it as is, I'd set the subassembly rule to fire when the parameter at the top level changes... adding the extra level of trying to change the subassembly parameter first and trigger off of it, is probably not needed.

 

But... I'll see if I can come up with something reliable with a test assembly to trigger off of the sub assembly parameter change.

 

Actually, I just tried this, and it triggered the rule in sub assembly, when the top level parameter was changed to True

 

 

Rule in the top level:

Parameter("BottomWeldment", "LHDoorTrueRHDoorFalse") = LHDoorTrueRHDoorFalse

 

and rule in the subassembly:

If LHDoorTrueRHDoorFalse = True Then
MessageBox.Show("hello world", "Title")
End if

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

EESignature

0 Likes
Message 10 of 41

t_fransman
Advocate
Advocate

I am trying to set it to trigger then it just does not work . Not sure why the rule wont trigger no matter what i try if I open the sub and fire the rule manually it works. Bit it wont fir when the true false in the sub changes to match etc. 

0 Likes
Message 11 of 41

WCrihfield
Mentor
Mentor

Is this rule you are trying to run a 'local' rule in both your main assembly, and also a 'local' rule in the target lower document?  If so, the rule(s) may be having trouble with trying to act upon the wrong target document.  It looks to me like your rule will be acting upon whichever document is 'active' at the moment it runs.  If you are running the rule in the lower document from the main assembly, the main assembly will still be the 'active' document, and therefore it will be trying to act upon the main assembly document, instead of it's 'local' document.  There are some techniques/changes you could do to help fix these types of issues.

 

If you want to keep using local rules, instead of opting for a single external rule, you can take advantage of ThisDoc.  When using that identifier, it will default to the 'local' document first (if there is one), next it will default to whichever document is 'active' when the rule started.  I created a post about document references you may be interested in.   Then, instead of using the shortcut iLogic snippets for accessing the parameters/iProperties, you could access them through the longer/natural route of digging down past the document's component definition, to its parameters, and/or its UserParameters, then using their properties/methods.  Doing it the long way ensures you are specifically working with that local document's parameters, not whatever document may be 'active' at the time.

 

And if you choose to go the external rule route, you can then use the other set of methods to run the rule (under the iLogicVb.Automation object) which allow you to specify the document object that you want the rule to target, such as

iLogicVb.Automation.RunExternalRule(oComponentDoc, oRuleName)

 But even this method of specifying the document isn't fool proof, and still depends somewhat on how you refer to any document(s) within (if any) and which methods you are using.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 41

t_fransman
Advocate
Advocate

yes both all rules are local

0 Likes
Message 13 of 41

Curtis_Waguespack
Consultant
Consultant

Hi @t_fransman 

 

Can you post the files?

 

Or create a simple test file set of one top level assembly with one subassembly file, and set up the rules and parameters as a test? 

 

If you can get it to work in a simple test set as I have, then you can compare things.

 

You might also check these setting in the rules

Curtis_W_0-1625585467833.png

 

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

 

 

 

EESignature

0 Likes
Message 14 of 41

Curtis_Waguespack
Consultant
Consultant

here are my simple test files for you to look at, they are Inv 2019 files

 

 

EESignature

0 Likes
Message 15 of 41

t_fransman
Advocate
Advocate
I added the message box, it works like a charm however I still have to manually run the rule to get the Door Hand rule to fire Ugh. So frustrated. 
If
LHDoorTrueRHDoorFalse = True Then iLogicVb.RunRule("Door Hand") MessageBox.Show("Doesn't work", "Title") End If If LHDoorTrueRHDoorFalse = False Then iLogicVb.RunRule("Door Hand") MessageBox.Show("Doesn't work", "Title") End If iLogicVb.UpdateWhenDone = True Parameter.UpdateAfterChange = True InventorVb.DocumentUpdate()
0 Likes
Message 16 of 41

WCrihfield
Mentor
Mentor

Just checking here to make sure.  The standalone (un-quoted) phrase your using 'LHDoorTrueRHDoorFalse' is the name of a Boolean type (not text type with words "True" & "False" in it) UserParameter in the top level assembly, and not just an iProperty in the top level assembly right?  And that unquoted phrase/name changes to blue (by default) in your iLogic rule editor, indicating that it is recognized as a local parameter, right?  And that same parameter, spelled exactly the same, and is also a Boolean type (not text type) is also in the component, right?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 17 of 41

t_fransman
Advocate
Advocate

tfransman_0-1625588007152.png

It is a true false not text rule. 

0 Likes
Message 18 of 41

t_fransman
Advocate
Advocate

It runs the text message but I have to go to the sub to run it manually to get it to switch a folder for the rh pieces or left hand pieces to act correctly. 

oPane1 = ThisApplication.ActiveDocument.BrowserPanes("Model")

If LHDoorTrueRHDoorFalse = True

'True
	oFolder = oPane1.TopNode.BrowserFolders.Item("LH-Door") 
	oFolderNodes = oFolder.BrowserNode.BrowserNodes 
	For Each oNode As BrowserNode In oFolderNodes 
	oComp = oNode.NativeObject
	oComp.Visible = True
	oComp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
	Next
Else	
'False	
	oFolder = oPane1.TopNode.BrowserFolders.Item("LH-Door")		  
	oFolderNodes = oFolder.BrowserNode.BrowserNodes 
	For Each oNode As BrowserNode In oFolderNodes 
	oComp = oNode.NativeObject
	oComp.Visible = False
	oComp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	Next
End If

	

If LHDoorTrueRHDoorFalse = False

'True
	oFolder = oPane1.TopNode.BrowserFolders.Item("RH-Door") 
	oFolderNodes = oFolder.BrowserNode.BrowserNodes 
	For Each oNode As BrowserNode In oFolderNodes 
	oComp = oNode.NativeObject
	oComp.Visible = True
	oComp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
	Next
Else	
'False	
	oFolder = oPane1.TopNode.BrowserFolders.Item("RH-Door")		  
	oFolderNodes = oFolder.BrowserNode.BrowserNodes 
	For Each oNode As BrowserNode In oFolderNodes 
	oComp = oNode.NativeObject
	oComp.Visible = False
	oComp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	Next
End If
0 Likes
Message 19 of 41

t_fransman
Advocate
Advocate

I just dont understand how it fires the text box but wont fire the rule itself. 

0 Likes
Message 20 of 41

Curtis_Waguespack
Consultant
Consultant

Hi @t_fransman 

 

I'd ditch the subassembly rule and move all that to the top level, unless there is a compelling reason to keep it there. 

 

here is what it would look like at the top level

 

Dim oOcc = Component.InventorComponent("BottomWeldment")
oDoc = oOcc.Definition.Document

oPane1 = oDoc.BrowserPanes("Model")
oFolder = oPane1.TopNode.BrowserFolders.Item("RH-Door")
oFolderNodes = oFolder.BrowserNode.BrowserNodes

If LHDoorTrueRHDoorFalse = False

	For Each oNode As BrowserNode In oFolderNodes
		oComp = oNode.NativeObject
		oComp.Visible = True
		oComp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
		Logger.Info("Rule fired, param is false")
	Next
Else
	For Each oNode As BrowserNode In oFolderNodes
		oComp = oNode.NativeObject
		oComp.Visible = False
		oComp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
		Logger.Info("Rule fired, param is true")
	Next
End If

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

EESignature

0 Likes