Python function?

   1963   10   1
User Avatar
Member
97 posts
Joined: May 2015
Offline
Is there a function that gets the selected parameter in a node? In Python.

Attachments:
Screenshot (379)_LI.jpg (1.5 MB)

User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
hou.parm('/obj/blah_blah/null1/parameter_here').eval()

If you're using the script in the same node as the parameter, you can also this where hou.pwd() means the current node:
hou.pwd().parm('parameter_here').eval()
User Avatar
Member
97 posts
Joined: May 2015
Offline
mkps
hou.parm('/obj/blah_blah/null1/parameter_here').eval()

If you're using the script in the same node as the parameter, you can also this where hou.pwd() means the current node:
hou.pwd().parm('parameter_here').eval()

Im quite new to python.

nodefolder = hou.parmTuple('/obj/subnet1/ProceduralEletricPole_Setup/Control/folder2').eval()

So this gets the number of parameters it gets from Parameter folder2(its a multiparm block). How do i get the name or value of each parameter in the parmTuple.
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
Ah, I missed the multiparm block part. You'll have to find out what the name of that “Placement1” parameter is either looking in the parameter interface, or just drag it into a python shell. In the example below I just called it “parm_name” and each new one gets numbered (1, 2, 3, etc).

If the number of parameters changes, you can do something like this to loop over the number of parameters:

numParms = hou.parm('/obj/geo1/null1/folder0').eval()

for i in range(1, numParms + 1) :
    parm = "/obj/geo1/null1/parm_name" + str(i)
    
    print hou.parm(parm).eval()

Or if they're static you can just change the number on the end of the parameter:
hou.parm('/obj/geo1/null1/parm_name1').eval()
hou.parm('/obj/geo1/null1/parm_name2').eval()
hou.parm('/obj/geo1/null1/parm_name3').eval()
User Avatar
Member
97 posts
Joined: May 2015
Offline
mkps
Ah, I missed the multiparm block part. You'll have to find out what the name of that “Placement1” parameter is either looking in the parameter interface, or just drag it into a python shell. In the example below I just called it “parm_name” and each new one gets numbered (1, 2, 3, etc).

If the number of parameters changes, you can do something like this to loop over the number of parameters:

numParms = hou.parm('/obj/geo1/null1/folder0').eval()

for i in range(1, numParms + 1) :
    parm = "/obj/geo1/null1/parm_name" + str(i)
    
    print hou.parm(parm).eval()

Or if they're static you can just change the number on the end of the parameter:
hou.parm('/obj/geo1/null1/parm_name1').eval()
hou.parm('/obj/geo1/null1/parm_name2').eval()
hou.parm('/obj/geo1/null1/parm_name3').eval()

Thank you for the help. Not use to python how it reads its function or what to put in the parameter for the functions, use alot more vex to use to c++. xD
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
No worries. Did you get yours working?
User Avatar
Member
97 posts
Joined: May 2015
Offline
mkps
No worries. Did you get yours working?

node = hou.pwd()
geo = node.geometry()
geo = hou.pwd().geometry()
pts = hou.pwd().point()

numParms = hou.parm('/obj/subnet1/ProceduralEletricPole_Setup/null1/folder2').eval()


for i in range(1, numParms + 1) :
    parm = "/obj/subnet1/ProceduralEletricPole_Setup/null1/PlacementParameter" + str(i)
    value = hou.parm(parm).eval()
    
    if geo.findPointAttrib("ValuePt") == 0:   #Find if Point Attrib ValuePt exists
      geo.addAttrib(hou.attribType.Point,"ValuePt", value)
    
    else:                                   #If it does just set the value in the same attrib
      pts.setAttribValue("ValuePt", value)
      
    print value
    

Error im getting: ^^^^^
AttributeError: ‘SopNode’ object has no attribute ‘point’

node = hou.pwd()
geo = node.geometry()
geo = hou.pwd().geometry()



numParms = hou.parm('/obj/subnet1/ProceduralEletricPole_Setup/null1/folder2').eval()


for i in range(1, numParms + 1) :
    parm = "/obj/subnet1/ProceduralEletricPole_Setup/null1/PlacementParameter" + str(i)
    value = hou.parm(parm).eval()
    
    geo.addAttrib(hou.attribType.Point,"ValuePt"+ str(i), value)
    
      
    print value
    

^^^^
With this i dont get any error, but i get more Attribs made. I just want 1 attrib made and for each point give it the value. Srry im bad at python xD
Edited by Shadowjonny - Aug. 27, 2019 01:16:13

Attachments:
Screenshot (392).png (675.0 KB)

User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
Your ‘point’ error was because it should have been
pts = geo.points()

But here is your script modified a little to work:
node = hou.pwd()
geo = node.geometry()

target = "/obj/subnet1/ProceduralEletricPole_Setup/null1/"
numParms = hou.parm(target + "folder2").eval()
attrib = "ValuePt"

if geo.findPointAttrib(attrib) == None :
    geo.addAttrib(hou.attribType.Point, attrib, 0.0)

for i in range(0, numParms) : #Start at 0 because ptnums start at 0
    parm = target + "PlacementParameter" + str(i + 1) #Offset parm number by 1 cause parms start at 1
    value = hou.parm(parm).eval()
    pt = geo.point(i)
    
    pt.setAttribValue(attrib, value)

    #print value
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
I forgot to add a safety check so it won't fail if the number of points is less than the number of parameters. This one fixes that.

node = hou.pwd()
geo = node.geometry()
pts = geo.points()

target = "/obj/subnet1/ProceduralEletricPole_Setup/null1/"
numParms = hou.parm(target + "folder2").eval()
num = min(len(pts), numParms) #Check if number of points is less than number of parms
attrib = "ValuePt"

if geo.findPointAttrib(attrib) == None : #Check for attrib and add it if it doesn't exist
    geo.addAttrib(hou.attribType.Point, attrib, 0.0)

for i in range(0, num) : #Start at 0 because ptnums start at 0
    parm = target + "PlacementParameter" + str(i + 1) #Offset parm number by 1 cause parms start at 1
    value = hou.parm(parm).eval()
    pt = geo.point(i)
    
    pt.setAttribValue(attrib, value)

    #print value
User Avatar
Member
97 posts
Joined: May 2015
Offline
mkps
I forgot to add a safety check so it won't fail if the number of points is less than the number of parameters. This one fixes that.

node = hou.pwd()
geo = node.geometry()
pts = geo.points()

target = "/obj/subnet1/ProceduralEletricPole_Setup/null1/"
numParms = hou.parm(target + "folder2").eval()
num = min(len(pts), numParms) #Check if number of points is less than number of parms
attrib = "ValuePt"

if geo.findPointAttrib(attrib) == None : #Check for attrib and add it if it doesn't exist
    geo.addAttrib(hou.attribType.Point, attrib, 0.0)

for i in range(0, num) : #Start at 0 because ptnums start at 0
    parm = target + "PlacementParameter" + str(i + 1) #Offset parm number by 1 cause parms start at 1
    value = hou.parm(parm).eval()
    pt = geo.point(i)
    
    pt.setAttribValue(attrib, value)

    #print value

Thank you for the help. This is helping me understand more about python. Also is it possible to make a array attribute?
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
Looks like there's an addArrayAttrib() method instead of addAttrib()
  • Quick Links