Studio4.5 scripting: how to deal with DUF material presets?

Sylva1nSylva1n Posts: 0
edited December 1969 in Daz Script Developer Discussion

Hello,

I've written a script which load a material preset. it's quite easy to do it with a material preset DSA file.

But since the DSA are deprecated, I would like to use the new DUF format.

But I don't know how to parse it.

How can I load a material preset DUF file in a script?

best regards,

Sylvain

Comments

  • Richard HaseltineRichard Haseltine Posts: 96,849
    edited December 1969

    App.getContentMgr().openNativeFile( presetName, true );

  • Alessandro MastronardiAlessandro Mastronardi Posts: 2,593
    edited December 1969

    How would you actually save a native file, i.e. save a .duf?

  • 3dcheapskate3dcheapskate Posts: 2,689
    edited September 2012

    Draft versions of the DS4 'Save a Material(s) Preset' and 'Save a Shader Preset' script samples are up.

    Edit: sorry, those samples are still for writing DSA files!

    Post edited by 3dcheapskate on
  • Alessandro MastronardiAlessandro Mastronardi Posts: 2,593
    edited September 2012

    Yes, but it's quite straightforward to convert those into SDK.

    I'm wondering how to detect if a DzNode DzProperty is a standard one (rotate,translate,scale etc.) or is a morph. I'm sure there must be a way...

    EDIT: probably something like DzProperty->inherits("Dzsomething")...

    Post edited by Alessandro Mastronardi on
  • Richard HaseltineRichard Haseltine Posts: 96,849
    edited December 1969

    In a script, DzProperty.hasControllers() wil tell you if a property is a slave. I'm not sure there's a simple way of telling if it's a master though.

  • Alessandro MastronardiAlessandro Mastronardi Posts: 2,593
    edited December 1969

    In a script, DzProperty.hasControllers() wil tell you if a property is a slave. I'm not sure there's a simple way of telling if it's a master though.

    Thanks Richard, that worked just fine.

  • rbtwhizrbtwhiz Posts: 2,179
    edited December 1969

    Take a look at this example.

    Replace the main loop with the following:

    /*********************************************************************/
    // Get the primary selection
    var oNode = Scene.getPrimarySelection();
    // If something is selected
    if( oNode ){
     // Get the properties available to the user by way of the selected node
     var aProperties = getNodeProperties( oNode, true, true );
     // Declare variables we'll be using as we iterate
     var oProperty, oOwner, oPresentation;
     // 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();
     
      // Get the property's presentation
      oPresentation = oProperty.getPresentation();
      
      print( "----------", oProperty.name, ":", oProperty.getLabel(), "----------" );
      
      if( oPresentation && oPresentation.type == "Modifier/Pose" ){
       print( "Used for posing" );
      } else if( oPresentation && oPresentation.type == "Modifier/Shape" ){
       print( "Used for shaping" );
      }
      
      // If the property inherits DzNumericProperty
      if( oProperty.inherits( "DzNumericProperty" ) ){
       var nXYZInterest = oProperty.getXYZInterest();
       switch( nXYZInterest ){
        case 1: // X_INTEREST
        case 2: // Y_INTEREST
        case 3: // Z_INTEREST
        case 4: // ALL_INTEREST
         print( "Influences transforms" );
         break;
        case 0: // NO_INTEREST
        default:
         print( "Does not influence transforms" );
         break;
       }
      }
      
      // If the property inherits DzFloatProperty
      if( oProperty.inherits( "DzFloatProperty" ) ){
       var nTransformType = oProperty.getTransformType();
       switch( nTransformType ){
        case 1: //  SCALE
         print( "Influences scale" );
         break;
        case 2: // TRANSLATE
         print( "Influences translation" );
         break;
        case 3: // ROT_FIRST_AXIS
         print( "Influences rotation on the first axis" );
         break;
        case 4: // ROT_SECOND_AXIS
         print( "Influences rotation on the second axis" );
         break;
        case 5: // ROT_THIRD_AXIS
         print( "Influences rotation on the third axis" );
         break;
        case 0: // NON_TRANSFORM
        default:
         break;
       }
      }
      
      print( String( "Owned by a %1\n").arg( oOwner.className() ) );
     }
    }


    -Rob

  • rbtwhizrbtwhiz Posts: 2,179
    edited December 1969

    Draft versions of the DS4 'Save a Material(s) Preset' and 'Save a Shader Preset' script samples are up.

    Edit: sorry, those samples are still for writing DSA files!

    You were right the first time... The DzAssetIOFilter subclasses are for writing DSON format files. The DzSaveFilter subclasses are for writing DAZ Script based presets, but were never fully exposed to the script API and are now deprecated.

    -Rob

  • Alessandro MastronardiAlessandro Mastronardi Posts: 2,593
    edited September 2012

    I'm trying to convert the .dsa as kindly provided by Rob, but I've some troubles.

    The .dsa getGroupProperties is this:

    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;
    // If a group is passed in
    } else {
    // 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 ){
    aProperties[ i ] = oGroup.getProperty( i );
    }

    // If we are recursing
    if( bRecurse ){
    // Concatenate the properties array from child groups
    aProperties = aProperties.concat( getGroupProperties( oGroup.getFirstChild(), bTraverse, 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;
    }


    I tried to convert it into a SDK function and used the DzTArray to return group properties. However, I get errors in the highlighted lines (concat and GetFirstChild do not exist in SDK). Any chance to get some help? Thanks.

    DzTArray getGroupProperties( DzNode *oGroup, bool bTraverse, bool bRecurse )
    {
    // Declare an array to hold properties
    DzTArray aProperties;

    // If a group isn't passed in
    if( !oGroup ){
    // We're done, return an empty array
    return aProperties;
    // If a group is passed in
    } else {
    // Get the number of proeprties in the group
    int nProperties = oGroup->getNumProperties();
    // Pre-size the properties array
    aProperties = DzTArray (nProperties) ;
    // Iterate over the properties, setting each element in the array
    for( int i = 0; i < nProperties; i += 1 ){
    aProperties = *oGroup->getProperty(i);
    }

    // If we are recursing
    if( bRecurse ){
    // Concatenate the properties array from child groups
    aProperties = aProperties.concat( getGroupProperties( oGroup->getFirstChild(), bTraverse, 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;
    }

    I could use a .append to concatenate values into the array, and getFirstChild() may be replaced by getNodeChild(0) ?
    But I'm not sure the approach I used is the correct one...

    Post edited by Alessandro Mastronardi on
  • Alessandro MastronardiAlessandro Mastronardi Posts: 2,593
    edited December 1969

    I also would like to ask something that confuses me.

    In the example above, DzProperty->name() returns the expected name if it's a DzModifier/Pose.
    In the case it's a DzModifier/Shape, the name() returned is always "Value", while I'd expect to return the controller name, such as "FBMBasicFemale" for the Genesis Female Modifier/Shape.
    Am I wrong?

  • Richard HaseltineRichard Haseltine Posts: 96,849
    edited December 1969

    Should you perhaps get the value channel and then the name of that?

  • rbtwhizrbtwhiz Posts: 2,179
    edited December 1969

    The oGroup argument should be a DzPropertyGroup pointer, not a DzNode pointer.

    If the owner of a property inherits DzMorph, get the name of the modifier... not the name of the valueChannel (which will be named "Value"), that is used to apply the morph.

    -Rob

  • Alessandro MastronardiAlessandro Mastronardi Posts: 2,593
    edited December 1969

    rbtwhiz said:
    The oGroup argument should be a DzPropertyGroup pointer, not a DzNode pointer.

    If the owner of a property inherits DzMorph, get the name of the modifier... not the name of the valueChannel (which will be named "Value"), that is used to apply the morph.

    -Rob

    Thanks Rob, I think I finally have a clear idea of how all those properties are linked...

Sign In or Register to comment.