Inventor Engineer-To-Order (Read-Only)
Welcome to Autodesk’s Inventor ETO Forums. Share your knowledge, ask questions, and explore popular Inventor ETO topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 7
CodeMonkey831
395 Views, 6 Replies

Event

I am not sure if I am using events properly and could use some advice.

 

I have a design, that when added, user can select another part (of the same design).  This is stored in the parameter "AttachTo".  I wish to use the event to modify the "Available" rule of the part the user selected.

 

Workflow example:

 

User dynamically adds "Module_1", no value for "AttachTo" parameter.

User dynamically adds "Module_2", selects "Module_1" as value for "AttachTo"

Rule "Available?" of part "Module_1" is set to "False"

 

The last part just isn't happening, and because all errors are swalloed in events, I have no idea where this is incorrect.

 

Design Module : TestProject BasePart

Parameter Rule AttachTo As Part = NoValue

Rule Available? As String = "True"

Method postCreateSelf() As List
	Dim result As List
	If AttachTo = NoValue Then
		result = {}
	Else
		result = {{:action, :createDynamicRule, _
			   :Part, AttachTo, _
			   :Name, :Available?, _
			   :formula, "False"} _
			 }
	End If
	Return result

End Method

 

6 REPLIES 6
Message 2 of 7
Jon.Balgley
in reply to: CodeMonkey831

A quick guess -- mismatch between the datatype of Available? and the formula you are providing.  Try either making "Available?" into a boolean parameter, or adding an "extra" set of double quotes in the :formula.

 

Worth a shot...


Jon Balgley
Message 3 of 7
CodeMonkey831
in reply to: Jon.Balgley

Changing the data type does not work either.  The documentation states that formula must be converted to a string, regardless of datatype, which is why I tried to use strings initially.

 

"The formula must be a string, even if it's a simple constant such as a number."

http://wikihelp.autodesk.com/Inventor_ETO/enu/2012/Help/0000-Inventor0/0113-Language113/0217-Events2...

 

 

Here is what I tried, without success

 

Design Module : TestProject BasePart

Parameter Rule AttachTo As Part = NoValue

Rule Available? As Boolean = True

Method postCreateSelf() As List
	Dim result As List
	If AttachTo = NoValue Then
		result = {}
	Else
		result = {{:action, :createDynamicRule, _
			   :Part, AttachTo, _
			   :Name, :Available?, _
			   :formula, stringValue(False)} _
			 }
	End If
	Return result

End Method

 

Message 4 of 7
Jon.Balgley
in reply to: CodeMonkey831

Well, my environment here is broken at the moment, so in the interest of getting you a fast answer, let me give another answer that is untested:

 

I am guessing you are testing these rules using the regular development environment, not in your own app yet.  When you do "Add Child", Intent creates the child rule at that time -- with NO parameters supplied.  And so, your postCreateSelf rule gets run at that time, and since there is no 'attachTo', it returns the empty action list and does nothing.  Then, a moment later, Intent prompts you for the parameters, and you specify the attachTo at that time.  Then when you press OK, Intent does individual overrides on the individual parameters, so no additional pre/postCreateSelf events are triggered.

 

In your real app, you will probably prompt for the the 'attachTo' before creating the new child, and then supply the attachTo in the parameter list of the Child rule, hence it will work differently.

 

There's nothing wrong with doing it either way.

 

BTW, one good technique for testing event-handlers is to simply call them from the Immediate pane.  This wouldn't have found this problem, but at least it would have confirmed that your event-handler had no obvious errors.


Jon Balgley
Message 5 of 7
CodeMonkey831
in reply to: Jon.Balgley

Thank you.  I see the behavior of dynamic children.  But even taking out the condition, createDynamicRule is not firing (or incorrectly firing).  I get the additional dynamic child, but not the rule with this code:

 

Method preCreateSelf() As List
	Dim result As List = {}
'	If (AttachTo = NoValue) Then
'		result = {}
'	Else
		result = {{:action, :createDynamicPart, :Part, Parent, :Name, MakeName("TESTME"), :Design, "Facility"} , _
				  {:action, :createDynamicRule, :Part, AttachTo, :Name, :Available?, :formula, stringValue(False)}}
'	End If
	preCreateSelf = result
End Method

 

Message 6 of 7
Jon.Balgley
in reply to: CodeMonkey831

At the time the preCreateSelf rule is evaluated, attachTo is NoValue.  So the action isn't valid.  Try adding the non-child rule to the parent.

 

...or try using an attachTo_postModify event-handler.


Jon Balgley
Message 7 of 7
CodeMonkey831
in reply to: Jon.Balgley

You were right; AttachTo was set to NoValue.  I (temporarily) used nth(1, Parent.Children) and it worked as intended.  Thanks so much for helping clarify.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report