Jump to content

error when setting expression via callback script


danf

Recommended Posts

Hey folks, my first post here so hello!

I'm setting an expression via hou.node().parm().setExpression(), and I have a problem where the parameter expression does evaluate correctly, however when triggered from a callback script (either code in a shelf button, or a parm gui callback script), I the node goes red and shows the following error:

Channel Evaluation Error Bad data type for function or operation

here's my callback:

hou.node("/obj/null1").parm("parm").setExpression("ifs(strcmp('foo','foo')==0,'true','false')", hou.exprLanguage.Hscript)

This expression evaluates error free if ran from the hython shell, however if called back from a shelf button, if throws up a red node / MMB click error (note that the parm is actually being evaluated correctly)

I did notice that the following expression when set by the same method evaluates without any error:

hou.node("/obj/null1").parm("parm").setExpression("if(strcmp('foo','foo')==0,1,2)", hou.exprLanguage.Hscript)

So it seems I am not doing a good job of declaring my data types as it seems happy with integers and not strings. Could this be because strcmp returns an integer, I'm mixing up data types? If so any suggestions for how I should do it? Could this be some python parsing error, as the injected hscript expression does evaluate correctly?

So I'm at my wit's end on this...any ideas would be greatly appreciated! even the example on the sidefx docs seem to show mixing data types in an "ifs" statement: http://www.sidefx.com/docs/houdini11.0/expressions/ifs

cheers,

Dan

Link to comment
Share on other sites

So it seems I am not doing a good job of declaring my data types as it seems happy with integers and not strings. Could this be because strcmp returns an integer, I'm mixing up data types? If so any suggestions for how I should do it? Could this be some python parsing error, as the injected hscript expression does evaluate correctly?

The IF statement always takes a boolean type as the first param. So no, you're not mixing up the data types.

Houdini will display "true"/"false" for some parameters that are integer (i.e. check boxes). You need to assign them 0 or 1 in hscript anyway.

Link to comment
Share on other sites

The IF statement always takes a boolean type as the first param. So no, you're not mixing up the data types.

Houdini will display "true"/"false" for some parameters that are integer (i.e. check boxes). You need to assign them 0 or 1 in hscript anyway.

In this case I'm not looking up values of any parms, just trying to do a simple string comparison. This feels alot like a houdini bug to me - why would a given line of code evalute error-free from the hython shell, but cause silent error as a button callback? Either that or I'm dong something blatantly wrong.

I can't figure out why this is ok:

rop.parm('camera').setExpression("if(strcmp('right','right')==0,1,2)", hou.exprLanguage.Hscript)

whereas this causes an error:

rop.parm('camera').setExpression("ifs(strcmp('right','right')==0,'true','false')", hou.exprLanguage.Hscript)

any ideas?

Link to comment
Share on other sites

or an even simpler example that also causes the same error:

hou.node("/obj/null1").parm("parm").setExpression("ifs(1==1,'yes','no')", hou.exprLanguage.Hscript)

this evaluates correctly but makes the node go red with the "Channel Evaluation Error Bad data type for function or operation" error

Has anyone ever managed to use the ifs statement from a python callback script?

Edited by danf
Link to comment
Share on other sites

this evaluates correctly but makes the node go red with the "Channel Evaluation Error Bad data type for function or operation" error

It evals correctly because there are no syntax errors in the expression, it makes the node go red because your trying to assign a string value to an non-string parameter type.

I think you're confusing the error message shown in the node as an error in your expression. Let's see if I can explain it. The parameter is on the left-hand of the equation, and the expression is on the right-hand. The IF statement returns a numeric value, and the IFS returns a string value. The parameter on the left-hand side of the equation must match the data type returned by the right-hand.

How are you creating the parameter named "parm"? what type is it suppose to be?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...