Jump to content

hscript question


mic

Recommended Posts

hello!

i am writing a very easy script, which copies the selected nodes N times, renames them and changes some parameters. The question is how should i query the copied nodes?

# selecting the node
set selected = `opselect("/obj")`
#copy-pasting this node once
opcp "/obj/"$selected "/obj"

but how can i get my new copy to rename it and to change the parameter? I want smth like

set copy = `run('opcp "/obj/"$selected "/obj"')`

but it's not right, $copy is empty. So, i need my copies in a variable..

Thank you!

Edited by mic
Link to comment
Share on other sites

Note that it's probably easier to do these types of tasks in Python (via HOM) instead these days.

few months ago i have the strange and unsolved problem with one scene, i had to recook many nodes each time i started it, possibly it was smth like a bug.. and i wrote a simple script-`recooker` in hscript and tried to write the same in py. but there was the 'updateui' command, which haven't yet implemented in HOM, so i thought it was better to wait until HOM would be implemented wider =))

and this script (if these few strokes are the 'script')) i'll translate to py for studying)

maybe for the very newbies these nine strokes will be useful.

# copy camera N times with left/right crop offset
set selected = `opselect("/obj")`
set N = 10
for i = 0 to `$N - 1`
	set j = `$i + 1`
	opcp /obj/$selected /obj/`$selected + _CROP_`$i
	opparm /obj/`$selected + _copy`$i cropl `$i/$N`
	opparm /obj/`$selected + _copy`$i cropr `$j/$N`
end

Link to comment
Share on other sites

For manipulating nodes, I think HOM is easier these days. For anything that HOM doesn't have implemented yet, there's hou.hscript() :)

def copySelectedCam(n):
	""" Copy the selected cameras N times with left/right crop offset """
	net = hou.node("/obj")
	selected = net.selectedChildren()[0]
	for i in xrange(0,n):
		copied = hou.copyNodesTo([selected], net)[0]
		copied.setName(selected.name() + "_CROP_" + str(i))
		copied.parm("cropl").set(float(i) / n)
		copied.parm("cropr").set(float(i + 1) / n)

Link to comment
Share on other sites

thank you very much, Edward, the only thing i'm still using 9.1.244 build and..

"hou.Node.selectedChildren method

This is not implemented yet" =))

and the last question is.. to execute python function we have python source editor and hou.session.our_function() in python shell. and in Hscript i haven't found how to execute function, only .cmd script.. so i had to write "set N = 10". That's not very convenient =)

Edited by mic
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...