CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
To minimize the ads you see on this page create a CGTalk account and log in HERE
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 12-27-2003, 06:16 AM   #1
Levitateme
Lord of the posts
 
Levitateme's Avatar
portfolio
Tim
USA
 
Join Date: Mar 2003
Posts: 2,023
Wireframe, smooth shade toggle?

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.
 
Old 12-28-2003, 02:54 PM   #2
Marcel
I like Skies!
 
Marcel's Avatar
Marcel Vijfwinkel
Lead Dishwasher
Netherlands
 
Join Date: Apr 2002
Posts: 1,507
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.
 
Old 12-28-2003, 10:13 PM   #3
Levitateme
Lord of the posts
 
Levitateme's Avatar
portfolio
Tim
USA
 
Join Date: Mar 2003
Posts: 2,023
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...
 
Old 12-29-2003, 11:01 AM   #4
Marcel
I like Skies!
 
Marcel's Avatar
Marcel Vijfwinkel
Lead Dishwasher
Netherlands
 
Join Date: Apr 2002
Posts: 1,507
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"...
 
Old 12-29-2003, 01:21 PM   #5
Levitateme
Lord of the posts
 
Levitateme's Avatar
portfolio
Tim
USA
 
Join Date: Mar 2003
Posts: 2,023
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.
 
Old 12-29-2003, 02:51 PM   #6
Marcel
I like Skies!
 
Marcel's Avatar
Marcel Vijfwinkel
Lead Dishwasher
Netherlands
 
Join Date: Apr 2002
Posts: 1,507
No problem!

I'm gonna use these scripts too, I always wanted to make them, but never came to actually do it
 
Old 01-17-2006, 01:00 AM   #7
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:33 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.