Jump to content

Execute string in Python ?


vrman

Recommended Posts

Hey guys

is there any way to execute string in python ? its my string variable :

"hou.parm('/obj/test3_FBX/materials/Google_Hybrid___7/Google_Hybrid___7_surface/map1')"

i want to use it to set a parameter , but problem is its a string.

im also tried to change it like this :

myPath = '/obj/test3_FBX/materials/Google_Hybrid___7/Google_Hybrid___7_surface/map1'
hou.parm(myPath)

in 3dsmax maxscript you can using a execute syntax before string to do it. is there a similar way in python for that ?

Edited by vrman
Link to comment
Share on other sites

37 minutes ago, davpe said:

i think you need to type something like this:

hou.node('your_node').parm('parm_name').set('string_you_want')

so you first need pointer to a node, then point to a parameter you want to modify and then set a value.

cheers, D.

the problem is , i want to to execute that to get texture path and then use that path to set something

myPath = '/obj/test3_FBX/materials/Google_Hybrid___7/Google_Hybrid___7_surface/map1'
hou.parm(myPath)

here is the full code :

myNodes = hou.selectedNodes()
mySize = len(myNodes)
for i in range(mySize):
    myNode = '/obj/geo1/'+myNodes[i-1].name()
    myShop = (myNodes[i-1].geometry().primAttribs()[0]).name()
    myShopATT = myNodes[i-1].geometry().primStringAttribValues(myShop)[0]
    
    myPath = 'hou.parm('+'"'+myShopATT+'/'+myShopATT.replace('/obj/test3_FBX/materials/','')+'/map1")'
    print myPath    
    hou.node(myNode).parm('Texture').set(myPath)

i want to execute myPath before use it to set Texture parm.

its return this now :

ret1.jpg.6fb50e5396f0b30aba2f2839fc1181dc.jpg

but it should be like this :

ret2.jpg.9f4e954ef91ddaa2ea5e375923ee71c1.jpg

Edited by vrman
Link to comment
Share on other sites

i think these lines

myShop = (myNodes[i-1].geometry().primAttribs()[0]).name()
myShopATT = myNodes[i-1].geometry().primStringAttribValues(myShop)[0]

don't make sense. what exactly are you trying to achieve?

also, you're missing #import hou

 

Edited by davpe
Link to comment
Share on other sites

2 minutes ago, davpe said:

i think these lines


myShop = (myNodes[i-1].geometry().primAttribs()[0]).name()
myShopATT = myNodes[i-1].geometry().primStringAttribValues(myShop)[0]

don't make sense. what exactly are you trying to achieve?

also, you're missing #import hou

 

i have 20 group prim , and there is 20 material for them , i want to get texture disk path from each material , and use it to set something .

its shelf tool , dont need import hou

Link to comment
Share on other sites

well... I'm no python expert but I would approach it this way:

mat = hou.node('mat').children()
geo = hou.node('obj/box_object1/material1').geometry()
attrib = geo.primStringAttribValues('str')
counter = -1
for i in mat:
    counter += 1
    value = attrib[counter]
    i.parm('basecolor_texture').set('C:/'+str(value)+'.exr')

it takes string prim attribute (possibly based on group names) and returns a tuple with all the attribute values. then in loop you can insert values into texture paths on materials (or anywhere). not sure if that is exactly what you're after thou... :)

Link to comment
Share on other sites

Try this:

hou.parm('/obj/test3_FBX/materials/Google_Hybrid___7/Google_Hybrid___7_surface/map1').eval()

 

There are many ways to get and set parms in HOM. Here is some of them:

>>> hou.evalParm('/mat/principledshader1/basecolor_texture')
'C:/PROGRA~1/SIDEEF~1/HOUDIN~1.705/houdini/pic/texture/rocks001_basecolor.rat'

>>> hou.parm('/mat/principledshader1/basecolor_texture').set('C:/some/path/to/file.jpg')
>>> hou.evalParm('/mat/principledshader1/basecolor_texture')
'C:/some/path/to/file.jpg'

>>> p = hou.parm('/mat/principledshader1/basecolor_texture')
>>> p.eval()
'C:/some/path/to/file.jpg'
>>> p.set('C:/some/other/path.exr')
>>> p.eval()
'C:/some/other/path.exr'

>>> node = hou.node('/mat/principledshader1')
>>> p = node.parm('basecolor_texture')
>>> p.eval()
'C:/some/other/path.exr'
>>> p.set('Mandril.pic')
>>> p.eval()
'Mandril.pic'

 

Link to comment
Share on other sites

1 hour ago, f1480187 said:

Try this:


hou.parm('/obj/test3_FBX/materials/Google_Hybrid___7/Google_Hybrid___7_surface/map1').eval()

 

There are many ways to get and set parms in HOM. Here is some of them:


>>> hou.evalParm('/mat/principledshader1/basecolor_texture')
'C:/PROGRA~1/SIDEEF~1/HOUDIN~1.705/houdini/pic/texture/rocks001_basecolor.rat'

>>> hou.parm('/mat/principledshader1/basecolor_texture').set('C:/some/path/to/file.jpg')
>>> hou.evalParm('/mat/principledshader1/basecolor_texture')
'C:/some/path/to/file.jpg'

>>> p = hou.parm('/mat/principledshader1/basecolor_texture')
>>> p.eval()
'C:/some/path/to/file.jpg'
>>> p.set('C:/some/other/path.exr')
>>> p.eval()
'C:/some/other/path.exr'

>>> node = hou.node('/mat/principledshader1')
>>> p = node.parm('basecolor_texture')
>>> p.eval()
'C:/some/other/path.exr'
>>> p.set('Mandril.pic')
>>> p.eval()
'Mandril.pic'

 

not working in my case , i got this "AttributeError: 'NoneType' object has no attribute 'eval'" error after running this :

    myPath = "'"+myShopATT+'/'+myShopATT.replace('/obj/test3_FBX/materials/','')+"_surface"+'/map1'+"'"
    hou.parm(myPath).eval()

 

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...