Message 1 of 4
Use MEL to use one object to control Smooth Mesh Preview of another?

Not applicable
03-12-2012
02:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to add a custom attribute to an object that let's me control the smooth mesh preview of a different object. Simplified version like this:
-Already have two meshes named "object1" and "object2".
-Add attribute to the object1.
-Integer, min 0, max 2, default 0
-When the new attribute is 0, make smooth mesh preview "off" (same as pressing 1) on object2.
-When the new attribute is 1, make smooth mesh preview "1" (same as pressing 2) on object2.
-When the new attribute is 2, make smooth mesh preview "2" (same as pressing 3) on object2.
I seem to have trouble getting this to always work... Any ideas?
This code works when I run it from the Script Editor, but it doesn't say valid after that. I was not able to use an Expression because the smooth mesh preview does not like to be connected that way. But I could very well be doing something wrong...
-Already have two meshes named "object1" and "object2".
-Add attribute to the object1.
-Integer, min 0, max 2, default 0
-When the new attribute is 0, make smooth mesh preview "off" (same as pressing 1) on object2.
-When the new attribute is 1, make smooth mesh preview "1" (same as pressing 2) on object2.
-When the new attribute is 2, make smooth mesh preview "2" (same as pressing 3) on object2.
I seem to have trouble getting this to always work... Any ideas?
This code works when I run it from the Script Editor, but it doesn't say valid after that. I was not able to use an Expression because the smooth mesh preview does not like to be connected that way. But I could very well be doing something wrong...
string $obj1 = "object1";
string $obj2 = "object2";
addAttr -ln "smoothLevel" -at long -min 0 -max 2 -dv 0 $obj1;
setAttr -e-keyable true ($obj1 + ".smoothLevel");
int $value = `getAttr ($obj1 + ".smoothLevel")`;
if ($value == 0){
setAttr ($obj2 + ".displaySmoothMesh") 0;
}
if ($value == 1){
setAttr ($obj2 + ".displaySmoothMesh") 1;
}
if ($value == 2){
setAttr ($obj2 + ".displaySmoothMesh") 2;
}