Using MScriptUtil with pointers?

Hello all!

I’m beginning my adventure into Python for Maya so I can dig into the Maya API. I am currently trying translate some API code I found on the net as a learning device. This code is:

 /// \brief	this function simply selects all nodes in the scene of the specified type
 /// \param	type	-	the maya type of the nodes to select
 ///
 void SelectItems(MFn::Type type) {

	// iterate over all nodes of the specified type
	MItDependencyNodes it(type);
	while(!it.isDone())
	{
		// get the object the iterator is referencing
		MObject obj = it.item();
		
		// select the node
		MGlobal::select( obj, MGlobal::kAddToList );
	
		// move to next item
		it.next();
	}
 }

The place where I’m getting stuck right now, is at the MItDependencyNodes call, as it requires two arguments, the second being a pointer. Can anyone tell me the proper formatting for this type of call? Also, if we are using the MScriptUtil to change it to a pointer, how are you determining which pointer to convert it to based on the documents?

Sorry if these seem like silly questions. Diving into the API docs and fully understanding them has been a slow process.

-csa

Thanks for posting this thread - I have recently begun a similar adventure (using Python to start scratching the surface of the API), and although I can’t help you here, I look forward to seeing any solutions, so I can learn too! :slight_smile:

This:

MItDependencyNodes it(type);

becomes:


try:
     it = OpenMaya.MItDependencyNodes( type )
except:
     print( 'Error creating dependency node iterator' )

In most cases, exceptions are used instead of an explicit status variable.

Since you don’t need to pass in a status variable, does that answer your MScriptUtil question?

[QUOTE=senkusha;1345]
does that answer your MScriptUtil question?[/QUOTE]

This is very helpful, yes. While we’re here, if I wanted to actually catch and print out the resulting status, MS::kSuccess or MS::kFailure, how does one do that in Python?

Maybe this matters less using API code… My MEL ways have me used to seeing what happened and testing against that command’s success and branching from there. I suppose right now, I’m looking to verify results to the script output to let me know everything is working beyond not receiving any errors.

Thanks!
-csa

While we’re here, if I wanted to actually catch and print out the resulting status, MS::kSuccess or MS::kFailure, how does one do that in Python?

The Python API makes less use of MStatus and makes more use of exception handling. You’ll notice that I wrapped the initialization of the iteration in a try block. If that call to MItDependencyNodes() were to fail, an exception would be raise and caught by the except block. This is how you can verify that everything is working how it is supposed to.