Script to export geograft morphs

Currently trying to replicate this in script:  https://www.youtube.com/watch?v=Gq6eePZxxvE

Was hoping I could use `oElement.addProperty` to quickly copy a property from the geograft to the main figure. 

First problem was that this seemed to move the property rather than create a new one.  But no big deal, I thought I should still be able to export it (though apparently the export didn't work). 

Second problem, and the problem I'm trying to solve now, is that properties whose names have the same suffix won't add, and I get a "DZ_NON_UNIQUE_NAME_ERROR". 

`MorphName This Morph` gets added, but then I get the duplicate name error when trying to subsequently add `MorphName This Morph More 1` and `MorphName This Morph More 2`. 

I might be barking up the wrong tree anyway, since the export didn't seem to work.  I'm considering trying to replicate the menu actions from the video if all else fails, but that's its own problem since I'm not sure those actions in "edit mode" are triggerable via script. 

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,564

    I haven't watched the video (a description of waht youw ant to achieve would be helpful) but copying a proeprty won't help if you are wanting to project a matching morph into a graft - that is a modifier (which will be driven by a property but is rather more than a proerpty itself). If the graft is close-fitting to existing mesh then you will get the projected morph when the morph on the base figure is set and just need to make it persistent, otherwise you would need to create a new morph for he graft.

  • CStratCStrat Posts: 30

    Richard Haseltine said:

    I haven't watched the video (a description of waht youw ant to achieve would be helpful) but copying a proeprty won't help if you are wanting to project a matching morph into a graft - that is a modifier (which will be driven by a property but is rather more than a proerpty itself). If the graft is close-fitting to existing mesh then you will get the projected morph when the morph on the base figure is set and just need to make it persistent, otherwise you would need to create a new morph for he graft.

     

    The gentleman in the video is using the Golden Palace geograft as an example.  I have been attempting to replicate the results in script using this shark tail resource which is a SFW geograft:
    https://www.daz3d.com/shark-tail-for-genesis-8-and-81-female

    First, he opens the settings on the morph he wants to export and unchecks the "auto follow" box.  He also copies several of the parameters such as name, label, type, and other settings to notepad. 

    Then he selects the model, goes into Edit Mode, and clicks "create new property". Property type is "float".  

    He pastes the params from notepad into his new property. He then clicks "create". 

    He then clicks on the parameter settings for the new property, and checks the box for "auto follow".  

    After these steps, he is able to use "FBX to Unity" successfully.  I am not exporting to unity, I am exporting FBX 2020 Ascii if that matters. 

    So, I thought there would be two possible avenues to tackle this in script:

    1. Replicate the menu actions that the video describes using script (not sure how to accomplish this)

    or

    2. Find a more direct way to copy/move the morph to the main model that satisfies the requirements for FBX export

  • Richard HaseltineRichard Haseltine Posts: 100,564

    Well, what he does (if Auto Follow was turned off before fitting) is stop the morphs from being projected into the fitted item as temporary morphs, so he can then add permanent properties with the same name which will follow the settings on the base and will exist to be exported. However, those new properties won't do anything so I am not sure how that helps.

  • CStratCStrat Posts: 30

    Richard Haseltine said:

    Well, what he does (if Auto Follow was turned off before fitting) is stop the morphs from being projected into the fitted item as temporary morphs, so he can then add permanent properties with the same name which will follow the settings on the base and will exist to be exported. However, those new properties won't do anything so I am not sure how that helps.

    I haven't gotten as far as testing the exported FBX, but I did solve recreating the steps in the video:

    First, set a var for the node you want to add the property to.  In my case, i called it primaryNode.

    Then, turn auto follow off:

    oProperty.setCanAutoFollow(false);

    Then, add it to your desired node:

    primaryNode.addProperty(oProperty);

    At this point you've replicated all the steps from the video.  I don't yet know whether it's effective, as you said. 

    That being said, I'm still running into the naming issue.  I'm finding these properties using 

    oProperty = oPropertyGroupTree.findProperty(sProperty);

    and if that fails, then

    oProperty = oPropertyGroupTree.findPropertyByLabel(sProperty);

    But as I said, it will find "Some Morph Name" on the first pass, but then in subsequent passes I get the "DZ_NON_UNIQUE_NAME_ERROR" error for names that use the first name as a suffix, like "Some Morph Name More 1" and "Some Morph Name More 2" etc.  I assume some issue in the core code with regex, although I'm continuing to examine my own code to see if I have created this issue somewhere. 

  • Richard HaseltineRichard Haseltine Posts: 100,564

    Proerpty names do not usually have spaces in them, though I am not sure oif that is a hard requirement.

  • CStratCStrat Posts: 30

    I did test, and indeed my method does not actually work when imported into Unity. 

  • CStratCStrat Posts: 30
    edited November 2

    However, when using the steps from the video manually, the export and import into unity does work. 

    The main difference between my script steps and the steps in the video is that through script, I don't see a way to get or set the Name value for a property.  So while you can copy/paste the name field in edit mode when creating a property in Daz, it doesn't seem you can do the same for the name field through script.  My new property through script just ends up with "Value" for name.  I believe this mismatch is what causes the script method to fail. 

    EDIT - That would also explain the non-unique name error, since every newly added property has the name "Value" instead of the actual name.

    Post edited by CStrat on
  • CStratCStrat Posts: 30

    Richard Haseltine said:

    The associated modifier will have a name, though - I don't know if that helps. http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/element_dz

    In fact, that is how I solved this in the end, thanks Richard! 

    For anyone else interested:

    oProperty.setCanAutoFollow(false); // removes autofollow from the source property
    var newProperty = new DzFloatProperty(oProperty.getOwner().getName(), oProperty.canAnimate(), oProperty.isUserProperty(), oProperty.getValue()); // creates a new property with the proper name, grabbing the name from the source property's modifier
    newProperty.copyFrom(oProperty); //copies most of the settings from the source property
    newProperty.setPath(oProperty.getPath()); // copies the path from the source property
    newProperty.setPresentation(oProperty.getPresentation()); // copies the "type" (Modifier/Shape) from the source property
    initialNode.addProperty(newProperty); // node that you want to export from, probably root node in most cases
    oProperty.setCanAutoFollow(true); // final step before export

    Note:  This does scramble up your scene, so if you need to perform fresh operations after this, then you'll have to revert the changes somehow.

  • CStratCStrat Posts: 30
    edited November 2

    Now I am trying to figure out how to revert the changes to restore the scene.  

    I tried keeping a cache of the new properties I am adding to the root node, then removing them at the end of the script.  That does make the original geograft morph properties re-appear, but they are greyed out and I can't figure out why.  I tried "unhide" but that didn't do anything. 

     

    UPDATE - Hmm.. It appears deselecting "show hidden properties" in preferences does make them disappear.  Yet, right-clicking the property itself and selecting "unhide" does nothing.

    UPDATE - SOLVED -  Before removing the new property you added to the root node, you have to go through the process of turning off auto-follow on the original property, then removing the new property, then turning auto-follow back on for the old property. Done!

    Post edited by CStrat on
Sign In or Register to comment.