Reputation: 389
I want to set the subCurveExtrMax
attribute to a random number between x
and y
but I am having trouble selecting the attribute:
string $sel[] = `ls -sl`;
string $obj;
for ($obj in $sel) {
float $ran = rand(0.972, 0.984);
setAttr ($obj+".polyExtrudeFace.subCurveExtrMax") $ran;
}
Upvotes: 1
Views: 729
Reputation: 12218
You can also supply a random extrusion depth when you call the extrude the first time:
polyExtrudeFacet -lt $ranx $rany $ranz; // to specify all 3 offsets
polyExtrudeFacet -ltz $ranz; // to specify just the extrusion depth
Upvotes: 1
Reputation: 2620
polyExtrudeFace is not an attribute of the selected object. It would be a node that is connected to the object.
You will have to treat it as a node and set its attribute using setAttr. Let's say the node's name was polyExtrudeFace1. You would do:
string $extrudeNode = "polyExtrudeFace1";
setAttr ($extrudeNode + ".subCurveExtrMax") $ran;
If you want to find the extrude node dynamically, you can use listConnections on your selected object with type as "polyExtrudeFace" to get list of connected extrude nodes.
Also, note that the extrude nodes are connected to the shape nodes and not the transform nodes. So we must make sure we do the listConnections on the shape nodes.
In your case something like this may work (modifying your code):
string $selObj[] = `ls -sl`;
for ($obj in $selObj) {
string $selShape[] = `listRelatives -shapes -path`;
string $conn[] = `listConnections -type "polyExtrudeFace" -source 0 -destination 1 $selShape[0]`;
for ($extrudeNode in $conn) {
setAttr ($extrudeNode + ".subCurveExtrMax") $ran;
}
}
This will apply the rand on all extrudeNodes of the object though. If this is not what you want, then you could apply your logic to pick out just the extrude node you want to apply the rand to, inside the inner most for loop.
Hope this helped.
Upvotes: 0