[Sidefx-houdini-list] problem using hom setExpression from callback script

Daniel Flood daniel.flood at drdstudios.com
Sun Sep 11 20:58:16 EDT 2011


I thought backticks weren't compatible with the python setExpression method,
I gave it a try and it didn't work, it's not the same as typing it into the
parm I think.

The sample code I gave works in terms of the expression evaluating the parm
correctly - it just throws up a "red node" error.  But not if ran from the
python shell.

Re string literals, I've tried all of the following, all produce the error:

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

note that using if instead of ifs, with integers, does work:
hou.node("/obj/null1").parm('camera').setExpression('if(1==1,1,2)',
hou.exprLanguage.Hscript)

the example from the Houdini docs is:

ifs ($F<12, padzero(4, $F), "0075")





2011/9/12 François Duchesneau <sidefx at trinix.ca>

> I tried the following expression directly in a string parameter and it
> doesn't work for me.
>
>
> ifs(strcmp('foo','foo')==0,'**true','false')
>
> You need to include into backticks to make it work.
>
> François
>
>
> Daniel Flood wrote:
>
>> Hey François,
>>
>>
>> Both examples were used on the same parameter, which is a string.
>>  Entering
>> the expression into the parm (and also running it from the callback) does
>> result in correct evaluation, however there is a silent "red node" error
>> revealed on middle mouse click.
>>
>> I tried running this instead:
>>
>> hou.node("/obj/null1").parm("**parm").setExpression("ifs(**
>> strcmp('foo','foo')==0,'true',**'false')",
>> hou.exprLanguage.Python)
>>
>> And then the expression doesn't evaluate, i'm not sure this is correct as
>> the expression being set is in hscript and not python.  Not sure how to do
>> the if statement as a one liner for a python expression.
>>
>> cheers,
>> Dan
>>
>>
>>
>> 2011/9/11 François Duchesneau <sidefx at trinix.ca>
>>
>>
>>
>>> Just throwing ideas here. Do you mean when you type
>>>
>>>
>>> ifs(strcmp('foo','foo')==0,'****true','false')
>>>
>>> directly in your parameter it works?
>>>
>>> Also when you say that when you use
>>>
>>>
>>> hou.node("/obj/null1").parm("****parm").setExpression("if(**
>>> strcmp('foo','foo')==0,1,2)",
>>> hou.exprLanguage.Hscript)
>>>
>>> it works, are you setting this expression in the same parameter as the
>>> ifs
>>> version that doesn't work? If yes, then it makes sense you've got an
>>> error
>>> if you're trying to set a string inside a float parameter for example.
>>>
>>> Also, make sure that when you set the expression via Python your
>>> parameter
>>> is actually evaluating a Python expression and not an Hscript.
>>>
>>> Hope this help.
>>>
>>> François
>>>
>>> François
>>>
>>> Daniel Flood wrote:
>>>
>>>
>>>
>>>> Hey folks,
>>>>
>>>> I'm setting an expression via hou.node().parm().****setExpression(),
>>>> and I
>>>> have
>>>> a problem where the parameter expression evaluates 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.co...****expressions/ifs
>>>>
>>>> cheers,
>>>> Dan
>>>> ______________________________****_________________
>>>> Sidefx-houdini-list mailing list
>>>> Sidefx-houdini-list at sidefx.com
>>>> https://lists.sidefx.com:443/****mailman/listinfo/sidefx-****
>>>> houdini-list<https://lists.sidefx.com:443/**mailman/listinfo/sidefx-**houdini-list>
>>>> <https://lists.**sidefx.com:443/mailman/**listinfo/sidefx-houdini-list<https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list>
>>>> >
>>>>
>>>>
>>>>
>>>>
>>>>
>>> ______________________________****_________________
>>> Sidefx-houdini-list mailing list
>>> Sidefx-houdini-list at sidefx.com
>>> https://lists.sidefx.com:443/****mailman/listinfo/sidefx-****
>>> houdini-list<https://lists.sidefx.com:443/**mailman/listinfo/sidefx-**houdini-list>
>>> <https://lists.**sidefx.com:443/mailman/**listinfo/sidefx-houdini-list<https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list>
>>> >
>>>
>>>
>>>
>> ______________________________**_________________
>> Sidefx-houdini-list mailing list
>> Sidefx-houdini-list at sidefx.com
>> https://lists.sidefx.com:443/**mailman/listinfo/sidefx-**houdini-list<https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list>
>>
>>
>>
> ______________________________**_________________
> Sidefx-houdini-list mailing list
> Sidefx-houdini-list at sidefx.com
> https://lists.sidefx.com:443/**mailman/listinfo/sidefx-**houdini-list<https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list>
>



More information about the Sidefx-houdini-list mailing list