Script for setting Morph and Parent

My goal is to create a icon that a user can click and it will position the selected figure, set a morph value, and parent it to another.

I've got the positioning part done, and it works well, but I am stuck on how to set a morph value (like Young = 100%) and the parent to...

Can anyone point me in the right direction on that? 

Comments

  • 3dOutlaw3dOutlaw Posts: 2,471

    For example, this is the method I am using for setting position and scale:

    var node = Scene.getPrimarySelection();
    var ctl = node.getXScaleControl();
    ctl.setValue(1.44);
    ctl = node.getZPosControl();
    ctl.setValue(0.40);

    Since I have the primary selection...looking for a way to set a morph value?

  • Use findProperty( name ) on the node to get the conmtroller, and then treat it as you do the XRotControl.

  • 3dOutlaw3dOutlaw Posts: 2,471

    Thanks, so I got this to work for morphs in the "Actor" area of the figure, but when I use the same for a morph in the "Morphs" area, it does not modify it?

    var node = Scene.getPrimarySelection();
    var prop = node.findProperty("morph");
    if ( prop ) {
    prop.setValue( 1 );
    }

  • 3dOutlaw3dOutlaw Posts: 2,471

    OK, I think I can figure it out using this as an exmaple.  The second example here shows the morphs I need, so I should be able to use that to get/set the morphs

    http://docs.daz3d.com/doku.php/artzone/wiki/user/rbtwhiz/technotes/daz_script/node_properties/start

  • 3dOutlaw3dOutlaw Posts: 2,471

    One step at a time, in case it helps others:

    Getting a list of group paths for a node

    const oNODE = Scene.getPrimarySelection(); 
    if( oNODE ){
        const aGROUPS = oNODE.getPropertyGroups();
        const paths = aGROUPS.getAllPaths();
        var oProperty;
        for( var i = 0; i < paths.length; i++ ){
            oProperty = paths[ i ];
            print( oProperty );
        }
    }

  • 3dOutlaw3dOutlaw Posts: 2,471

    ...hmmm, this may be beyond me...  I can now get the path I want, but I think then I need to sort through the array of properties, and get the property and then I am not sure if I can even set it, ugh.

    It would be nice to be able to specify this directly, given I know the group/path name, node name and property name, like node.group.path.property.setvalue(1)  

    Here is hoping that someone has done this before, and can throw me a bone?  I am actually trying to make a freebie, so I will pay it forward!  cheeky

  • Why are you wanting to go through the path? If you aren't getting the morphs from the figure (or bone) node try going (Bone>)Figure>Object and getting the modifier from that.

  • 3dOutlaw3dOutlaw Posts: 2,471
    edited August 2016

    Well, I was following the link above, which if pasted and run (the second script shown) Rob was able to list out all of the morphs.  In that example, he goes through the path, it looks like.  I just assumed that was the only way to get the morph.

    That being said, I used what you said, and found some of your old helps, linked below and got it, thanks!

    http://www.daz3d.com/forums/discussion/13295/setting-parameter-value-by-name

    const oNODE = Scene.getPrimarySelection(); 
    if( oNODE ){
        var object = oNODE.getObject();
        print( object.name );
        var temp = object.findModifier("Morph");    
        print ( temp.name );
        temp.getValueChannel().setValue( 1 );

    Now I just need to figure out the second part, how to Parent that object to another, though I may just leave that as part of the instruction (i.e. run this script, that parent to figure) if it takes too long to figure out.

    Thanks Richard, always very helpful! smileyyes

    Post edited by 3dOutlaw on
  • Richard HaseltineRichard Haseltine Posts: 101,465
    edited August 2016

    Use node.addNodeChild( child ) - it's slightly unexpected as the UI always refers to setting the parent, but in scripting we are adding a child to the parent.

    Don't forget that Rob's samples are not Public Domain, they do require attribution (that is to the samples page, so that people can find the original) if you adapt them in your scripts.

    Post edited by Richard Haseltine on
  • 3dOutlaw3dOutlaw Posts: 2,471

    OK I'll try that.

    No problem on the attribution, I acutally used your forum posts more than his notes. That will be what is in my end freebie.  In any case, I will give credit to both he and you (and Casual) for assistance in the README to cover all bases.

  • 3dOutlaw3dOutlaw Posts: 2,471

    You should start a sticky with API Examples when you or someone comes up with them!  For example, you had a nice visibility example here:

    http://www.daz3d.com/forums/discussion/21827/script-to-toggle-visibility-of-a-node-and-all-children-nodes

    Found it via google.  I am not sure these are all in the API samples, but a Forum sticky about it, with basic user examples would be cool  (unless there is something similar I missed already).

    Here is the end result for me, made general for others benefit:

    //This part gets selected item and adjusts transforms with goal of replacing part of another figure
    var node1 = Scene.getPrimarySelection();
    var ctl = node1.getScaleControl();
    ctl.setValue(0.87);
    ctl = node1.getYPosControl();
    ctl.setValue(6.5);
    ctl = node1.getZPosControl();
    ctl.setValue(-2);

    //This part finds a Morph on the Node, and sets its value (change morphname of course)
    var object = node1.getObject();
    var mod1 = object.findModifier("morphname");    
    mod1.getValueChannel().setValue( 1 );

    //This part finds another figure in the scene, and the bone to parent the selected object
    var node2 = Scene.findNodeByLabel( "figurename" ).findBone("bonename1");
    node2.addNodeChild( node1 )

    //Then turn off the visibility of stuff the selected item is replacing
    node2.setVisible( false );
    var node3 = Scene.findNodeByLabel( "figurename" ).findBone("bonename2");
    var node4 = Scene.findNodeByLabel( "figurename" ).findBone("bonename3");
    node3.setVisible( false );
    node4.setVisible( false );

    I am not a programmer...lol

  • Heh, I can't recall what I've posted over the years - I know I have on occasion reinvented my own wheels.

    I would put some error checking in there - make sure that there is a node before doing anything with it, make sure you have an object before trying to get its modifier and so on. If not the script will just exit with an error in the log file, while explicitly checking allows you to at least pop-up an explaantory alert before stopping.

  • ratus69_c6741fefbfratus69_c6741fefbf Posts: 34
    edited September 2016

    hello,

    thanks for this helpfull thread 3dOutlaw

    Post edited by ratus69_c6741fefbf on
  • rex218rex218 Posts: 0

    Hello guys i want to print all morphs of Genesis 8 female , below is my code but it mot working

     

    var genesis8Female = Scene.findNodeByLabel("Genesis 8.1 Female");
    if (genesis8Female) {
        adjustCrotchHeightToTargetValue(genesis8Female, );
    } else {
        print("Genesis 8.1 Female node not found.");
    }

    function adjustCrotchHeightToTargetValue(node) {
    var mod1 = node.findModifier("Height");   
        print(mod1);
    }

     

  • Richard HaseltineRichard Haseltine Posts: 101,465

    As I said in the otehr thread, is this your code or AI generated code? Whata re you trying to do - you can't just "print a modifier", you need some specific detail (e.g. its name or label, or both). Have you looked at the sample script that shows how to get modifiers for a figuer? Remember that morphs belong to the shape that belongs to the figure, not the figure itself.

  • rex218rex218 Posts: 0

    Can you help with script to modify Height slider on Genesis 8 female body

     

Sign In or Register to comment.