setNodeOrigin?

macleanmaclean Posts: 1,007

Hi,

I need to update some DS presets for DS 3 & 4.5. I have this line

setNodeOrigin(47.25, 0, 1.76); 

Does anyone know the correct syntax for DS 3/4.5?

TIA

mac

«1

Comments

  • cridgitcridgit Posts: 823
    edited December 1969

    Hi maclean

    Assume you're referring to DAZ Script?

    To read the origin:

    node.getOriginXControl().getValue()
    node.getOriginYControl().getValue()
    node.getOriginZControl().getValue()


    To set the origin

    node.getOriginXControl().setValue( x );
    node.getOriginYControl().setValue( y );
    node.getOriginZControl().setValue( z );

  • macleanmaclean Posts: 1,007
    edited December 1969

    Hi cridgit,

    Yes. I currently have some old DS pose scripts which change the origin + some trans values. They're from DS 1.7 and they actually work in DS 3, but I wanted to update them with the correct current syntax.

    That looks good. I'll try it out and see how it goes.

    Thanks!

    mac

  • macleanmaclean Posts: 1,007
    edited December 1969

    Hmm... I've come across an issue with this Pose Preset. It seems DS doesn't like not having the node defined. Here's my script and the error message I get.

    switch( this.m_oElement.name ){
    case "door":
    g_oPresetHelper.setTransformProperty( "ZTranslate", [ 0 ] );
    g_oPresetHelper.setTransformProperty( "YRotate", [ 0 ] );
    node.getOriginXControl().setValue( 47.25 );
    node.getOriginYControl().setValue( 0 );
    node.getOriginZControl().setValue( 1.76 );
    break;
    default:
    break;

    Executing Script...
    Script Error: Line 523
    ReferenceError: node is not defined
    Stack Trace:
    (DzSkeleton(name = "rc0_door2_5578"),DzBone(name = "door"),false)@:523
    (DzSkeleton(name = "rc0_door2_5578"),DzSkeleton(name = "rc0_door2_5578"),true)@:542
    ()@:504
    ()@:274
    ()@:549
    ()@:-1
    Error executing script on line: 523
    Script executed in 0 secs 16 msecs.

    I'm using the generic 'case "door"'; Is there a way to get the label, as opposed to a specific name. This script has to work with a door on several different figures.

    mac

  • cridgitcridgit Posts: 823
    edited December 1969

    maclean said:
    Hmm... I've come across an issue with this Pose Preset. It seems DS doesn't like not having the node defined. Here's my script and the error message I get.

    switch( this.m_oElement.name ){
    case "door":
    g_oPresetHelper.setTransformProperty( "ZTranslate", [ 0 ] );
    g_oPresetHelper.setTransformProperty( "YRotate", [ 0 ] );
    node.getOriginXControl().setValue( 47.25 );
    node.getOriginYControl().setValue( 0 );
    node.getOriginZControl().setValue( 1.76 );
    break;
    default:
    break;

    Executing Script...
    Script Error: Line 523
    ReferenceError: node is not defined
    Stack Trace:
    (DzSkeleton(name = "rc0_door2_5578"),DzBone(name = "door"),false)@:523
    (DzSkeleton(name = "rc0_door2_5578"),DzSkeleton(name = "rc0_door2_5578"),true)@:542
    ()@:504
    ()@:274
    ()@:549
    ()@:-1
    Error executing script on line: 523
    Script executed in 0 secs 16 msecs.

    I'm using the generic 'case "door"'; Is there a way to get the label, as opposed to a specific name. This script has to work with a door on several different figures.

    mac



    Its trying to call a method on node, so when node is undefined that triggers an error.

    You can use getZPosControl().setValue( z ) instead of setTransformProperty( "ZTranslate", [ 0 ] ) and similarly you have getXPosControl(), getYPosControl(), getXRotControl(), getYRotControl(), getZRotControl(), getScaleControl(), getXScaleControl(), getYScaleControl() and getZScaleControl() for manipulating the object's transforms.

    To identify an object, use node.name or node.getLabel() and to check if it contains "door" you can do this

    if (node.name.find("door") >= 0 || node.getLabel().find("door") >= 0)     ...


    I can't see from your code what's causing node to be undefined, but if you want a second pair of eyes, PM me.

    Cheers

  • macleanmaclean Posts: 1,007
    edited October 2012

    It's not the setTransformProperty lines causing the issue. I just tried removing the origin lines and the script works perfectly. Like this.

    switch( this.m_oElement.name ){
    case "door":
    g_oPresetHelper.setTransformProperty( "ZTranslate", [ 0 ] );
    g_oPresetHelper.setTransformProperty( "YRotate", [ 0 ] );
    break;
    default:
    break;

    But that's just a normal Pose Preset, which doesn't help me. With the origin lines in, I keep getting the same error, and after I close DS 3, it wants to send a crash report.

    I was loading the figure from a DS directory (with DS geometry in the data folder), so I tried it from a Poser folder instead, but the result is the same. The reason I tried is that the 'rc0_door2_5578' error refers to the door folder in data - ie. its vertex count.

    Not sure how I use the getLabel thing. Can I paste it into the IDE window?

    mac

    Edit - The peculiar thing is that the old script from DS 1.5 works fine. The line in it reads
    setNodeOrigin (47.25, 0, -2.26);
    It also refers to case "door", but of course other functions in the script will be different from current versions. Certainly, adding that line to a current script doesn't work.

    Post edited by maclean on
  • Richard HaseltineRichard Haseltine Posts: 19,371
    edited December 1969

    What it means is that node is an undefined item for some reason - it should, as I recall, be set at the beginning of the function, before the switch statement, butt hat's either missing or is not getting a valid value for some reason.

  • cridgitcridgit Posts: 823
    edited December 1969

    Hi maclean

    In the example I gave you above, I used node as the object name. You pasted those lines into your script, but perhaps aren't setting the value of node further up (as Richard said), so either you need to rename node to whatever object you're working with, or you need to set node. If you don't it always going to hiccup on that line.

    I shared the other transform methods with you because they appear to be a more updated way of setting object transforms. You don't have to use them, but if you want to update the script I thought you might like to know about them.

    I can't help any further now until I see a bit more of the script (for example, where g_oPresetHelper is defined). If you don't want to post the script here, PM me and I can help offline.

    Cheers

  • macleanmaclean Posts: 1,007
    edited December 1969

    Well, I'm not sure how I go about defining the node, or how DS does it.

    This is just a normal Pose Preset saved for the door, then edited to remove unneccessary values, (Scale, etc), and with the origin lines added (as posted above). If DS itself doesn't define a node when saving the preset (other than using case "door") how do I go about it?

    I have the script on my other pc. I'll transfer it later on and post it here. But as I said, it's nothing unusual. Just an edited Pose Preset.

    mac

  • cridgitcridgit Posts: 823
    edited December 1969

    node is a variable name (like g_oPresetHelper) so you need to set it to something before you can use it. In the example I gave you, I used node, figuring you'd know to set it beforehand.

    That was an assumption and a simplification on my part. Unfortunately I can't tell you how to set node unless I know what you want to do (impossible to dive into the middle of a script and know what happens at the beginning / end of the script). Clearly we need to take a step back and take the script from the top, otherwise I won't be able to help.

    Just let me node (sorry!) how you want to proceed :-)

  • Richard HaseltineRichard Haseltine Posts: 19,371
    edited December 1969

    Looking at it, I think this.m_oElement is the thing you are altering the properties of - so replace node with this.m_oElement

  • macleanmaclean Posts: 1,007
    edited October 2012

    Looking at it, I think this.m_oElement is the thing you are altering the properties of - so replace node with this.m_oElement

    Bingo!!

    That works perfectly! Thanks a lot.

    mac

    Post edited by maclean on
  • macleanmaclean Posts: 1,007
    edited October 2012

    cridgit said:
    node is a variable name (like g_oPresetHelper) so you need to set it to something before you can use it. In the example I gave you, I used node, figuring you'd know to set it beforehand.

    That was an assumption and a simplification on my part. Unfortunately I can't tell you how to set node unless I know what you want to do (impossible to dive into the middle of a script and know what happens at the beginning / end of the script). Clearly we need to take a step back and take the script from the top, otherwise I won't be able to help.

    Just let me node (sorry!) how you want to proceed :-)

    Yeah, sorry, cridgit. With me, you have to assume you're talking to an idiot 5 y.o. LOL.

    Thanks very much for all the help.

    cheers

    mac

    Post edited by maclean on
  • macleanmaclean Posts: 1,007
    edited October 2012

    Well, I should have known it was too good to be true. This script is causing a new set of problems.

    I had been testing the script with a basic door (in Room Creator), which is the slimmed-down version of the main door. Today I tried applying it to the main door, which has numerous other items parented to it - crossbars, dividers, etc - and discovered that when I apply the script, all items parented to the door move a considerable distance away. (That distance appears to be the exact reverse of the distance from the center of the scene - Ztrans -595).

    So what I want to know now is, is there a way to ensure all parented items behave properly? I see various oChild references, but I don't know what they mean. In this script, the final line reads
    this.setProperties( oSkeleton, oChild, false );
    whereas in my old 1.5 script, it reads
    this.setProperties( oSkeleton, oChild, bRecurse );

    I tried changing it to bRecurse, but with no luck. I'm almost ready to forget this and use the old v1.5 script which works perfectly.

    Anyway, here's the latter part of the script as it stands now. (Note - I made it a Char preset so I could include the material switch as well, but that shouldn't make any difference).

    TIA

    mac

    DsActions.prototype.begin = function()
    {
    var bSelected = false;
    var bRecurse = false;
    var bRoot = false;
    if( g_oGui.getNodes() == g_sSELECTED )
    {
    bSelected = true;
    }
    if( g_oGui.getPropagation() == g_sRECURSIVE )
    {
    bRecurse = true;
    }
    if( g_oGui.getNodes() == g_sROOT )
    {
    bRoot = true;
    bSelected = true;
    }
    g_oPresetHelper.setDoMorphs( g_oGui.morphsChecked() );
    g_oPresetHelper.setLimits( g_oGui.limitsChecked() );
    g_oPresetHelper.setTransforms( g_oGui.transformsChecked() );
    g_oPresetHelper.setXRot( g_oGui.xRotChecked() );
    g_oPresetHelper.setYRot( g_oGui.yRotChecked() );
    g_oPresetHelper.setZRot( g_oGui.zRotChecked() );
    g_oPresetHelper.setXPos( g_oGui.xTranChecked() );
    g_oPresetHelper.setYPos( g_oGui.yTranChecked() );
    g_oPresetHelper.setZPos( g_oGui.zTranChecked() );
    g_oPresetHelper.setGScl( g_oGui.gScaleChecked() );
    g_oPresetHelper.setXScl( g_oGui.xScaleChecked() );
    g_oPresetHelper.setYScl( g_oGui.yScaleChecked() );
    g_oPresetHelper.setZScl( g_oGui.zScaleChecked() );
    setBusyCursor();
    this.m_aNodes = g_oSceneHelper.collectNodes( bSelected, bRecurse, bRoot );

    beginUndo();
    for( var i = 0; i < this.m_aNodes.length; i++ ){
    this.setProperties( this.m_aNodes[ i ].getSkeleton(), this.m_aNodes[ i ], bRecurse );
    }

    bSelected = false;
    bRoot = false;
    if( g_oGui.getSurfaces() == g_sSELECTED )
    {
    bSelected = true;
    bRoot = true;
    }
    if( g_oGui.getSurfaces() == g_sALL )
    {
    bRoot = true;
    }

    if( g_oGui.getMapSettings() == g_sIGNORE_MAPS )
    g_oPresetHelper.setMapSetting( DzPresetHelper.Ignore );
    else
    g_oPresetHelper.setMapSetting( DzPresetHelper.Replace );

    this.m_aNodes = g_oSceneHelper.collectNodes( true, true, true );

    for( var i = 0; i < this.m_aNodes.length; i++ )
    {
    this.m_oNode = this.m_aNodes[ i ];
    this.m_aNewMaterials = new Array;
    g_oPresetHelper.collectMaterials( this.m_oNode, false, bSelected, bRoot );
    this.m_aMaterials = g_oPresetHelper.getCollectedMaterials();
    this.m_aMaterialShapes = g_oPresetHelper.getCollectedMaterialShapes();
    for( var j = 0; j < this.m_aMaterials.length; j++ )
    this.setMaterialProperties( this.m_aMaterials[ j ] );
    }

    acceptUndo( String( "\"%1\"" ).arg( g_sSCRIPT_NAME ) );
    clearBusyCursor();
    }

    /*********************************************************************/
    DsActions.prototype.setMaterialProperties = function( oMaterial, oShape ){
    this.m_oElement = oMaterial;
    var sID = this.m_oElement.name;
    switch( sID ){
    case "hinge":
    this.m_sMaterialType = "DzDefaultMaterial";
    this.m_sMaterialName = "DAZ Studio Default";
    this.prepareMaterial();
    g_oPresetHelper.setTargetElement( this.m_oElement );
    g_oPresetHelper.setColorProperty( "Diffuse Color", [ 255, 255, 255 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Diffuse Strength", true, 0, 1, [ 1 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Glossiness", true, 0, 1, [ 1 ] );
    g_oPresetHelper.setColorProperty( "Specular Color", [ 0, 0, 0 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Specular Strength", true, 0, 1, [ 1 ] );
    g_oPresetHelper.setNumericProperty( "Multiply Specular Through Opacity", [ 0 ] );
    g_oPresetHelper.setColorProperty( "Ambient Color", [ 0, 0, 0 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Ambient Strength", true, 0, 1, [ 1 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Opacity Strength", true, 0, 1, [ 0 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Bump Strength", true, 0, 2, [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Negative Bump", [ -0.01 ] );
    g_oPresetHelper.setNumericProperty( "Positive Bump", [ 0.01 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Displacement Strength", true, 0, 2, [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Minimum Displacement", [ -0.1 ] );
    g_oPresetHelper.setNumericProperty( "Maximum Displacement", [ 0.1 ] );
    g_oPresetHelper.setPropertyWithString( "Normal Map", "" );
    g_oPresetHelper.setColorProperty( "Reflection Color", [ 255, 255, 255 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Reflection Strength", true, 0, 1, [ 0 ] );
    g_oPresetHelper.setColorProperty( "Refraction Color", [ 255, 255, 255 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Refraction Strength", true, 0, 1, [ 0 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Index of Refraction", true, 0, 10, [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Horizontal Tiles", [ 1 ] );
    g_oPresetHelper.setNumericProperty( "Horizontal Offset", [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Vertical Tiles", [ 1 ] );
    g_oPresetHelper.setNumericProperty( "Vertical Offset", [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Lighting Model", [ 3 ] );
    g_oPresetHelper.setNumericProperty( "UV Set", [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Smooth On", [ 1 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Smooth Angle", true, 0, 180, [ 89.9 ] );
    break;
    case "hinge_back":
    this.m_sMaterialType = "DzDefaultMaterial";
    this.m_sMaterialName = "DAZ Studio Default";
    this.prepareMaterial();
    g_oPresetHelper.setTargetElement( this.m_oElement );
    g_oPresetHelper.setColorProperty( "Diffuse Color", [ 0, 0, 0 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Diffuse Strength", true, 0, 1, [ 1 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Glossiness", true, 0, 1, [ 0.6 ] );
    g_oPresetHelper.setColorProperty( "Specular Color", [ 255, 237, 178 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Specular Strength", true, 0, 1, [ 1 ] );
    g_oPresetHelper.setNumericProperty( "Multiply Specular Through Opacity", [ 1 ] );
    g_oPresetHelper.setColorProperty( "Ambient Color", [ 0, 0, 0 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Ambient Strength", true, 0, 1, [ 1 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Opacity Strength", true, 0, 1, [ 1 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Bump Strength", true, 0, 2, [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Negative Bump", [ -0.01 ] );
    g_oPresetHelper.setNumericProperty( "Positive Bump", [ 0.01 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Displacement Strength", true, 0, 2, [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Minimum Displacement", [ -0.1 ] );
    g_oPresetHelper.setNumericProperty( "Maximum Displacement", [ 0.1 ] );
    g_oPresetHelper.setPropertyWithString( "Normal Map", "" );
    g_oPresetHelper.setColorProperty( "Reflection Color", [ 244, 216, 130 ],
    "/Runtime/textures/maclean/room creator/rc0chrome.jpg" );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Reflection Strength", true, 0, 1, [ 0.6 ] );
    g_oPresetHelper.setColorProperty( "Refraction Color", [ 255, 255, 255 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Refraction Strength", true, 0, 1, [ 0 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Index of Refraction", true, 0, 10, [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Horizontal Tiles", [ 1 ] );
    g_oPresetHelper.setNumericProperty( "Horizontal Offset", [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Vertical Tiles", [ 1 ] );
    g_oPresetHelper.setNumericProperty( "Vertical Offset", [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Lighting Model", [ 3 ] );
    g_oPresetHelper.setNumericProperty( "UV Set", [ 0 ] );
    g_oPresetHelper.setNumericProperty( "Smooth On", [ 1 ] );
    g_oPresetHelper.setNumericPropertyWithAttributes( "Smooth Angle", true, 0, 180, [ 89.9 ] );
    break;
    default:
    break;
    }
    }

    /*********************************************************************/
    DsActions.prototype.setProperties = function( oSkeleton, oNode, bRecurse ){
    var sSkeleton = "";
    if( oSkeleton ){
    this.m_oSkeleton = oSkeleton;
    sSkeleton = this.m_oSkeleton.name;
    }
    this.m_oElement = oNode;
    this.m_oObject = ( this.m_oElement ? this.m_oElement.getObject() : undefined );
    g_oPresetHelper.setTargetElement( this.m_oElement );
    switch( this.m_oElement.name ){
    case "door":
    g_oPresetHelper.setTransformProperty( "ZTranslate", [ -3.5 ] );
    g_oPresetHelper.setTransformProperty( "YRotate", [ 0 ] );
    this.m_oElement.getOriginXControl().setValue( 47.25 );
    this.m_oElement.getOriginYControl().setValue( 0 );
    this.m_oElement.getOriginZControl().setValue( -2.26 );
    break;
    default:
    break;
    }
    if( bRecurse ){
    var aStack = [ oNode ];
    while(aStack.length>0){
    var oParent = aStack.pop();
    var nNodes = oParent.getNumNodeChildren();
    var oChild;
    for( var n = 0; n < nNodes; n++ ){
    oChild = oParent.getNodeChild( n );
    if( oChild.inherits( "DzBone" ) ){
    if(oChild.getNumNodeChildren()>0){
    aStack.push( oChild );
    }
    this.setProperties( oSkeleton, oChild, false );
    }
    }
    }
    }
    }

    g_bCONTROL_PRESSED ? g_oGui.doDialog() : g_oGui.doNoDialog();

    Post edited by maclean on
  • cridgitcridgit Posts: 823
    edited December 1969

    Hi mac, thanks for posting the script. I'll take a look at it but its going to require some attention so it could be a day or two if that's ok.

  • macleanmaclean Posts: 1,007
    edited December 1969

    Hey, no problem. I'm just happy you're trying to help.

    cheers

    mac

  • cridgitcridgit Posts: 823
    edited December 1969

    Hi mac

    I'm going through the script now, reformatting and adding comments which will hopefully help you. However, it doesn't run on my system, because a number of the variables are undefined (e.g. g_oGUI). Is this the whole script, or was there something at the top (e.g. include(X) that you left out?

    Thanks

  • cridgitcridgit Posts: 823
    edited October 2012

    Hi mac

    I've gone through the script, reformatted to make it easier to read/understand and added comments to help. Haven't changed any code, but I did add some comments marked *** where I thought the intent wasn't clear.

    /* All the g_oXXX objects e.g. g_oGui, are defined somewhere else in another script. This script is executed on the last line which is g_oGui.doDialog(). I assume that shows the dialog, then calls DsActions.prototype.begin when the user clicks Accept. *//* Below defines a function "begin" without arguments, on the DSActions object. Generally, adding functions to a third party object (through DSActions.prototype) is frowned upon because it could lead to instability. This is ok if DsActions is your object, defined in this script */DsActions.prototype.begin = function() {   // Initialize variables    var bSelected = false;   var bRecurse = false;   var bRoot = false;   // Check if nodes are selected in the GUI   if( g_oGui.getNodes() == g_sSELECTED )      bSelected = true;   // Check if recursive is selected in the GUI   if( g_oGui.getPropagation() == g_sRECURSIVE )      bRecurse = true;   // Check if root node is selected in the GUI   if( g_oGui.getNodes() == g_sROOT )   {      bRoot = true;      bSelected = true;   }   // Transfer GUI checkboxes to preset helper   g_oPresetHelper.setDoMorphs( g_oGui.morphsChecked() );   g_oPresetHelper.setLimits( g_oGui.limitsChecked() );   g_oPresetHelper.setTransforms( g_oGui.transformsChecked() );   g_oPresetHelper.setXRot( g_oGui.xRotChecked() );   g_oPresetHelper.setYRot( g_oGui.yRotChecked() );   g_oPresetHelper.setZRot( g_oGui.zRotChecked() );   g_oPresetHelper.setXPos( g_oGui.xTranChecked() );   g_oPresetHelper.setYPos( g_oGui.yTranChecked() );   g_oPresetHelper.setZPos( g_oGui.zTranChecked() );   g_oPresetHelper.setGScl( g_oGui.gScaleChecked() );   g_oPresetHelper.setXScl( g_oGui.xScaleChecked() );   g_oPresetHelper.setYScl( g_oGui.yScaleChecked() );   g_oPresetHelper.setZScl( g_oGui.zScaleChecked() );   // Tell the user we're busy   setBusyCursor();      // Collect nodes (tell the function whether anything is selected, whether to recurse and whether the root node is selected)   this.m_aNodes = g_oSceneHelper.collectNodes( bSelected, bRecurse, bRoot );    // Set the undo checkpoint   beginUndo();      // Run through all the collected nodes and set the properties of each node using    // "DsActions.prototype.setProperties" function below   for( var i = 0; i < this.m_aNodes.length; i++ )      this.setProperties( this.m_aNodes[ i ].getSkeleton(), this.m_aNodes[ i ], bRecurse );      // Re-initialize variables   bSelected = false;   bRoot = false;      // Check if any surfaces are selected   if( g_oGui.getSurfaces() == g_sSELECTED )   {      bSelected = true;      bRoot = true;   }      // *** Not sure why we're doing this here - if surfaces are selected above then bRoot is already true.    // Need to see what getSurfaces() does. ***   if( g_oGui.getSurfaces() == g_sALL )      bRoot = true;    // Transfer "ignore maps" option from GUI to preset helper   if( g_oGui.getMapSettings() == g_sIGNORE_MAPS )      g_oPresetHelper.setMapSetting( DzPresetHelper.Ignore );   else      g_oPresetHelper.setMapSetting( DzPresetHelper.Replace );       // Collect nodes (tell the function something is selected, to recurse and that the root node is selected) -    // I guess this forces collection of all nodes   this.m_aNodes = g_oSceneHelper.collectNodes( true, true, true );      // Run through all the collected nodes and ..   for( var i = 0; i < this.m_aNodes.length; i++ )   {      // ... make a note of the current node      this.m_oNode = this.m_aNodes[ i ];            // ... create a new materials container      this.m_aNewMaterials = new Array;            // ... collect materials for the current node (tell the function whether something is selected and       // whether the root node is selected)      g_oPresetHelper.collectMaterials( this.m_oNode, false, bSelected, bRoot );            // ... make a note of the collected materials      // *** Not sure why we're doing this step and the previous step this way - normally we'd call the function and       // store the result in a variable in 1 step. Need to see these two functions to know why ***      this.m_aMaterials = g_oPresetHelper.getCollectedMaterials();            // ... make a note of the material shapes      this.m_aMaterialShapes = g_oPresetHelper.getCollectedMaterialShapes();            // ... run through the collected materials for this node and set material properties using the       // DsActions.prototype.setMaterialProperties function below      for( var j = 0; j < this.m_aMaterials.length; j++ )         this.setMaterialProperties( this.m_aMaterials[ j ] );   }    // Add the script name to the undo list   acceptUndo( String( “\”%1\”” ).arg( g_sSCRIPT_NAME ) );      // Tell the user we're finished   clearBusyCursor();} /*********************************************************************/DsActions.prototype.setMaterialProperties = function( oMaterial, oShape ){   // Make a note of the material and its name   // *** sID should probably be called sMaterialName - that would be a more intuitive variable name ***   this.m_oElement = oMaterial;   var sID = this.m_oElement.name;   // Check the material's name ...   switch( sID )   {      case “hinge”:         // ... initialize the material         // *** Not sure what prepareMaterial does - might need to see this function ***         this.m_sMaterialType = “DzDefaultMaterial”;         this.m_sMaterialName = “DAZ Studio Default”;         this.prepareMaterial();                  // ... set hinge material properties, i.e. make it look like a hinge         g_oPresetHelper.setTargetElement( this.m_oElement );         g_oPresetHelper.setColorProperty( “Diffuse Color”,  [ 255, 255, 255 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Diffuse Strength”, true, 0, 1, [ 1 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Glossiness”, true, 0, 1, [ 1 ] );         g_oPresetHelper.setColorProperty( “Specular Color”,  [ 0, 0, 0 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Specular Strength”, true, 0, 1, [ 1 ] );         g_oPresetHelper.setNumericProperty( “Multiply Specular Through Opacity”,  [ 0 ] );         g_oPresetHelper.setColorProperty( “Ambient Color”,  [ 0, 0, 0 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Ambient Strength”, true, 0, 1, [ 1 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Opacity Strength”, true, 0, 1, [ 0 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Bump Strength”, true, 0, 2, [ 0 ] );         g_oPresetHelper.setNumericProperty( “Negative Bump”,  [ -0.01 ] );         g_oPresetHelper.setNumericProperty( “Positive Bump”,  [ 0.01 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Displacement Strength”, true, 0, 2, [ 0 ] );         g_oPresetHelper.setNumericProperty( “Minimum Displacement”,  [ -0.1 ] );         g_oPresetHelper.setNumericProperty( “Maximum Displacement”,  [ 0.1 ] );         g_oPresetHelper.setPropertyWithString( “Normal Map”, “” );         g_oPresetHelper.setColorProperty( “Reflection Color”,  [ 255, 255, 255 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Reflection Strength”, true, 0, 1, [ 0 ] );         g_oPresetHelper.setColorProperty( “Refraction Color”,  [ 255, 255, 255 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Refraction Strength”, true, 0, 1, [ 0 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Index of Refraction”, true, 0, 10, [ 0 ] );         g_oPresetHelper.setNumericProperty( “Horizontal Tiles”,  [ 1 ] );         g_oPresetHelper.setNumericProperty( “Horizontal Offset”,  [ 0 ] );         g_oPresetHelper.setNumericProperty( “Vertical Tiles”,  [ 1 ] );         g_oPresetHelper.setNumericProperty( “Vertical Offset”,  [ 0 ] );         g_oPresetHelper.setNumericProperty( “Lighting Model”,  [ 3 ] );         g_oPresetHelper.setNumericProperty( “UV Set”,  [ 0 ] );         g_oPresetHelper.setNumericProperty( “Smooth On”,  [ 1 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Smooth Angle”, true, 0, 180, [ 89.9 ] );      break;      case “hinge_back”:         // ... initialize the material         this.m_sMaterialType = “DzDefaultMaterial”;         this.m_sMaterialName = “DAZ Studio Default”;         this.prepareMaterial();         // ... set hinge material properties, i.e. make it look like a hinge back         g_oPresetHelper.setTargetElement( this.m_oElement );         g_oPresetHelper.setColorProperty( “Diffuse Color”,  [ 0, 0, 0 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Diffuse Strength”, true, 0, 1, [ 1 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Glossiness”, true, 0, 1, [ 0.6 ] );         g_oPresetHelper.setColorProperty( “Specular Color”,  [ 255, 237, 178 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Specular Strength”, true, 0, 1, [ 1 ] );         g_oPresetHelper.setNumericProperty( “Multiply Specular Through Opacity”,  [ 1 ] );         g_oPresetHelper.setColorProperty( “Ambient Color”,  [ 0, 0, 0 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Ambient Strength”, true, 0, 1, [ 1 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Opacity Strength”, true, 0, 1, [ 1 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Bump Strength”, true, 0, 2, [ 0 ] );         g_oPresetHelper.setNumericProperty( “Negative Bump”,  [ -0.01 ] );         g_oPresetHelper.setNumericProperty( “Positive Bump”,  [ 0.01 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Displacement Strength”, true, 0, 2, [ 0 ] );         g_oPresetHelper.setNumericProperty( “Minimum Displacement”,  [ -0.1 ] );         g_oPresetHelper.setNumericProperty( “Maximum Displacement”,  [ 0.1 ] );         g_oPresetHelper.setPropertyWithString( “Normal Map”, “” );         g_oPresetHelper.setColorProperty( “Reflection Color”,  [ 244, 216, 130 ],          “/Runtime/textures/maclean/room creator/rc0chrome.jpg” );         g_oPresetHelper.setNumericPropertyWithAttributes( “Reflection Strength”, true, 0, 1, [ 0.6 ] );         g_oPresetHelper.setColorProperty( “Refraction Color”,  [ 255, 255, 255 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Refraction Strength”, true, 0, 1, [ 0 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Index of Refraction”, true, 0, 10, [ 0 ] );         g_oPresetHelper.setNumericProperty( “Horizontal Tiles”,  [ 1 ] );         g_oPresetHelper.setNumericProperty( “Horizontal Offset”,  [ 0 ] );         g_oPresetHelper.setNumericProperty( “Vertical Tiles”,  [ 1 ] );         g_oPresetHelper.setNumericProperty( “Vertical Offset”,  [ 0 ] );         g_oPresetHelper.setNumericProperty( “Lighting Model”,  [ 3 ] );         g_oPresetHelper.setNumericProperty( “UV Set”,  [ 0 ] );         g_oPresetHelper.setNumericProperty( “Smooth On”,  [ 1 ] );         g_oPresetHelper.setNumericPropertyWithAttributes( “Smooth Angle”, true, 0, 180, [ 89.9 ] );      break;      default:      break;   }} // This function is called by the DsActions.prototype.begin function above, to set the properties for each collected node.DsActions.prototype.setProperties = function( oSkeleton, oNode, bRecurse ){   // Clear skeleton name   var sSkeleton = “”;      // Make a note of skeleton and its name if it exists   if( oSkeleton )   {      this.m_oSkeleton = oSkeleton;      sSkeleton = this.m_oSkeleton.name;   }      // Make a note of the current node   this.m_oElement = oNode;      // Make a note of the current node's object   // *** I cant' find getObject() in the DAZ Script reference. Perhaps this function is defined elsewhere in your scripts? ***   this.m_oObject = ( this.m_oElement ? this.m_oElement.getObject() : undefined );   // Tell the preset helper which node to target   g_oPresetHelper.setTargetElement( this.m_oElement );   // Check the current node's name   switch( this.m_oElement.name )   {      case “door”:         // Move the door         g_oPresetHelper.setTransformProperty( “ZTranslate”,  [ -3.5 ] );         g_oPresetHelper.setTransformProperty( “YRotate”,  [ 0 ] );                  // Set the door's origin (so it rotates correctly)         this.m_oElement.getOriginXControl().setValue( 47.25 );           this.m_oElement.getOriginYControl().setValue( 0 );         this.m_oElement.getOriginZControl().setValue( -2.26 );      break;      default:      break;   }   // If we need to recurse (i.e. also set properties on the node's children   if( bRecurse )   {      // Create a container and place the current node inside      var aStack = [ oNode ];            // Keep working while the container has things in it ...      while(aStack.length > 0)      {         // ... get the next thing in the container         var oParent = aStack.pop();                  // ... count its children         var nNodes = oParent.getNumNodeChildren();                  // ... run through all its children ...         var oChild;         for( var n = 0; n < nNodes; n++ )         {            // ... make a note of the current child            oChild = oParent.getNodeChild( n );                        // ... if the child is a bone ...            if( oChild.inherits( “DzBone” ) )            {               // ... if the child has children of its own, put the child in the container so we can pick it up in the next round               if(oChild.getNumNodeChildren() > 0)                  aStack.push( oChild );                                 // ... set the child's properties               this.setProperties( oSkeleton, oChild, false );            }         }      }   }}// This is the activating line of the script which launches the GUI if control is pressed otherwise runs in silent mode.// These functions probably call the being function above.g_bCONTROL_PRESSED ? g_oGui.doDialog() : g_oGui.doNoDialog();

    Post edited by Richard Haseltine on
  • cridgitcridgit Posts: 823
    edited December 1969

    maclean said:
    Well, I should have known it was too good to be true. This script is causing a new set of problems.

    I had been testing the script with a basic door (in Room Creator), which is the slimmed-down version of the main door. Today I tried applying it to the main door, which has numerous other items parented to it - crossbars, dividers, etc - and discovered that when I apply the script, all items parented to the door move a considerable distance away. (That distance appears to be the exact reverse of the distance from the center of the scene - Ztrans -595).

    So what I want to know now is, is there a way to ensure all parented items behave properly? I see various oChild references, but I don't know what they mean. In this script, the final line reads
    this.setProperties( oSkeleton, oChild, false );
    whereas in my old 1.5 script, it reads
    this.setProperties( oSkeleton, oChild, bRecurse );

    I tried changing it to bRecurse, but with no luck. I'm almost ready to forget this and use the old v1.5 script which works perfectly.



    Here's my understanding of the script (some of these are assumptions because I don't have the whole script):

    1. You collect the selected nodes (including all their children if recurse is checked).
    2. Then you run through all the collected nodes and if its name is "door" you move it and set its origin.
    3. Then collect the selected surfaces and run through all of those.
    4. If a surface has a material named hinge or hingback, you make it look pretty.

    The this.setProperties( oSkeleton, oChild, false ) looks right to me, because if you'd checked recurse, its going to pick up all the children anyway when you collect selected nodes in #1, therefore no need to recurse again when setting the properties.

    I also don't think the script is causing the children to move away from the centre, because the script is ONLY touching a node named "door". I wonder if DS is doing something to the children when the parent door moves. I'll experiment with this and let you know - you using 4.5?

  • Richard HaseltineRichard Haseltine Posts: 19,371
    edited December 1969

    Edited the comment lines so that the page wasn't running into the black border, rendering text unreadable.

    Yes, parented items can behave oddly with rotation - I can't recall when, or what the fix/work around is but I ssupect that's the problem here, rather than anything in the script itself.

  • macleanmaclean Posts: 1,007
    edited December 1969

    Ok. Hold everything, guys!! I've solved the issue. And in the dumbest way imaginable.

    I was continuing updating the other scripts I have (there are hundreds of them!) and I came across one which changes switching geometry - ie - sets it to one of the alternatives. Of course, I hadn't a clue how this would be written in DS 3, so I spent an hour going through the SDK docs and found nothing relating to alt geom (I never can find anything useful in those docs).

    Anyway, to cut to the chase, on an impulse, I opened the old script in the IDE window, which of course, automatically updated it to DS 3 format. I then resaved and tested that script and it worked fine. I checked it in an editor and it all looked good, so I went back to the set origin script and did the same. Again, it updated, and again, it worked fine. (I haven't tried these in DS 4.5 yet).

    So, damn it all.... after all this dorking around, the solution was right there in DS 3. And as far as I can tell, the scripts work perfectly, with no issues whatsoever., and the parented parts on the door stay exactly where they're supposed to.

    Here's what I have now. (From the begin function again).

    DsActions.prototype.begin = function()
    {
    var bSelected = false;
    var bRecurse = false;
    var bRoot = false;
    if( g_oGui.getNodes() == g_sSELECTED )
    {
    bSelected = true;
    }
    if( g_oGui.getPropagation() == g_sRECURSIVE )
    {
    bRecurse = true;
    }
    if( g_oGui.getNodes() == g_sROOT )
    {
    bRoot = true;
    bSelected = true;
    }
    this.m_bMorphs = g_oGui.morphsChecked();
    this.m_bLimits = g_oGui.limitsChecked();
    this.m_bTransforms = g_oGui.transformsChecked();
    this.m_bXRot = g_oGui.xRotChecked();
    this.m_bYRot = g_oGui.yRotChecked();
    this.m_bZRot = g_oGui.zRotChecked();
    this.m_bXPos = g_oGui.xTranChecked();
    this.m_bYPos = g_oGui.yTranChecked();
    this.m_bZPos = g_oGui.zTranChecked();
    this.m_bGScl = g_oGui.gScaleChecked();
    this.m_bXScl = g_oGui.xScaleChecked();
    this.m_bYScl = g_oGui.yScaleChecked();
    this.m_bZScl = g_oGui.zScaleChecked();
    setBusyCursor();
    this.m_aNodes = this.collectNodes( bSelected, bRecurse, bRoot );
    beginUndo();
    for( var i = 0; i < this.m_aNodes.length; i++ )
    {
    this.setProperties( this.m_aNodes[ i ].getSkeleton(), this.m_aNodes[ i ], bRecurse );
    }
    acceptUndo( String( "\"%1\"" ).arg( g_sSCRIPT_NAME ) );
    clearBusyCursor();
    }

    /*********************************************************************/
    DsActions.prototype.setNodeOrigin = function( xChange, yChange, zChange )
    {
    var movement = new DzVec3( xChange, yChange, zChange );
    var curOrigin = this.m_oElement.getOrigin();
    var bb = this.m_oElement.getLocalBoundingBox();
    bb.translate( curOrigin );
    newOrigin = bb.getCenter().add( movement );
    if( curOrigin == newOrigin )
    return;
    this.m_oElement.setOrigin( newOrigin );
    movement = newOrigin.subtract( curOrigin );
    var wsrot = this.m_oElement.getWSRot();
    var wsscale = this.m_oElement.getWSScale();
    var wspos = this.m_oElement.getWSPos();
    wspos = wspos.subtract( movement );
    movement = wsscale.multiply( wsrot.multVec( movement ) );
    this.m_oElement.setWSPos( wspos.add( movement ) );
    this.m_oElement.update();
    }

    /*********************************************************************/
    DsActions.prototype.setProperties = function( oSkeleton, oNode, bRecurse )
    {
    var sSkeleton = "";
    if( oSkeleton )
    {
    this.m_oSkeleton = oSkeleton;
    sSkeleton = this.m_oSkeleton.name;
    }
    this.m_oElement = oNode;
    this.m_oObject = ( this.m_oElement ? this.m_oElement.getObject() : undefined );
    switch( this.m_oElement.name )
    {
    case "door":
    this.setTransformProperty( "YRotate", [ 0 ] );
    this.setNodeOrigin( 47.25, 0, -2.26 );
    this.setTransformProperty( "ZTranslate", [ -3.5 ] );
    break;
    default:
    break;
    }
    if( bRecurse )
    {
    var nNodes = oNode.getNumNodeChildren();
    var oChild;
    for( var n = 0; n < nNodes; n++ )
    {
    oChild = oNode.getNodeChild( n );
    if( oChild.inherits( "DzBone" ) )
    this.setProperties( oSkeleton, oChild, bRecurse );
    }
    }
    }
    g_bCONTROL_PRESSED ? g_oGui.doDialog() : g_oGui.doNoDialog();

    I really appreciate all the help, and I'm sorry for any wasted time.

    cheers

    mac

    PS Cridgit - Check your PMs

  • cridgitcridgit Posts: 823
    edited December 1969

    I'm sure the dumbness/simplicity of the solution is directly proportional to the amount of time you've invested in looking for it! :lol: :lol:

    That's so funny, but no harm done. Just glad you got it working.

    Cheers.

  • cridgitcridgit Posts: 823
    edited December 1969

    @Richard: by the way, code blocks and/or comments seems to cause havoc with the page formatting. You might want to ask the web team to look into this. Not only do the comments not wrap, but the page numbering and Prev/Next buttons don't work properly on pages with code/comments.

    Cheers

  • macleanmaclean Posts: 1,007
    edited October 2012

    It also seems to be doing other weird things. This post is listed in New Posts as having 22 pages. I clicked on page 22 and arrived here, which is actually the top of page 3. But when I previously came to the thread from the Developer Forum page, cridgit's post (above this one) was at the bottom of page 2.

    Edit - After posting this, I arrived back at the bottom of page 2. LOL.

    mac

    Post edited by maclean on
  • Richard HaseltineRichard Haseltine Posts: 19,371
    edited December 1969

    Yes, this forum is till displaying posts instead of pages, and if you click on the last post link it puts it at the top of a page even if it would naturally fall part way down a page. Oh well, coders should be more robust than the average user or something.

  • macleanmaclean Posts: 1,007
    edited December 1969

    Argh!

    A quick question. Does anyone know if DS 4.5 saves switching geometry code in presets? I've tried the .duf types - Pose, Char - and they both seem to ignore it.

    The resaved presets for switching geom don't work in DS 4.5 (Surprise!), and neither do the original ones. I'm now trying to figure out what the code could possibly be. Or is it just broken? I know DS 4.5 has had issues with alt geom from the beginning.

    mac

  • Richard HaseltineRichard Haseltine Posts: 19,371
    edited December 1969

    Is the geometry switching working on the figures? We found the other day that some very old items (Anton's Victoria Changing Ponytail for example) was showing a drop-down list instead of a slider, and wasn't applying materials or morphs to the alternative forms. A more recent item I made, on the other hand, is working tvia slider and is applying materials correctly. So it looks as if there may be subtle differences in how different items are handled.

  • macleanmaclean Posts: 1,007
    edited December 1969

    Yes, everything works fine, but by dropdown menu - not a slider.

    Bear in mind that all these figures are being opened from the Poser directory. One of the reasons for this Room Creator upgrade is to remove all .daz scenes and data so the user will only have a Poser install with .DSAs, plus the folders of DS presets (Materials & Poses, plus Toolbar). That's why I'm opening everything from the Poser dirs.

    So these are normal .cr2s and they all use menus for alt geom. What difference that makes, I don't know, but it doesn't seem like that's the issue.

    mac

  • Richard HaseltineRichard Haseltine Posts: 19,371
    edited December 1969

    Both of the items I was using were CR2s - there just seems to be a slight difference. However, when I checked I had the morphs from the base shape showing on all shapes which isn't how it should work so even the one that was showing and responding to a slider wasn't fully functional.

  • macleanmaclean Posts: 1,007
    edited December 1969

    But is there any savable 4.5 preset which includes alt geom settings? I can't find one.

    I want to see what code it uses in the hope I can use it to update the ones I have.

    mac

  • Richard HaseltineRichard Haseltine Posts: 19,371
    edited October 2012

    I can't see a way to save the setting in a .duf file, but it worked in a .dsa preset. with both the Victoria Changing Ponytail (no slider) and my item (with slider).

    g_oPresetHelper.setNumericProperty( "Geometry",  [ "bangs_2" ] );

    Post edited by Richard Haseltine on
Sign In or Register to comment.
Rocket Fuel