Below is an example demonstrating how to adjust the positions of a figure's bones based on the difference between the default shape and the current shape, via script.
// Define an anonymous function; // serves as our main loop, // limits the scope of variables (function( oNode ){ /*********************************************************************/ // String : A function for retrieving a translation if one exists function text( sText ) { // If the version of the application supports qsTr() if( typeof( qsTr ) != "undefined" ){ // Return the translated (if any) text return qsTr( sText ); } // Return the original text return sText; }; /*********************************************************************/ // Define message components var sTitle = text("Resource Error"); var sMessage = text("This script requires version 4.9.3.93 or newer."); var sOk = text("&OK"); // If the application is less than 4.9.3.93 if( App.version64 < 0x000400090003005d ){ // Inform the user MessageBox.information( sMessage, sTitle, sOk ); // We're done... return; } // Initialize var oFigure = undefined; // If we have a bone if( oNode.inherits( "DzBone" ) ){ // Get its skeleton oFigure = oNode.getSkeleton(); // If we have a figure } else if( oNode.inherits( "DzFigure" ) ){ // We have what we want oFigure = oNode; } // If we don't have a weight mapped figure if( !oFigure || !oFigure.inherits( "DzFigure" ) ){ // Define message components sTitle = text("Selection Error"); sMessage = text("This script requires a weight mapped figure to be selected."); // Inform the user MessageBox.information( sMessage, sTitle, sOk ); // We're done... return; } // Get the object var oObject = oFigure.getObject(); // If the node doesn't have an object if( !oObject ){ // Define message components sTitle = text("Selection Error Object"); sMessage = text("This script requires an object with geometry to be selected."); // Inform the user MessageBox.information( sMessage, sTitle, sOk ); // We're done... return; } // Get the current shape var oShape = oObject.getCurrentShape(); oShape = oShape.getCurrentShapeForNode( oFigure ); // If we don't have a shape if( !oShape ){ // Define message components sTitle = text("Selection Error Shape"); sMessage = text("This script requires an object with geometry to be selected."); // Inform the user MessageBox.information( sMessage, sTitle, sOk ); // We're done... return; } // Get the geometry var oGeometry = oShape.getGeometry(); // If we don't have a facet mesh if( !oGeometry || !oGeometry.inherits("DzFacetMesh") ){ // Define message components sTitle = text("Selection Error Mesh"); sMessage = text("This script requires an object with geometry to be selected."); // Inform the user MessageBox.information( sMessage, sTitle, sOk ); // We're done... return; } // Get the skin binding var oSkin = oFigure.getSkinBinding(); // If we don't have a weight mapped figure if( !oSkin || !oSkin.findSkinFromNode( oFigure ) ){ // Define message components sTitle = text("Selection Error Skin"); sMessage = text("This script requires a weight mapped figure to be selected."); // Inform the user MessageBox.information( sMessage, sTitle, sOk ); // We're done... return; } // Let the user know we're busy setBusyCursor(); // Create the rigging adjuster utility var oRigAdjuster = new DzShapeRiggingAdjuster(); // Set the figure to adjustthe rigging on oRigAdjuster.setFigure( oFigure ); // Set any facet groups to ignore oRigAdjuster.setExcludedFacetGroups( [] ); // Set any bones to exclude oRigAdjuster.setExcludedBones( [ "lowerJaw" ] ); // Adjust center points oRigAdjuster.setAdjustCenterPoints( true ); // Adjust end points oRigAdjuster.setAdjustEndPoints( true ); // Don't adjust orientations oRigAdjuster.setAdjustOrientation( false ); // Begin collecting undo-able operations UndoStack.beginHold(); // If the adjustment is successful if( oRigAdjuster.doAdjustments() ){ // Create the undo item UndoStack.accept( text("Adjust Rigging to Shape") ); // If the adjustment fails } else { // Cancel the undo item UndoStack.cancel(); } // Let the user know we're done clearBusyCursor(); // Finalize the function and invoke })( Scene.getPrimarySelection() );