Need some simple programming scripts for daz

Hi guys I usually use listeners for learning scripting like maya I learnt Mel using maya script editor which shows whatever that you do.why daz 3d doesn't have this feature it's so bad. :( Couple of days just looking how to set a value to a blend shape in daz and how to set a key on it and go to the next frame in the time line these are the three simple things that I need any body knows what are the codes?tnx.

Comments

  • Tnx but I didn't get anything don't know even were is the script editor is it Script IDE??

    When I run something I don't get any result don't get anything from this.Would you plz tell me the codes cause I don't really need daz that much I use maya but now I just want to do these four things with it:

    1-Set a value.

    2-Set a key (I mean animation key)

    3-go to the next frame

    4-export a file to fbx.

    Plz help me with this. tnx again.

  • Richard HaseltineRichard Haseltine Posts: 102,436

    Yes, ScriptIDE is the editor (and has a debugger).

    The - as yet incomplete - docs for the DS 4 functions are at http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/start , though it is worth getting the DS 3 docs too as a lot of elements carry over http://docs.daz3d.com/doku.php/public/software/dazstudio/3/start

    What you want are DzElement:findProperty ( name ) or DzElement.findPropertyByLabel ( label ) (where the DzEleemnt will usually be the bone or figure you are working on, or the object for a morph for a Morph - DzNode.getObject().findModifier( name ) then use getValueChannel() to get its property controller).

    Once you have the property you have getNumKeys(), getKeyValue( n ), getValue( ) or getValue( time ), and various setValue() objects on DzProperty, .DzNumericProperty, and DZFloatProperty (each of which derives in turn from the former).

  • edited May 2016

    Ok tnx for the reply Richard.

    But the point is I still get nothing I ran some of your codes but I get this same error What's wrong should I define a language programming first for this syntax error??:

    And for this:

    Sceen.getPrimarySelection()

    I get:

     

    Executing Script...

    Script Error: Line 1

    ReferenceError: Can't find variable: Sceen

    Stack Trace: ()@:1

    Error executing script on line: 1

    Script executed in 0 secs 2 msecs.

    Nothing really works wish I could MEL :(

    Post edited by kmthrong_149911edc9 on
  • Richard HaseltineRichard Haseltine Posts: 102,436
    edited May 2016

    Scene, not Sceen.

    You need to get the primary selection (if that is what you want to work on), check it's a valid type (usually using .inherits( classname )), then use the findProperty on that, then set or examine the values on that (checking for validity each time).

    var figure = Scene.getPrimarySelection();// Check there was a return and that it's a figureif ( figure && figure.inherits( "DzSkeleton" ) ) {	// get the object	var object = figure.getObject();	// Make sure that worked	if ( object && object.inherits( "DzObject" ) ) {		// get the morph using its name		// we could usually get this more directly from the figure node		var lats = object.findModifier( "PBMLatsSize" );		// check we did get a modifier		if ( lats && lats.inherits( "DzModifier" ) ) {			// get the value channel - which holds the value and its keys			var valueChannel = lats.getValueChannel();			// this should be a float property, but we will check just that it is a property			if ( valueChannel && valueChannel.inherits( "DzProperty" ) ) {				// get the number of keys on the property				var nKeys = valueChannel.getNumKeys();				// print the number of keyd and their values				print( nKeys );				for ( var n = 0 ; n < nKeys ; n++ ) {					print( valueChannel.getKeyValue( n ) );				}			}		}	}}

    (This is what Rob calls arrow code, but I haven't sorted out the anonymous function approach that prodcues neater results yet)

    If you execute this in the ScriptIDE pane it will print its results under the edit panel, if you run it from a file it will print to the log.

    Post edited by Richard Haseltine on
  • Hi again tnx for the code it works and gives me the value of the Lats size.But how to set a value I tried:

    var figure = Scene.getPrimarySelection();var object = figure.getObject();var lats = object.findModifier( "PBMLatsSize" );lats.setValueChannel(1);

     

    But I get:

    Script Error: Line 4

    TypeError: Result of expression 'lats.setValueChannel' [undefined] is not a function.

    Stack Trace: ()@:4

     

     

    Didn't get this part BTW:

    			if ( valueChannel && valueChannel.inherits( "DzProperty" ) ) {				// get the number of keys on the property				var nKeys = valueChannel.getNumKeys();				// print the number of keyd and their values				print( nKeys );				for ( var n = 0 ; n < nKeys ; n++ ) {					print( valueChannel.getKeyValue( n ) );				}			}

    And before using this I think we need to set a key but how to Set the value of the controller choose the frame for example Go to frame 2 and then set a key.

    Really tnx for your help :)

  • Richard HaseltineRichard Haseltine Posts: 102,436

    You need to get the ValueChannel for the modifier and use setValue on that. SetValue can take a time as well as a value, which is how you create a key (I think - it's not a feature I have used).

  • Tnx again but that's exactly the problem now how to set a value??And how to go to frame for example 2??

    I tried:

    lats.setValue(1);

    lats.setValueChannel(1);

    but it doesn't work.and I still don't know how to go to frame 2.

    Plz help me more and tnx again for the replys dude.

  • Richard HaseltineRichard Haseltine Posts: 102,436
    edited May 2016

    You have the valueChannel, as an object so-named, from lats. lats is the modifier - the morph, its label and name, and the parameter that controls it; valueChannel is the actual controller and it's that that needs adjusting. Starting (ideally) from a figure without aniamtion this will add keys at frames 0, 15 and 30:

    var figure = Scene.getPrimarySelection();// Check there was a return and that it's a figureif ( figure && figure.inherits( "DzSkeleton" ) ) {	// get the object	var object = figure.getObject();	// Make sure that worked	if ( object && object.inherits( "DzObject" ) ) {		// get the morph using its name		// we could usually get this more directly from the figure node		var lats = object.findModifier( "PBMLatsSize" );		// check we did get a modifier		if ( lats && lats.inherits( "DzModifier" ) ) {			// get the value channel - which holds the value and its keys			var valueChannel = lats.getValueChannel();			// this should be a float property, but we will check just that it is a property			if ( valueChannel && valueChannel.inherits( "DzProperty" ) ) {				// get the number of keys on the property				var nKeys = valueChannel.getNumKeys();				// print the number of keyd and their values				print( "Number of keys %1".arg( nKeys ) );				for ( var n = 0 ; n < nKeys ; n++ ) {					print( valueChannel.getKeyValue( n ) );				}				// Now let's set the base value (no keys assumed)				valueChannel.setValue( 1 );				// and repeat the readout of keys - 				// note we don't need to declare the variables again				nKeys = valueChannel.getNumKeys();				print( "Number of keys %1".arg( nKeys ) );				for ( n = 0 ; n < nKeys ; n++ ) {					print( valueChannel.getKeyValue( n ) );				}				// now we will set three keys - 				// 0.75 at frame 0,				// 0.5 at frame 15 (0.5 s, which is 2,400 ticks)				// 1 at frame 30 (1s, 4,800 ticks)				valueChannel.setValue( 0 , 0.75 );				valueChannel.setValue( 2400 , 0.5 );				valueChannel.setValue( 4800 , 1 );				// and again print out the keys				nKeys = valueChannel.getNumKeys();				print( "Number of keys %1".arg( nKeys ) );				for ( n = 0 ; n < nKeys ; n++ ) {					print( valueChannel.getKeyValue( n ) );				}			}		}	}}

    Note that the time is set in "ticks", one second is four-thousand-eight-hundred ticks. This is covered in the DS 3 scripting docs for DzTime.

    Post edited by Richard Haseltine on
  • Thank that's working pretty well :)

    Also wrote a code in cmd for converting the number of frames to ticks.

    @echo off:startcolor 2clsecho Give the number of the frame to convert it to daz ticks.set /p r=set /a answer=160*%r%echo.color 9echo %answer%pause>nulgoto start

    Your script works with some morphs but doesn't work with some too which I don't know why.you know my question is.

    If it's lats size for example how do you know the morph name is PBMLatsSize.What is PBM??

    I tested :

      var lats = object.findModifier( "PBMAA" );

    But it doesn't work I figure maybe the name here is not:

    PBMAA

    I don't know maybe something else could you tell me where did you get it from I mean PBM??

  • Richard HaseltineRichard Haseltine Posts: 102,436

    Click the gear icon on the morph's slider and select Parameter Settings, the morph's name will be listed there.

  • Tnx for the information ok now I know the name:

    eCTRLvAA

    But still doesn't work maybe I noticed that your awesome script works with Modifier/Shape

    But doesn't work with Modifier/Pose.

    Would you plz help me on these last parts too tnx again you're a great dude!!!!!!!

     

  • Richard HaseltineRichard Haseltine Posts: 102,436

    If it's a pose modifier it will belong to the figure itself, so you can use findModifier on figure and skip the getting the object step (if you want only pose modifiers).

  • Tnx again buddy but it doesn work agian don't know why I edited:

      var lats = figure.findModifier( "eCTRLvAA" );

    and deleted the :

     var object = figure.getObject();

    But now it tells me:

    TypeError: Result of expression 'figure.findModifier' [undefined] is not a function.

  • Richard HaseltineRichard Haseltine Posts: 102,436

    Sorry, you need findProperty( name ) not findModifier( name ). You could also use findPropertyByLabel( label )  which would avoid the need to get the morph's name.

  • Richard HaseltineRichard Haseltine Posts: 102,436

    Rob has updated the Node properties sample script to demonstrate both getting a full list of the properties on a node (showing the different handling of modifiers and others) and fidning a property by label or name: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/properties/node_properties/start Using code like that to retrieve the proeprties you can then apply the stuff in my example above to manipulate values and keys.

  • TNX a lot Richard Finally I achived the purpose here's the final code for selecting AA and adding keys on it :) :

    // DAZ Studio version 4.8.0.55 filetype DAZ Script(function(){ 	/*********************************************************************/	// Array<DzProperty> : A function for getting a list of the properties in a group	function getGroupProperties( oGroup, bTraverse, bRecurse )	{		// Declare an array to hold properties		var aProperties = []; 		// If a group isn't passed in		if( !oGroup ){			// We're done, return an empty array			return aProperties;		} 		// Get the number of proeprties in the group		var nProperties = oGroup.getNumProperties();		// Pre-size the properties array		aProperties = new Array( nProperties );		// Iterate over the properties, setting each element in the array		for( var i = 0; i < nProperties; i += 1 ){			// Assign the property to the position in the array			aProperties[ i ] = oGroup.getProperty( i );		} 		// If we are recursing		if( bRecurse ){			// Concatenate the properties array from child groups			aProperties = aProperties.concat(				getGroupProperties( oGroup.getFirstChild(), true, bRecurse ) );		} 		// If we are traversing		if( bTraverse ){			// Concatenate the properties array from sibling groups			aProperties = aProperties.concat(				getGroupProperties( oGroup.getNextSibling(), bTraverse, bRecurse ) );		} 		// Return the array of properties		return aProperties;	}; 	/*********************************************************************/	// Array<DzProperty> : A function for getting the list properties for an element	function getElementProperties( oElement, bTraverse, bRecurse )	{		// Get the property group tree for the element		var oPropertyGroupTree = oElement.getPropertyGroups();		// Get the first group in the tree		var oPropertyGroup = oPropertyGroupTree.getFirstChild();		// Return the properties for the element		return getGroupProperties( oPropertyGroup, bTraverse, bRecurse );	}; 	/*********************************************************************/	// DzProperty : A function for finding a property associated with an element	function findElementProperty( oElement, sProperty, bUseLabel )	{		// Declare a working variable		var oProperty; 		// If the application version is 4.7.1.44 or newer and we're not using		// the label to find, or the application version is 4.9.3.11 or newer		if( (App.version64 >= 0x000400070001002c && !bUseLabel) ||			App.version64 >= 0x000400090003000b ){			// Get the property group tree for the element			var oPropertyGroupTree = oElement.getPropertyGroups(); 			// If we're using the label			if( bUseLabel ){				// Attempt to find the property				oProperty = oPropertyGroupTree.findPropertyByLabel( sProperty );			// If we're not using the label			} else {				// Attempt to find the property				oProperty = oPropertyGroupTree.findProperty( sProperty );			} 			// If we found a property			if( oProperty ){				// We're done, return it				return oProperty;			}		// Otherwise		} else {			// Get the properties of the element			var aProperties = getElementProperties( oElement, true, true );			// Iterate over the properties			for( var i = 0; i < aProperties.length; i += 1 ){				// Get the 'current' property				oProperty = aProperties[i]; 				// If we're using the label				if( bUseLabel ){					// If the label of the property is the one we're looking for					if( oProperty.getLabel() == sProperty ){						// We're done, return it						return oProperty;					}				// If we're not using the label				} else {					// If the name of the property is the one we're looking for					if( oProperty.name == sProperty ){						// We're done, return it						return oProperty;					}								}			}		} 		return null;	}; 	/*********************************************************************/	// void : A function for reporting information about the properties associated with an element	function printElementPropertiesInfo( oElement )	{		// Get the properties available to the user by way of the selected node		var aProperties = getElementProperties( oElement, true, true );		// Declare variables we'll be using as we iterate		var oProperty, oOwner;		// Iterate over all properties		for( var i = 0; i < aProperties.length; i += 1 ){			// Get the "current" property			oProperty = aProperties[ i ];			// Get the owner of the property			oOwner = oProperty.getOwner(); 			// If the property is on a modifier			if( oOwner.inherits( "DzModifier" ) ){				// Provide feedback				print( String( "%1 : %2 : %3" )					.arg( oOwner.className() )					.arg( oOwner.name )					.arg( oProperty.getLabel() )				);			// Otherwise			} else {				// Provide feedback				print( String( "%1 : %2 : %3" )					.arg( oOwner.className() )					.arg( oProperty.name )					.arg( oProperty.getLabel() )				);			}		}	}; 	/*********************************************************************/	// Get the primary selection	var oNode = Scene.getPrimarySelection();	// If nothing is selected	if( !oNode ){		// We're done..		return;	} 	// Print information about the properties on the node	//printElementPropertiesInfo( oNode ); 	// Find a specific property by name	var lats = findElementProperty( oNode, "eCTRLvAA", false );	// If we found a property	if( lats ){		// Provide feedback		print( "Found:", lats.name, ":", lats.getLabel() );lats.setValue( 1 );lats.setValue( 0  , 2 );lats.setValue( 320 , 0.5 );lats.setValue( 480 , 1 );}})();		

     

  • Richard HaseltineRichard Haseltine Posts: 102,436

    Good, glad to have helped (or passed on Rob's help)

Sign In or Register to comment.