UT_String path; OP_Node * base; OP_Node * node; node->getFullPath(path); // get full path of 'node' node->getRelativePathTo(base, path); // get path of 'node' relative to 'base'
Given a node path, we can find the corresponding OP_Node via the OP_Node::findNode() function.
OP_Node * node; node = OPgetDirector()->findNode("/obj/geo1"); // find via absolute path node = node->findNode("file1"); // find via relative path node = node->findNode("/obj/geo2/file1"); // OK as well
Often times, you will want obtain a specific type of the OP_Node instead. This is defined by the OP_Node::findFOONode() functions where FOO is the desired node type. If the path doesn't reference a node of the desired type, then these functions return NULL.
OBJ_Node * obj_node = OPgetDirector()->findOBJNode("/obj/geo1"); SOP_Node * sop_node = OPgetDirector()->findSOPNode("/obj/geo1/file1");
bool someFunction(OP_Context &context) { float t = context.getTime(); OP_Network * parent; OP_Node * node; OP_Node * input; // create node parent = (OP_Network *)OPgetDirector()->findNode("/obj"); node = parent->createNode("cam", "cam1"); if (!node) return false; // run creation script if (!node->runCreateScript()) return false; // set parameters node->setFloat("t", 0, t, 1.0f); // set tx to 1.0 node->setFloat("t", 1, t, 2.0f); // set ty to 2.0 node->setFloat("t", 2, t, 0.0f); // set tz to 0.0 // connect the node input = parent->findNode("null1"); // find /obj/null1 as relative path if (input) { node->setInput(0, input); // set first input to /obj/null1 } // now that done we're done connecting it, position it relative to its // inputs node->moveToGoodPosition(); return true; }
bool nodeCallback(OP_Node &node, void *data) { const char * prefix = (const char *)data; UT_String path; node.getFullPath(path); cout << prefix << ":" << path << endl; } void printChildren(OP_Node *parent, const char *prefix) { parent->traverseChildren(&nodeCallback, (void *)prefix, true); }
For certain network types (eg. OBJ_Node), it can only have one child node (eg. SOP_Node) that has its display or render flag set. To obtain the child display or render nodes use OP_Network::getDisplayNodePtr() or OP_Network::getRenderNodePtr() respectively.
OP_NodeList picked_nodes; node1->pickRequest(true); // clear node selection and then select node1 node2->pickRequest(false); // add node2 to the selection OPgetDirector()->clearPickedItems(); // just clear the selection OPgetDirector()->getPickedNodes(picked_nodes); // obtain all selected nodes // get the last selected node OP_Node *node3 = OPgetDirector()->getLastPickedNode(); // last selected child of parent OP_Node *node4 = parent->getCurrentNodePtr();
OP_BundleList * list = OPgetDirector()->getBundles();
OP_BundleList * list = OPgetDirector()->getBundles(); // create a new bundle called 'my_bundle' OP_Bundle * new_bundle = list->createBundle( "my_bundle" ); // remove the bundle we just created list->destroyBundle( "my_bundle" );
Once you obtain an OP_Bundle pointer you can modify the contents of the bundle. However, it is best to use the OP_BundleList methods for modifying a bundle because the list creates undo blocks and also sends notifications to interested parties that the bundle contents has changed. For example:
OP_BundleList * bundles; OP_Bundle * bundle; OP_NodeList nodes; // obtain the bundle named "my_bundle" bundles = OPgetDirector()->getBundles() bundle = bundles->getBundle( "my_bundle" ); // obtain the currently selected nodes OPgetDirector()->getPickedNodes( nodes ); // add or remove the nodes to or from the bundle if( add_nodes ) bundles->bundleAddOps( bundle, nodes ); else bundles->bundleRemoveOps( bundle, nodes );
OP_Bundle * bundle; OP_Network * mgr; UT_String mask( "mynode*" ); UT_String bundle_name; OP_NodeList nodes; // get a manager that contains objects mgr = OPgetDirector()->getManager( "obj" ); // get a bundle that contains nodes matching the mask pattern. The 'creator' // argument specifies the root at which tree search for nodes begins. The // 'relative_to' specifies a node with respect to which relative references in // the pattern are specified. The 'filter' names the built-in filter that // accepts or rejects the nodes; in this case the "!!OBJ!!" specifies a built-in // filter that accepts only object nodes. bundle = OPgetDirector()->getBundles()->getPattern( bundle_name, /*creator=*/ mgr, /*relative_to=*/ mgr, /*pattern=*/ mask, /*filter=*/ "!!OBJ!!"); // get the node list for processing bundle->getMembers( nodes ); // ... processing ... // release the internal bundle created by getPattern() OPgetDirector()->getBundles()->deReferenceBundle( bundle );
The following code demonstrates how to use OP_Node::getParmBundle() method.
OP_Bundle * HDK_MyOperator::getNodesToProcess( float t ) { UT_String mask; OP_Bundle * bundle; const char * parameter_name = "nodelist"; int vector_index = 0; evalParameterOrProperty( parameter_name, vector_index, t, mask ); return getParmBundle( parameter_name, // name of the parameter vector_index, // component index i // .. (for vector parameters) mask, // globbed pattern getCreator(), // root at which to look for nodes NULL); // name of an additional filter; // .. NULL means no extra filtering }
NULL. OBJ_Node * obj_node = CAST_OBJNODE(node); SOP_Node * sop_node = NULL; if (obj_node) sop_node = CAST_SOPNODE(obj_node->getChild("file1"));
1.5.9