User Tools

Site Tools


Find View Tool Classname

Summary

Below is an example demonstrating how you can find the classname of a view tool using its label, via script.

API Areas of Interest

Example

View_Tool_Find_Classname.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	/*********************************************************************/
	// String : A function for finding the classname of a view tool
	function findViewToolClassName( sToolName )
	{
		// Get the viewport manager
		var oViewportMgr = MainWindow.getViewportMgr();
		// If we do not have an viewport manager
		if( !oViewportMgr ){
			// We are done...
			return "";
		}
 
		// Declare working variable
		var oTool;
		// Iterate over the tools
		for( var i = 0, nTools = oViewportMgr.getNumTools(); i < nTools; i += 1 ){
			// Get the 'current' tool
			oTool = oViewportMgr.getTool( i );
			// If the name of the tool does not match the one we are looking for
			if( oTool.name != sToolName ){
				// Next!!
				continue;
			}
			// Return the class name
			return oTool.className();
		}
 
		// Return an empty string
		return "";
	};
 
	/*********************************************************************/
	// Find the class name of the view tool
	var sClassName = findViewToolClassName( "Universal" );
	// If the view tool was not found
	if( sClassName.isEmpty() ){
		// We are done...
		return;
	}
 
	// Provide feedback
	print( sClassName );
 
// Finalize the function and invoke
})();