PDA

View Full Version : Current viewport info


DezFX
01-01-2004, 07:19 PM
Is there a way to extract which viewport is currently active?

I'm trying to create a small (newbie) script that will draw a facited nurbs polygon shape. I'd like it to be intuative like the default "Circle" and "Square" commands where they draw out perpendicular to the current viewport selected. Yet, if the Persp or a non-orthographic viewport is selected, it defaults to the top for creation. Any ideas?

Here is what I have so far:

circle -nr 0 1 0 -r 1 -d 1;
rename "nurbsPoly1";

I'm trying to get rid of the blue code above so that Maya looks for which viewport is active and draws my nurbsPoly1 perpendicular to the active viewport or top viewport if Persp/non-orthagonal is active. Would I use the "getPanel -withFocus;" command in the syntax above to achieve this result? If so, what would be the correct syntax for my script?

Marcel
01-02-2004, 10:40 AM
Here is how to get the active viewport:

// get active panel
string $currentPanel = `getPanel -underPointer`;
// no panel under pointer --> get panel with focus
if ($currentPanel == "") { $currentPanel = `getPanel -withFocus`; }

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

if ($panelType == "modelPanel")
{

// Create object in correct axis:
if($currentPanel == "top") { //create object }
if($currentPanel == "left") { //create object }
// and soforth :)

}

DezFX
01-02-2004, 07:40 PM
OK, thanks for the help...

Here is what I have so far, but it does not seem to be working. Could you help me debug?

*****************
global proc nurbsPoly()

// get active panel
string $currentPanel = `getPanel -underPointer`;
// no panel under pointer --> get panel with focus
if ($currentPanel == "")
{
string $currentPanel = `getPanel -withFocus`;
}

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

if ($panelType == "modelPanel")
// Create object in correct axis:
{
if($currentPanel == "top")
{
circle -nr 0 1 0 -r 1 -d 1;
rename "nurbsPoly1";
}
if($currentPanel == "side")
{
circle -nr 1 0 0 -r 1 -d 1;
rename "nurbsPoly1";
}
if($currentPanel == "front")
{
circle -nr 0 0 1 -r 1 -d 1;
rename "nurbsPoly1";
}
}

******************

I am getting a Syntax Error: $currentPanel = `getPanel -underPointer`;

Any ideas?

ajk48n
01-03-2004, 09:41 AM
You forgot the brackets for the procedure.

It still doesn't really work, since the panels aren't usually named "top", "side", etc. as far as I can tell. It's usually something like "modelPanel5". I'm not sure what to do to fix it, but the bracket things at least gets it to work.

Marcel
01-03-2004, 11:12 AM
I've looked it up, the viewport name that the user sees is called a 'label' and you can get it using:

string $currentName = `modelPanel -query -label $currentPanel`;

It returns stuff like 'Top View' and 'Front View', so the way you test it should work (if you change the text ofcourse).

DezFX
01-05-2004, 12:01 AM
OK guys, thanks. I did not abandon your help, just was out of town for a few days. I will tinker around with it and let you know if I get it working. :thumbsup:

DezFX
01-05-2004, 03:30 AM
Thanks a lot guys! I, with your help :bowdown:, got my first MEL script to work. Now it draws the facited polygon shaped nurbs circle (8 sides) in the current viewport as I wanted it to do! It's not a great tool, but being my first I'm happy to get it working. Here's the final script all put together:

global proc nurbsPoly()
{
// get active panel
string $currentPanel = `getPanel -underPointer`;

// no panel under pointer --> get panel with focus
if ($currentPanel == "")
$currentPanel = `getPanel -withFocus`;

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

// get panel name
string $currentName = `modelPanel -query -label $currentPanel`;

// Create object in correct axis:
if ($panelType == "modelPanel")
{
if($currentName == "Top View")
{
circle -nr 0 1 0 -r 1 -d 1;
rename "nurbsPoly1";
}
if($currentName == "Persp View")
{
circle -nr 0 1 0 -r 1 -d 1;
rename "nurbsPoly1";
}
if($currentName == "Side View")
{
circle -nr 1 0 0 -r 1 -d 1;
rename "nurbsPoly1";
}
if($currentName == "Front View")
{
circle -nr 0 0 1 -r 1 -d 1;
rename "nurbsPoly1";
}
}
}

:beer:

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.