Check if Prerender mel script exist or not


#1

Edite // I started this thread for how to "
Check if Prerender mel script exist or not"

but apparently i found the solution and this thread get little derailed and now this thread is more about

" how to connect infield or floatfield to particular value of an object and reverse "

Read further reply for the answer for the new query.

Hi,

Here i want to query if there is any mel command set in the prerender mel script segment of maya render setting. But can’t figure out how.
I can set a prerender mel script via the script editor but can’t know if there is already one assigned or not.

Do anyone know how can i know this??


#2

It is an attribute in the defaultRenderGlobals:

defaultRenderGlobals.preMel

You can simply get the attribute and check for any content.


#3

Thanks,
I knew it. I was trying the same but was getting some error. i must have typed something wrong or may be have misspelled or miss written.

Thanks any way. now it’s working.


#4

Another question.

I have a small Gui wher i can put a integer value in the intfield box and it is connected to a sahder’s certain value.
if i change the gui’s value the shader updates it.But whenever i change the value in gui and then reopen the gui the value in the gui shows a certain default value whether the value in shader is one i just set beforereopening the Gui.

So i can’t figure it out how to connect them reversely.
i mean if i change the value in gui and then re open it it should show me the value i just put in not a default value set in script.


#5

How do you connect the UI and the shader attribute? Without seeing a script or part of it it’s difficult to say what’s wrong.


#6

Hi,

i have a small intField with an ‘accept’ button beside it.

here is my code for the UI

intFieldGrp -nf 1 -cw 1 110 -cat 10 left 1 -cat 2 both 5 -l "Occlusion Samples :" -v1 190 -cl2 right left OccSmpl;



and here is the command for accept button:

 int $OccSample = `intFieldGrp -q -v1 OccSmpl`;
 setAttr "mibOccTexture.samples" $OccSample;


I can get the value from shader itself with getAttr command and store it into a variable but can’t figure out how to use that variable inside the Ui code’s -V1 flag instead of the value 190 (the top one).


#7

What about trying to use the variable instead of the 190 if you create the intField?
Or later with -edit:

intFieldGrp -e -v1 $yourVariable;

#8

Yes i tried using variable instead of 190 in the -v1 flag but isn’t working. :cry: :cry:


#9

It normally works fine. If you could tell us the error message and post your code, we can analyze very much better what’s wrong.


#10

I’m sorry this was my bad. Actually i was declaring the variable after the infieldgrp generation in coding. that’s why i was getting the error.

I have to declare the variable at the very beginning of the code and it will run like a charm.

so the code looks like:

//declare the variable first
int $getoccsampl = `getAttr mibOccTexture.samples`;
float $getoccspread = `getAttr mibOccTexture.spread`;
float $getoccMaxD = `getAttr mibOccTexture.max_distance`;

//then generate the infield or floatfield

if ( `window -exists Test` ) {deleteUI OccDepthvalue;}
window -s no -te 110 -title "Test Window" Test;
if (`windowPref -exists OccDepthvalue`) windowPref -remove OccDepthvalue;


columnLayout; 

	     rowLayout -numberOfColumns 4 -columnWidth3 0 0 0;     
	         columnLayout  center;
	      
		       intFieldGrp -nf 1 -cw 1 110 -cat 10 left 1 -cat 2 both 5 -l "Occlusion Samples :" -v1 $getoccsampl -cl2 right left OccSmpl;
		       separator -style "none" -h 3;
		       floatFieldGrp -nf 1 -cw 1 110 -cat 10 left 1 -cat 2 both 5 -l "Maximum Distance :" -v1 $getoccspread -cl2 right left OccMD;
		       separator -style "none" -h 3;
		       floatFieldGrp -nf 1 -cw 1 110 -cat 10 left 1 -cat 2 both 5 -l "Sprade :" -v1 $getoccMaxD -cl2 right left OccSprd;
		       separator -style "none" -h 10; 
		       
		     setParent..;
		       
		       button -label "Accept" -w 50 -h 50 -command "setOccValue()";
		 setParent..;
		  
setParent..;
      
//command for the accept button.
global proc setOccValue()
{
 int $OccSample = `intFieldGrp -q -v1 OccSmpl`;
 setAttr "mibOccTexture.samples" $OccSample;
 float $OccMaxDist = `floatFieldGrp -q -v1 OccMD`;
 setAttr "mibOccTexture.spread" $OccMaxDist;
 float $OccSprad = `floatFieldGrp -q -v1 OccSprd`;
 setAttr "mibOccTexture.max_distance" $OccSprad;
}
showWindow;

But now i’m having another problem. If the mibOccTexture dosen’t exist then the code doesn’t run at all. and gives me the error
"No object matches name: mibOccTexture.samples "

Now how to fix this, at-least if the ‘mibOccTexture.samples’ doesn’t exist then i should get a confirm dialog saying that the texture doesn’t exist.So How to get that confirm dialog box? :frowning:


#11

Wait wait wait,

I just figure out how to do this confirm dialog(at least for test print “texture doesn’t exist”) but can’t figure out how to sop generating the window if the texture doesn’t exist.

i mean now there is no error. if the texture doesn’t exist instead it print “texture doesn’t exist” and run the remaining code and shows up the window.
But i want if the texture doesn’t exist then it will print “texture doesn’t exist” but the remaining code will not run or the window will not show up.

here’s the code for checking if the texture exist or not:


if (`objExists mibOccTexture`){
                               int $getoccsampl = `getAttr mibOccTexture.samples`;
                               float $getoccspread = `getAttr mibOccTexture.spread`;
                               float $getoccMaxD = `getAttr mibOccTexture.max_distance`;
                              }
else{print("texture doesn't exist 
");}

#12

This is a question of program structure.
You have two possibilities:

Put your program into a seperate procedure and return if something goes wrong like this:

global proc doit()
{
	 so something;
	 ....
	 if(!`objectExists mibOccTexture`)
		  return;
}

doit();

Or you enclose the rest into the if-else block:

	 if(!`objectExists mibOccTexture`)
	 {
		  printSomeErrorMessage;
	 }else{
		  goOnWithYourCodeAndShowTheWindow;
	 }