Moving props and figures with the keyboard - using custom actions and scripts

Firstly, many thanks to everyone for the existing posts and scripts, I'd credit people directly, but for some reason I cant find the original post that pointed me to http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/ (it was something about keeping an eye on this link as it might have examples for keyboard interaction similar to the WASD changes - but I closed the window earlier by accident and now its gone).  Also thanks directly to w00tus for their answer on chris-2599934's post "My first script - feedback sought", without that I wouldnt have figured out about custom actions.

I really like using DAZ, but I find the mouse positioning tricky, I'm lucky to have a 4K monitor, but the widget to move is too small and finicky to click.  So I wanted a way to be able to move things with the keyboard.  I know I can drive around with WASD, but I cant reposition an object unless I use the widget or enter values in the Parameters window.

So I did some digging in the forums and documentation and created some very simple scripts that move items, and some custom action setup to tie them to keyboard shortcuts.

Attached is a word document with some screenshots and some text, but in summary I found you can simply create a new Custom Action under Workspace/Customize by right clicking on Custom.  You can add a script directly to the custom action that performs the object property changes and then you can Assgin a Keyboard shortcut to the custom action.

For the key you want to use, try to avoid keys you will need for other things (i.e. you can press the right arrow key, but then when you try to select items in the content view with the arrow keys it wont work)..  I used CTRL-SHIFT and the arrow keys.

I used the following script for a simple move right:

(function(){
                    var oNode = Scene.getPrimarySelection();
                    if( !oNode ){
                                        return;
                    }

                   var oProperty = 0 // 0 = Transform X, 1 = Transform Y, 2 = Transform Z
                   var oChange =  5.0
                   oNode.getProperty( oProperty ).setValue( oNode.getProperty( oProperty ).getValue() + oChange);

})();

For oChange you can set whatever you want, 0.1 is very slow and a minimal change, I used 5, but you may want more or less, or even different shortcuts for different amounts.  The property can be extended to rotate also change oProperty to 4,5,6 and I assume scale (not tested, but guessing 7,8,9).

 

Right (X++)

var oProperty = 0

var oChange =  5.0

Left (X--)

var oProperty = 0

var oChange =  -5.0

Up (Y++)

var oProperty = 1

var oChange =  5.0

Down (Y--)

var oProperty = 1

var oChange =  -5.0

Forward (Z++)

var oProperty = 2

var oChange =  5.0

Back (Z--)

var oProperty = 2

var oChange =  -5.0

 

You can also extend the script using something similar to the Geometry_Info script to allow it always select the parent even if you have a child selected (apologies for no comments, I had trouble getting this code here, so I reduced it to its minimum):

(function(){
    function getRootNode( oNode )

    {
        if( oNode && oNode.inherits( "DzBone" ) ) {
            return oNode.getSkeleton();
        }
        return oNode;
    };
    function getObjectForRootNode( oNode )
    {
        var oRootNode = getRootNode( oNode );
        if( !oRootNode ) {
            return null;
        }
        var oObject = oRootNode.getObject();
        if( !oObject ){
            return null;
        }
        return oObject;
    };

    var oNode = Scene.getPrimarySelection();
    if( !oNode ){
        return;
    }
    var oRootObject = getRootNode( oNode )
    if( !oRootObject ){
        return null;
    }

    var oProperty = 2 // 0 = Transform X, 1 = Transform Y, 2 = Transform Z
    var oChange = 5.0
    oNode.getProperty( oProperty ).setValue( oNode.getProperty( oProperty ).getValue() + oChange);
})();

 

Hope this helps someone else,

Thanks,

mjdalways

Comments

Sign In or Register to comment.