Hello folks,
I recently began scripting in MEL, and my first script consists of a simple Material creator through a window.
Here is what I've got so far :
// DOES NOT WORK!
optionVar -sv colorManagementColorPickerColorSpaceSelection "Display Space";
// delete window if it already exists
if ( `window -exists VRCreator` ) {
deleteUI VRCreator;
}
// create a window
$VRCreator = `window -t "VRay Mtl Creator" -sizeable false -widthHeight 700 700`;
// define the layout of the controls
columnLayout;
// create a couple of buttons
textFieldGrp -label "Name" -text "New material" MatName;
radioButtonGrp -numberOfRadioButtons 3 -label "Type" -labelArray3 "Plastic" "Metallic" "Transparent" -sl 1 MatType;
colorSliderGrp -label "Color" MatColor;
optionMenu -label "Roughness" -changeCommand "print #1" MatRough;
menuItem -label "Glossy";
menuItem -label "Satin";
menuItem -label "Matte";
floatFieldGrp -label "IoR" -annotation "(Water 1,33 / Plexi 1,49 / Glass 1,54)" MatRefracIndex;
frameLayout -width 450 -labelVisible false;
helpLine;
setParent ..;
button -label "Create" -command "CreationProcess()";
// show the created window
showWindow $VRCreator;
// update window based on selection
// begin the creation process
global proc CreationProcess() {
// redeclare the variables for the procedure
string $MatRoughResult;
// store which options are selected
$MatNameResult = `textFieldGrp -q -tx MatName`;
$MatRoughResult = `optionMenu -q -v MatRough`;
$MatColorResult = `colorSliderGrp -q -rgb MatColor`;
$MatColorRough = `optionMenu -q -v MatRough`;
// Apply choices to variables
$MatRefAmount = 255;
switch ($MatRoughResult) {
case "Glossy" :
$MatRoughAmount = 0.95;
break;
case "Satin" :
$MatRoughAmount = 0.80;
break;
case "Matte" :
$MatRoughAmount = 0.60;
break;
}
// create the material
shadingNode -asShader -name $MatNameResult VRayMtl;
$Selection = `ls -sl`;
setAttr ($Selection[0] + ".diffuseColor") -type float3 $MatColorResult[0] $MatColorResult[1] $MatColorResult[2];
setAttr ($Selection[0] + ".reflectionColor") -type float3 $MatRefAmount $MatRefAmount $MatRefAmount;
setAttr ($Selection[0] + ".reflectionGlossiness") $MatRoughAmount;
}
if ( catch( CreationProcess() ) ) {
window -title " " -titleBarMenu false -sizeable false -widthHeight 1 1 VRCErrorWindow;
columnLayout;
text -label "Error! Check availability of the Vray plugin";
button -label "Ok" -command "CloseErrorWindow()";
showWindow;
} else {
}
proc CloseErrorWindow() {
deleteUI VRCErrorWindow;
};
I am currently having trouble with setting width and height for my window. I started writing that :
window -t "VRay Mtl Creator" -sizeable false -widthHeight 700 700 VRCreator;
But for any reason, the dimensions do not apply correctly, and I don't know why. I had to change it for this to work :
$VRCreator = `window -t "VRay Mtl Creator" -sizeable false -widthHeight 700 700`;
That works, the window has the right size. However, now the beginning part who deletes the window if already created does nothing anymore. That one :
// delete window if it already exists
if ( `window -exists VRCreator` ) {
deleteUI VRCreator;
}
If I add a "$" to VRCreator in that part, it returns me an error of undeclared variable for "$VRCreator".
So basically I have to choose between a window that have the proper dimensions, or one that re-opens if called again.
As stated in the title, I began scripting only a few days ago, and I really don't have a clue why any of this happens. Can you help me ? I hope I am clear enough