How to script modifying a body shape?

MCphylyssMCphylyss Posts: 34

Hello,

I'm trying to write a very simple "random character" script, but I really don't know to script.

I have to do two things :

        - How to get existing shapes names for an object ?

        - How to set a shape on an object once I have my object and the shape name? ( something like: object.set_chape("Giselle_6_body", 0.75) ) ?

Thanks for help.

Post edited by MCphylyss on

Comments

  • Have a look at http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/properties/node_properties/start for accessing the properties of a node. You can use oProperty.setValue( value ) once you have a morph or other property you want to modify.

  • Thanks for the reply. Its finaly working. The only problem is that I have to write manually shapes names I want to use. I can share the script if someone's interrested.

    // array of shapes names to use. In this example, actors face shapes var shapes = ["FHMAshleyHead","FHMGretaHead","FHMBambi","FHMGiselle","FHMIridessa"...]// number of shapes to use. n is randomly chozen between n_min and n_maxn_min = 4; n_max = 10;// shape strength. default is 1 impact = 1;// choosing number of shapes tu usen_morphs = Math.round(Math.random()*(n_max-n_min)+n_min);// getting selected object in the sceneoNode = Scene.getPrimarySelection().getSkeleton();oObject = oNode.getObject();// resetting all usable shapesfor ( n = 0 ; n < shapes.length ; n++ ) {	oModifier = oObject.findModifier(shapes[n]);	if (oModifier!=null) {oModifier.getValueChannel().setValue(0);}	else {print(shapes[n]);}}// choosing shapes to use, and their value.morph = [];total = 0;for (i=0; i<n_morphs; i++){	m = Math.random()*(shapes.length-1);	v = Math.random(); total+=v;	morph.push([shapes[Math.round(m)],v]);}// applying chosen morphs.for (i=0; i<morph.length; i++){    oModifier = oObject.findModifier(morph[i][0]);	if (oModifier!=null) {oModifier.getValueChannel().setValue(morph[i][1]/total*impact);}}

    If Someone knows a way to get shapes names by scripting, I would be interested. Thanks aagain.

  • The modifiers should have a name and a getLabel() function, so you could just grab all of the modifiers and list or check the names from that (or randomly pick a modifier by number).

  • Thanks a lot! I did not found doc about modifier object, but I just checked and methods getName() ang getLabel() are working.

  • jag11jag11 Posts: 885

    How'bout moving this thread to Daz Script Developer Discussion forum, I found it really interesting/helpful.

  • mcphylyss_dc4b55d7ad - if you wish to move this to the Scripting forum, which is a good source of information, edit your first post by clicking the gear icon in its  top-right corner and select the the new forum from the button just above the title.

  • MCphylyss_2MCphylyss_2 Posts: 48
    edited May 2018

    Hi, I used the script as is for a while, but few days ago, A user called Davidagha sent me informations thanks to which I was able to considerably improve the script. It's now fully automated and you can randomize any body part you want : body, head, eyes, nose, mouth, brows, expressions... For those who're interested : https://www.sharecg.com/v/91228/view/8/Script/Daz3D-Morphs-Randomizer#

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