Digital Art Zone

 
   
1 of 3
1
setNodeOrigin?
Posted: 20 October 2012 04:40 AM   [ Ignore ]
Active Member
Avatar
RankRank
Total Posts:  761
Joined  2003-10-09

Hi,

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

setNodeOrigin(47.2501.76); 

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

TIA

mac

Profile
 
 
Posted: 20 October 2012 05:30 AM   [ Ignore ]   [ # 1 ]
Active Member
RankRank
Total Posts:  901
Joined  2009-12-07

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);
node.getOriginYControl().setValue);
node.getOriginZControl().setValue); 
 Signature 

PoseMaster for DAZ Studio and PoseMaster People Pack now sold at Rendo.

Profile
 
 
Posted: 20 October 2012 02:27 PM   [ Ignore ]   [ # 2 ]
Active Member
Avatar
RankRank
Total Posts:  761
Joined  2003-10-09

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

Profile
 
 
Posted: 21 October 2012 04:13 AM   [ Ignore ]   [ # 3 ]
Active Member
Avatar
RankRank
Total Posts:  761
Joined  2003-10-09

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:
<anonymous>(DzSkeleton(name = “rc0_door2_5578”),DzBone(name = “door”),false)@:523
<anonymous>(DzSkeleton(name = “rc0_door2_5578”),DzSkeleton(name = “rc0_door2_5578”),true)@:542
<anonymous>()@:504
<anonymous>()@:274
<anonymous>()@:549
<global>()@:-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

 

Profile
 
 
Posted: 21 October 2012 05:56 AM   [ Ignore ]   [ # 4 ]
Active Member
RankRank
Total Posts:  901
Joined  2009-12-07
maclean - 21 October 2012 04:13 AM

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:
<anonymous>(DzSkeleton(name = “rc0_door2_5578”),DzBone(name = “door”),false)@:523
<anonymous>(DzSkeleton(name = “rc0_door2_5578”),DzSkeleton(name = “rc0_door2_5578”),true)@:542
<anonymous>()@:504
<anonymous>()@:274
<anonymous>()@:549
<global>()@:-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") >= || 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

 Signature 

PoseMaster for DAZ Studio and PoseMaster People Pack now sold at Rendo.

Profile
 
 
Posted: 21 October 2012 09:38 AM   [ Ignore ]   [ # 5 ]
Active Member
Avatar
RankRank
Total Posts:  761
Joined  2003-10-09

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.

Profile
 
 
Posted: 21 October 2012 02:54 PM   [ Ignore ]   [ # 6 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14720
Joined  2003-10-09

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.

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 21 October 2012 04:48 PM   [ Ignore ]   [ # 7 ]
Active Member
RankRank
Total Posts:  901
Joined  2009-12-07

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

 Signature 

PoseMaster for DAZ Studio and PoseMaster People Pack now sold at Rendo.

Profile
 
 
Posted: 22 October 2012 04:03 AM   [ Ignore ]   [ # 8 ]
Active Member
Avatar
RankRank
Total Posts:  761
Joined  2003-10-09

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

Profile
 
 
Posted: 22 October 2012 06:11 AM   [ Ignore ]   [ # 9 ]
Active Member
RankRank
Total Posts:  901
Joined  2009-12-07

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 grin

 Signature 

PoseMaster for DAZ Studio and PoseMaster People Pack now sold at Rendo.

Profile
 
 
Posted: 22 October 2012 07:27 AM   [ Ignore ]   [ # 10 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  14720
Joined  2003-10-09

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

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 22 October 2012 09:10 AM   [ Ignore ]   [ # 11 ]
Active Member
Avatar
RankRank
Total Posts:  761
Joined  2003-10-09
Richard Haseltine - 22 October 2012 07:27 AM

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

Profile
 
 
Posted: 22 October 2012 09:13 AM   [ Ignore ]   [ # 12 ]
Active Member
Avatar
RankRank
Total Posts:  761
Joined  2003-10-09
cridgit - 22 October 2012 06:11 AM

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 grin

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

Profile
 
 
Posted: 23 October 2012 04:07 AM   [ Ignore ]   [ # 13 ]
Active Member
Avatar
RankRank
Total Posts:  761
Joined  2003-10-09

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();

Profile
 
 
Posted: 23 October 2012 11:52 AM   [ Ignore ]   [ # 14 ]
Active Member
RankRank
Total Posts:  901
Joined  2009-12-07

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.

 Signature 

PoseMaster for DAZ Studio and PoseMaster People Pack now sold at Rendo.

Profile
 
 
Posted: 23 October 2012 03:04 PM   [ Ignore ]   [ # 15 ]
Active Member
Avatar
RankRank
Total Posts:  761
Joined  2003-10-09

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

cheers

mac

Profile
 
 
   
1 of 3
1