can i use a python expression to alter node params in a dop?

   1558   2   1
User Avatar
Member
48 posts
Joined: Dec. 2015
Offline
Hi there

If I'm bringing in a particle field into a ParticleFluidObject and initializing the fluid values, am i able to use python expressions to set parameter values based on another value in the geometry?

thanks
Nigel.
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
I'm pretty sure you can.

I'm still somewhat of a newbie and haven't worked with DOPs, but for my projects I have used Python for working with different parameters, combining them and/or running them through/into functions to be used elsewhere.

When I use Python directly in the expression edit boxes of a parameter I'm referring to other parameters with the syntax like follows:

node_type = hou.nodeType(hou.objNodeTypeCategory(), “vc_control_tx”)
return node_type.hdaModule().PHI_Divide_Bracket( ch(“range_position_txx”),
ch(“range_position_txy”),
ch(“increments_position_tx”),
ch(“index_position_tx”),
ch(“add_subtract_position_tx”),
ch(“result_is_positive_position_tx”) )

The first two lines are basically one way to refer to the function “PHI_Divide_Bracket” I have in my PythonModule section of the digital asset this example is taken from.

The same function if it was simply in my Python Source Editor would simply eliminate the first two lines to

hou.session.PHI_Divide_Bracket (……

But probably the important distinction here are the arguments like…

ch(“range_position_txx”)

which is referring to a parameter.

However if I create a PythonScript Node and put my code there I would refer to parameters in a slightly different way:

******************

node = hou.pwd()

import math
import time

New_Angle = hou.parm('/obj/geo1/transform1/rz')

Govenor = 4.0

if hou.frame() == 1:
hou.session.STime = hou.time()
hou.session.ETime = 0.0
hou.session.TMarker_A = 0.0
hou.session.Angle_A = 0.0
hou.session.resetrz()


if (hou.frame() < 120) and (hou.frame() > 1):
hou.session.ETime = hou.time() - hou.session.STime
New_Angle.set( (math.sin(hou.session.ETime/Govenor)) * 90)

if hou.frame() == 120:
hou.session.Angle_A = New_Angle.eval()
hou.session.STime = hou.time()

if (hou.frame() < 240) and (hou.frame() > 120):
hou.session.ETime = hou.time() - hou.session.STime
New_Angle.set( ( -(math.sin(hou.session.ETime/Govenor)) * 90) + (hou.session.Angle_A) )

***********************

In this second example I'm only using working with one parameter yet works in conjunction with the following I have in my Python Source Editor:

STime = 0.0
ETime = 0.0
TMarker_A = 0.0
Angle_A = 0.0

RZ = hou.parm('/obj/geo1/transform1/rz')

def resetrz():
RZ.set(0)

**********************

So basically you work with and alter different parameters however you want it just matters how you refer to those parameters depending on the context.

In the first example I refer to a parameter like - ch(“obj/theparam/specific_apsect”)

and in the second example I refer to that paramater and assign it to a name to work with it - My_named_parameter = hou.parm('obj/theparam/specific_apsect')

Hope this gives you a bit of info that is useful.
User Avatar
Member
48 posts
Joined: Dec. 2015
Offline
Hi Babaj

Thanks very much for this, the syntax examples are great.

cheers
Nigel.
  • Quick Links