How to change surface name by using script correctly?
578276864_563542692c
Posts: 31
Here is the problem:
When I set surface name with DzMaterial.setName() funciton, The new name can show at the tool setting pannel but not at surface panel,when i save file,the texture will lost.
Comments
As far as I understand, DzMaterial is not the surface group - note that a given material can belong to an array of shapes DzMaterial.getShapeList() . Unfortunately DzShape does not currently have documentation - I think a lot of the geometry-related objects were removed to avoid spilling the beans during a previous development cycle - so if you need to access those features you may have to go object-diving, bearing in mind that what is not docuemnted is subkject to change without notice (and indeed, if changes planned/in progress that may be another/the actual reason for the lack of documentation).
For the first part of your question, I suspect the issue is name vs label.
This will result in
However, the label is not a saved property. If you save and reload this node, it will load with both name and label set to Alpha.
It is not clear what you mean by the texture being lost after saving.
Problem solved,Thank your very much!
Hi everyone, sorry to hijack this thread but I'm trying to do a similar thing and rename a surface with a particular name. For simplicities sake lets use the same names as above, so I want to rename the `Alpha` surface to `Beta`.
As someone that's new to DAZ scripting I find the samples pretty difficult to understand, but the deepCopyMaterial script is at least partially understandable. This script has multiple variables for getting the current shape etc, so in context of these how would I rename the surface?
EDIT: Sorry about the formatting, the forum doesn't save the code snippet as its displayed in edit mode :o( have attached a screenshot.
Repeated without a code block to get around forum issue...
var oTgtNode = Scene.getPrimarySelection();if (!oTgtNode)
return false;
var oTgtObject = oTgtNode.getObject();
if (!oTgtObject)
return false;
var oTgtShape = oTgtObject.getCurrentShape();
if (!oTgtShape)
return false;
var oTgtMaterial = oTgtShape.findMaterial ('Alpha');
if (!oTgtMaterial)
return false;
oTgtMaterial.setName ('Beta');
oTgtMaterial.setLabel ('Beta');
@Omniflux thank you so much! I was sooooo close, just missed that last bit :)
@Silas3D :
Since you stated you were new to scripting, I just wanted to point out from your snippet above one thing for you going forward with your scripting :
For both of your if statements...
// If we don't have both objects
if( !oSrcObject || !oTgtObject ){
// We're done...
return false;
}
...Is giving conditional argument that if either one of those are true, cancel, instead of if both of these conditions, then cancel.
Use && (and) if you need both to be true, and the || (or) if you only need one of those to be true.
Hope this helps. I know when I was first starting out, there was a lot of little things I had to learn to transition syntax to from my Python syntax for correct results.
@DaremoK3 many thanks for the advice
This actually comes from one of the DAZ snippets you mentioned in your other post