Save UV Set Value with Material Preset or change UV Set via script

quindorquindor Posts: 4

Hi!

I'm trying to change the UV Set of a script generated shell either per script or when I apply the material. I can't get it work. I've loaded in the UVSet on the base figure and saved it as a UV Asset. I can change the UV Set manually in the base figure and in the generated shell - so this works fine. But somehow it's not possible to change this property via script. And it seems like it's also not saved in the material preset.
 

Here is the part of my script (I can succesfully change other values of the material):
 

Scene.findNodeByLabel("MyShell").select(true);var node = Scene.getPrimarySelection();var nodeShape = node.getObject().getCurrentShape();var numMats = nodeShape.getNumMaterials();///////////////change uv setfor (var mats = 0; mats < numMats; mats++){	var curMat = nodeShape.getMaterial(mats);	var UVSet= curMat.findProperty("UV Set");	UVSet.setValue("MyUV");	}

 

I hope someone can help me.

 

Thank you very much!

Post edited by Richard Haseltine on

Comments

  • Moved to the scripting forum.

    Some error checking in there might help - but I have grave doubts that you are correct in using a string to set the value as the UV Set is a DzEnumProperty - you might be able to use DzEnumProperty.setValueFrom String( "MyUV" ).

  • Use the getUVSetControl() method on the material to get the DzEnumProperty:

    var UVSet = curMat.getUVSetControl();	UVSet.setValueFromString( "MyUV" );

     

  • quindorquindor Posts: 4

    Ok, thank you very much. I found a solution in the meantime.

    var node = Scene.getPrimarySelection();var nodeShape = node.getObject().getCurrentShape();var numMats = nodeShape.getNumMaterials();///////////////change uv setfor (var mats = 0; mats < numMats; mats++){	var curMat = nodeShape.getMaterial(mats);	var UVSet= curMat.findProperty("UV Set");		///////////// get right index	for (listuv = 0; listuv < 5; listuv++)		{		UVSet.setValue(listuv);		var UVName = curMat.getUVSetControl().getStringValue();		//print(UVName);		if(UVName == "MyUV")			break;		}	}

    Nice suggestion with with setValueFromString(). I will try this instead of the for loop.

     

    Thank you very much!

Sign In or Register to comment.