PDA

View Full Version : Wireframe, smooth shade toggle?


Levitateme
12-27-2003, 06:16 AM
I was trying to make a Hotkey like 5 so it would toggle between smoothshaded, wireframe. and later i would like to get the code and set 4 as flat shaded.
i tried this

if $TimsWireFrameToggle = 0
{
string $currentPanel = `getPanel -underPointer`;
if ("" == $currentPanel) {
$currentPanel = `getPanel -withFocus`;
}
if ("" != $currentPanel) {
string $panelType = `getPanel -typeOf $currentPanel`;
if ($panelType == "modelPanel") {
modelEditor -edit -displayAppearance "smoothShaded" -displayTextures off
-displayLights "default" $currentPanel;
} else if (`isTrue "MayaCreatorExists"` && `scriptedPanel -exists $currentPanel`
&& `scriptedPanel -query -type $currentPanel` == "dynPaintScriptedPanelType") {
dynPaintEditor -edit -displayTextures 0 -displayAppearance "smoothShaded"
-displayLights "default" $gDynPaintEditorName;
}
}
}


$TimsWireFrameToggle = 1
else
displaySmoothness -full;
{
string $currentPanel = `getPanel -underPointer`;
if ("" == $currentPanel) {
$currentPanel = `getPanel -withFocus`;
}
if ("" != $currentPanel) {
string $panelType = `getPanel -typeOf $currentPanel`;
if ($panelType == "modelPanel") {
modelEditor -edit -displayAppearance "wireframe"
-displayLights "default" $currentPanel;
} else if (`isTrue "MayaCreatorExists"` && `scriptedPanel -exists $currentPanel`
&& `scriptedPanel -query -type $currentPanel` == "dynPaintScriptedPanelType") {
dynPaintEditor -edit -displayAppearance "wireframe"
-displayLights "default" $gDynPaintEditorName;
}
}
}

$TimsWireFrameToggle = 0
;

but i get syntax errors...does anyone know how to get around this? it would be great if i could have 5 key toggle wireframe/smooth shaded and 4 toggle flat shaded/Xray...if anyone can help out that would be really great. most appreciated.

Marcel
12-28-2003, 02:54 PM
There are several reasons why you get syntax errors:

an if statement needs () around the thing you want to check (I'm not a programmer, so I don't know all the nomenclature :) ) If you want to compare an variable to (for example) 6 you need to use the = two times:

if($i==6) {do stuff}

if you use a single = then you are assigning the value to the variable:

$i=6; means that the variable $i get's the value of 6

If you want to use variables that are 'global' (which means that they exists even when your script is closed down) you need to declare them with the word global in front. If you do not do this Maya will 'forget' the variable as soon as the script is finished;
In this case you would also need to check if the variable already exists because you ran the script earlier. It is much easier to query the displayState from the active panel and use that to switch between smoothShaded and wireframe:

string $currentDisplayType = `modelEditor -q -displayAppearance $currentPanel`;
(returns "wireframe" or "smoothshaded")

Adding it all up I came to this little script:

// get active panel
string $currentPanel = `getPanel -underPointer`;
if ($currentPanel == "") { $currentPanel = `getPanel -withFocus`; }

// get panel display type
string $panelType = `getPanel -typeOf $currentPanel`;

if ($panelType == "modelPanel")
{
// query display type
string $currentDisplayType = `modelEditor -q -displayAppearance $currentPanel`;

// if displayType is not smoothShaded set it to smoothShaded, else set it to wireframe
if ($currentDisplayType != "smoothShaded") {modelEditor -edit -displayAppearance "smoothShaded" -displayTextures on -displayLights "default" $currentPanel;}
else {modelEditor -edit -displayAppearance "wireframe" -displayTextures off -displayLights "default" $currentPanel;}
}


I haven't got a clue what the whole 'MayaCreatorExists' and 'scriptedPanel' stuff does, everything seems to work without those lines. It must be some special type of panel...
The 'wireFrameOnShaded' and 'xray' flags can also be queried with the modelEditor command, so I think it won't be very hard to change this script to toggle Xray on or off.

Levitateme
12-28-2003, 10:13 PM
Wow thanks marcel. thats so great that works. so if i wanted to make another key be like...xray and flat shaded i would just replaces parts of your code? cause clearly i dont get this, my code was like 8 times longer than yours...

Marcel
12-29-2003, 11:01 AM
Here is a small script for toggling the Xray. Because the Xray value is a boolean (means either true or false, with values 0 or 1 ) it can be done a bit simpler. The query can be put into the command that sets the Xray, with a exclamation mark in front:

modelEditor -edit -xray (!`modelEditor -q -xray $currentPanel`) $currentPanel;

The red part queries the current Xray state, and because there is an exclamation mark in front it toggles the value (1 becomes 0 and 0 becomes 1).

Here is the full script:

// get active panel
string $currentPanel = `getPanel -underPointer`;
if ($currentPanel == "") { $currentPanel = `getPanel -withFocus`; }

// get panel display type
string $panelType = `getPanel -typeOf $currentPanel`;

if ($panelType == "modelPanel")
{
// toggle Xray
modelEditor -edit -xray (!`modelEditor -q -xray $currentPanel`) $currentPanel;
}

What did you want to toggle with flatshaded? A button that toggles between flatshaded and smoothshaded? Then you'd just have to take the first script and replace the "wireframe" by "flatShaded"...

Levitateme
12-29-2003, 01:21 PM
Marcel. i truly truly apprecaite you doing all that work. sorry for me just flat out asking. but i really wanted to have them keys...so i just really wanted to show my thanks to you. i was looking at the code to make the viewport turn into xray, noticed it had a value on there also. that is why i couldn't get it to work. so once again thanks a ton. im goign to use these scripts a lot thanks.

Marcel
12-29-2003, 02:51 PM
No problem!

I'm gonna use these scripts too, I always wanted to make them, but never came to actually do it :)

CGTalk Moderation
01-17-2006, 01:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.