Need Simple Menu to Enter 3 Values to be used in Existing Script
There's a script I want to add a menu to so I can enter 3 values for xyz so I don't have to edit the script every time I want to enter a new value. How would I do this? I'm not sure how to do menus. The menu needs a description string, xyz entry fields, and an ok and cancel button. If cancel is selected it quits and Daz resumes normally. If ok is selected then it needs to first run the script below, feeding the 3 values entered in the menu into xPos, yPos, and zPos. It looks like it may need to feed NAN in if 0 is written in a field based on the script code. Is the best solution to have this be one script stuck together with the menu script or separate? Below is the script that the menu should come before.
//by Room Creator
// DAZ Studio version 4.15.0.30 filetype DAZ Script
var xPos = 100;
var yPos = NAN;
var zPos = NAN;
function moveObject( object )
{
if( object == undefined )
return;
if( !isNaN( xPos ) )
object.getXPosControl().setValue( object.getXPosControl().getValue() + xPos );
if( !isNaN( yPos ) )
object.getYPosControl().setValue( object.getYPosControl().getValue() + yPos );
if( !isNaN( zPos ) )
object.getZPosControl().setValue( object.getZPosControl().getValue() + zPos );
}
beginUndo();
for( var i = 0; i < Scene.getNumSelectedNodes(); i++ )
moveObject( Scene.getSelectedNode( i ) );
acceptUndo( "Move selected object(s)" );
Comments
Do you mean dialogue box, rather than menu? http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/general_ui/simple_dialog/start shows how to create and execute a dialogue, for numbers you would presumably want to use three http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/floatslider_dz as the active widgets
Yeah I meant a dialog box. The DzColorWgt probably won't work for negative coordinates, or numbers beyond 255 right? The DzIntSlider does not have the number limit problems, but it appears I can't enter numbers by keyboard like I could by right clicking in the DzColorWgt. Is there anything that allows: right clicking a field to enter a number by keyboard, negative numbers, and setting the allowed range in code as well?
Maybe this (or just the free QT editor that comes with DS) may help:
https://www.daz3d.com/dialog-design
Replace the colour widget with three numeric sliders, one for each value - you should be able to entre values just by clicking on the current value.
For DzFloatSlider, you need to set textEditable = true to edit the current value directly.
Here is an example that works on a single node (Your original sample works on all selected nodes).
So you can have keyboard entry with other sliders. I'm not sure exactly how I'd connect the code of the script I included (got errors trying to). The point is to relatively move all selected nodes, not just one. How would I call the first script from this one to feed the answers in, or should I stick them together as one script?
Here is one way of doing it that uses your existing code.
Note that all the if checks in the moveObject function are unneccessary in this case, as object is guaranteed to be defined and xPos, yPos, and zPos are guaranteed to be valid numbers.
And finally, here is how I would write this starting from nothing - it is functionally equivalent to the above but without the code duplication.
Thanks for your help!