Jump to content

how can I add "spare" parameters to an existing node


mrice

Recommended Posts

How does one add and organize parameters that arent part of a node's definition?

The only methods I can find require a "dialog script" stream, not sure how to go about that with the DS classes or if that's barking up the wrong tree.

Thanks in advance for any Guidance and hand-holding

Link to comment
Share on other sites

How does one add and organize parameters that arent part of a node's definition?

The only methods I can find require a "dialog script" stream, not sure how to go about that with the DS classes or if that's barking up the wrong tree.

Thanks in advance for any Guidance and hand-holding

If you're talking about the HDK, then there are some higher level functions in OP_Director.h (and MOT_Director.h). I hesitate to point them out though because the interface there is messy and you won't hear me talk about this again. :)

Link to comment
Share on other sites

I should have added with the HDK :lol:

If you're talking about the HDK, then there are some higher level functions in OP_Director.h (and MOT_Director.h). I hesitate to point them out though because the interface there is messy and you won't hear me talk about this again. :)

but WAIT, before you never speak of this again:

OPgetDirector()->addNodeSpareParm(op_node, &myTemplate);

does indeed create a spare parameter, but it automagically puts it in a "spare" folder (pre H9 style? before my time).

I thought maybe I could get use PI_EditScriptedParms to reorganize it into the base parm layout, but I cant get that to work. Surely there must be a better way though? How does hou.Node.addSpareParmTuple() work?

Thank you!

Link to comment
Share on other sites

The combination of using HOM to create a parameter, then OP_Director and PI_EditScriptedParms to change it as needed seems to be working great B)

One of the problems I was having was that I wasnt calling OP_Parameters::disableParmsAndSpareParms() before using OP_Director.

Link to comment
Share on other sites

That's odd. Which function in OP_Director were you using? As far as I can tell, disableParmsAndSpareParms() seems like it's already being called at end of addNodeSpareParm(), as well as from HOM_Node::addSpareParmTuple().

You're right, If I create a parm through HOM_Node then no need for disableParmsAndSpareParms(). But if I use OP_Director::changeNodeSpareParms() to modify a spare parm created via python in the scene, the node's "parameter mixing layout" gets trashed without disableParmsAndSpareParms(). It would be nice if there was some information on how the parameter layout works, but I guess that's where "with lots of complicated code" comes into play? OK count me out.

Anyways, my revelation of the week is how nice the interface between python and the HDK is, very powerful stuff. Several things that have been tripping me up with the HOM are history!

Link to comment
Share on other sites

From my end of things it looks like everything is implemented on top of changeNodeSpareParms() which itself is implemented on top of changeSpareParms(). changeSpareParms() is actually where the real work takes place and that calls disableParmsAndSpareParms() at the end. But oh well, it doesn't really hurt to call it again. :)

Link to comment
Share on other sites

  • 2 weeks later...

Well I've run into one more problem with this.

I need a function that will destroy a given spare parameter and its containing group.

extract:

PI_EditScriptedParms spareParms = PI_EditScriptedParms(op_node, 1, 0);

int parmIdx = spareParms.getParmIndexWithName(parmName);
int groupStartIdx = spareParms.getParentGroupParm(parmIdx);
int groupEndIdx = spareParms.getMatchingGroupParm(groupStartIdx);

spareParms.removeParms(groupStartIdx, groupEndIdx-1);
mot->changeNodeSpareParms(op_node, spareParms, errors);

In general it works, but Houdini will crash when the parameter folder is on the boundry of a tab group. It might crash if its the first tab or else the last tab, one or the other, but the behavior is consistent. What's really strange to me is that just deleting the parameters and not the folders causes the same thing to happen.

A stack trace says that the crash is happening on PRM_Parm::setMostRecentCallbackValue(). Any idea when that gets called and what might be going wrong?

Link to comment
Share on other sites

Try removing the -1 part from "groupEndIdx-1".

Tried that, as well as anything else I could think of. The reason I have groupEndIdx-1 is because in the header it says that a group parm's opposite end will be automatically removed, so I thought that could be causing a problem. But what's strange is that even if I remove groupStartIdx+1, groupEndIdx-2 it still crashes, so it would seem this is not related to the switcher structure? But it only happens if the folder is on a tab group boundry :(

Link to comment
Share on other sites

Maybe you could try calling dump() or save() and look to see if anything in the internal structure looks wrong.

That's what I did. The ds stream is definitely getting messed up before Houdini crashes, but I really don't see why.

It didn't take long though while looking at the output to realize that the key to all this dynamic ui stuff was staring right at me:

1. get ds stream in python via C API

2. add,remove,modify,shuffle with python's Text Processing Power

3. send ds script back to the HDK and replace

4. drink beverage of choice while thinking about all the fun stuff this can be used for

So far this works great :D

Link to comment
Share on other sites

With lots of complicated code. If you can't use the simple interface in OP_Director, then I recommend you just do it by calling HOM from C++. There's a small example on how to call HOM from C++ in the HDK under HOM/SOP_HOMWave.C

Anyway. Can anybody share sample, how to create parameters on existing node using only C++, as hou.Node.addSpareParmTuple() does?

Edited by mitya
Link to comment
Share on other sites

Anyway. Can anybody share sample, how to create parameters on existing node using only C++, as hou.Node.addSpareParmTuple() does?

A bit simplified and probably dangerous:

void
SomeKindOfNode::addSpareParm(const PRM_Template *spareParmTemplate, const char *folderName)
{
	UT_String 		errors;
	OP_Director  		*director = OPgetDirector();
	PI_EditScriptedParms	nodeParms(this, 1, 0);

	const PI_EditScriptedParms 	spareParms(this, spareParmTemplate, 1, 0, 0);
	nodeParms.mergeParms(spareParms);

	if (folderName) {
		int folderIdx = nodeParms.getParmIndexWithName(folderName);
		if (folderIdx) {
			int folderEndIdx = nodeParms.getMatchingGroupParm(folderIdx);
			int myParmIdx = nodeParms.getNParms() - 1;
			nodeParms.moveParms(myParmIdx, myParmIdx, folderEndIdx - myParmIdx);
		}
	}

	director->changeNodeSpareParms(this, nodeParms, errors);
}

Or use HOM_Node::addSpareParmTuple() in the HDK as Edward says above.

Or get the ds stream, for example by passing an ostringstream object into PI_EditScriptedParms::save(), parse it, and you can really mess things up :)

Link to comment
Share on other sites

  • 3 weeks later...

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