Script for add layer on
Hello,
I'm not a developper but I'm little familiar with php langage and I hope I could understand DAZ scripting because my request is not difficult (I believe) and it could give me great result..
I would like to modify an image on shader (ex bump image) like we can manually with Layered Image Editor. Only change one layer, don't touch to others.
So How to get the current layers properties and modified them ?
I would like to add/remove and/or replace a line :
For example replace bump2.jpg by bump3.jpg
Or add another bump layer in one image-library set
Replace that :
"image_library" : [
{
"id" : "bump",
"name" : "bump",
"map_size" : [ 1600, 1600 ],
"map_gamma" : 1,
"map" : [
{
"url" : "/url-link/bump.jpg",
"label" : "bump.jpg",
"color" : [ 0, 0, 0 ],
"transparency" : 1,
"invert" : false,
"rotation" : 0,
"xmirror" : false,
"ymirror" : false,
"xscale" : 1,
"yscale" : 1,
"xoffset" : 0,
"yoffset" : 0,
"operation" : "alpha_blend"
},
{
"url" : "/url-link/bump2.jpg",
"label" : "bump2",
"color" : [ 0, 0, 0 ],
"transparency" : 0.3,
"invert" : false,
"rotation" : 0,
"xmirror" : false,
"ymirror" : false,
"xscale" : 1,
"yscale" : 1,
"xoffset" : 0,
"yoffset" : 0,
"operation" : "alpha_blend"
}
]
},
by
"image_library" : [
{
"id" : "bump",
"name" : "bump",
"map_size" : [ 1600, 1600 ],
"map_gamma" : 1,
"map" : [
{
"url" : "/url-link/bump.jpg",
"label" : "bump.jpg",
"color" : [ 0, 0, 0 ],
"transparency" : 1,
"invert" : false,
"rotation" : 0,
"xmirror" : false,
"ymirror" : false,
"xscale" : 1,
"yscale" : 1,
"xoffset" : 0,
"yoffset" : 0,
"operation" : "alpha_blend"
},
{
"url" : "/url-link/bump3.jpg",
"label" : "bump3",
"color" : [ 0, 0, 0 ],
"transparency" : 0.3,
"invert" : false,
"rotation" : 0,
"xmirror" : false,
"ymirror" : false,
"xscale" : 1,
"yscale" : 1,
"xoffset" : 0,
"yoffset" : 0,
"operation" : "alpha_blend"
},
{
"url" : "/url-link/bump4.jpg",
"label" : "bump4",
"color" : [ 0, 0, 0 ],
"transparency" : 0.3,
"invert" : false,
"rotation" : 0,
"xmirror" : false,
"ymirror" : false,
"xscale" : 1,
"yscale" : 1,
"xoffset" : 0,
"yoffset" : 0,
"operation" : "alpha_blend"
}
]
},
Please give me help ! :)))))
Comments
Load the file into the script a a string (just read the whole file into a single variable), JSON.parse( yourString ) to get a data object, find the string variable wthin the image_library array, edit it, JSON.stringify( yourObject ) to get a string, and write it to a new .duf file.
Thank you Richard, I precise
The "problem" is that one of my layer is a variable. it depend of the loaded shader. so I would like to get (collect) and re-use it (a little like GET-URL)
I want to modify the layers after a shader is loaded.
For example the shader load 3 layers for bump image. Then I want that after load the script I keep one of these 3 layers and modify the 2 others.
In that case you need to get the item that owns the geometry, getObject() on that, getCurrentShape() on that, then you can get the materials for that (unfortunately the entry for DzMaterial in the docs is not currently available, but the DS 3 version should be enough to handle this), then you can use findProperty() on the material to get the thing with the maps, then get the map from the property and it will be a DzLayeredImage http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/layeredimage_dz
I don't want to use it as material but as shader to apply in any surface on any object. You are telling me that's it's not possible ?
I'm not following - I told you how to edit the file and you said you wanted to modify it after application, which is trickier, so I gave an outline of the likely steps to take to do that.
Sorry, it's me. translation + scripting = 2 langages for me ! :)
I will try that thank you very much Richard
A little begin of script will be appreciate ^^
I meant to post a link to oen of Rob's samples, showing how to handle amterials
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/properties/material_properties/start
When he reminded me of that he added a link to a script that uses layered images
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/images/create_layered_image_backdrop/start
Yes I read that but I would like easier script with no condition, no loop. Only find the layer and replace it.
A begin like that :
var oNode = Scene.getPrimarySelection();
var oObj = oNode.getObject();
var oShape = oObj.getCurrentShape();
etc
Thank you !
You can use DzShape.findMaterial( name ) to get a specifed material - but make sure your script does check that it has succeeded - if you are wanting to modifiy only a single, known surface.