PDA

View Full Version : screen resolution


fritz8th
02-14-2008, 12:47 PM
Hey everyone,

Strange question but is it possible to find the screen resolution using mel or python. I have a gui that I need to show up full screen but if each user has a different screen resolution it wouldnt show up full screen. I tried using this

int $winSize[] = `window -q -wh MayaWindow`;

but this will only give you the size of the maya window wich when full size is not the same size as the screen resolution . So any help or ideas would be great.

Thanks

Dan.

GiantG
02-14-2008, 07:24 PM
Hi.

I can't give you a general Solution because it depens on the Operating System and the Language of the OS.

This command will generate a Text File with the Name of your Computer that contains all the Information about your Display Hardware.
Now you can parse this File and search for The Display Resolution.
The Path of this File can be set with $path

string $path = "c:\\temp\\";
string $cmd0 = "\"\"%CommonProgramFiles%\\Microsoft Shared\\MSInfo\\MSINFO32.EXE\" /report ";
string $cmd1 = $path + ".\\%COMPUTERNAME%.txt /categories +ComponentsDisplay\"";
string $FullCmd = $cmd0 + $cmd1;
system $FullCmd;

Cheerz...

fritz8th
02-17-2008, 03:07 PM
Hey Gaint G

Thanks that worked like a charm. Yeah sorry should have listed the OS would have helped a little hu.

Thanks
Dan

Dontnoun
12-29-2008, 11:46 AM
I got same problem last week,maybe we can not directly get screen resolution by mel command,I was guess maya know that information,but it was not want to tell us, so I have to tortured maya ,then maya told me what I want,the torture as follows:

global proc int[] get_screen_resolution(){
int $scren_resltin[]; if (`window -exists tst_scrn_rsltin`) deleteUI -window tst_scrn_rsltin;
window -wh 999999 999999 tst_scrn_rsltin; showWindow tst_scrn_rsltin;
$scren_resltin = `window -q -wh tst_scrn_rsltin`; deleteUI -window tst_scrn_rsltin;
return $scren_resltin; //get screen resolution by overflow attacks ------Lyone 29,12,2008 Dontnoun
}get_screen_resolution;

ewerybody
12-31-2008, 09:18 AM
hey Dontnoun! thats pretty cool :)
I was looking for a soultion for that too and laughing my ass of as I saw maya returns size of a maximized window like its not maximized.. :D
but the MSINFO32.EXE-thing looks interesting as well. Nice tips!
have a nice NYE everyone!!

gozzer
07-13-2009, 12:16 AM
I realize this thread has been dead for a while, but I recently came across the same problem when dealing with the user's screen resolution. Since there was no apparent solution to the problem, other than the tips that were listed here, I thought I'd summarize what we did to make it (seemingly) work.

Going through some VBS Q/A online, I found a quick little script that works okay-ish on Windows. Using MEL, this piece of VBS get written to a temp file and executed, by calling the following procedure:
// Procedure that will grab the screen resolution on a windows machine
global proc int stereo_getScreenResWin() {

// declarations
string $stereo_screenResRaw;
string $stereo_screenResArray[];

// temporarily write the vbs script to a file
$stereo_tmpFile = (`internalVar -userTmpDir` + "tmp_screenRes.vbs");

if (!`filetest -f $stereo_tmpFile`) {
$stereo_fileId=`fopen $stereo_tmpFile "w"`;
fprint $stereo_fileId "strComputer = \".\"\n";
fprint $stereo_fileId "Set objWMIService = GetObject(\"winmgmts:\\\\\" & strComputer & \"\\root\\cimv2\")\n";
fprint $stereo_fileId "Set colItems = objWMIService.ExecQuery (\"Select * From Win32_DisplayConfiguration\")\n";
fprint $stereo_fileId "For Each objItem in colItems\n";
fprint $stereo_fileId " Wscript.Echo objItem.PelsWidth & \" \" & objItem.PelsHeight\n";
fprint $stereo_fileId "Next\n";
fclose $stereo_fileId;
}

// execute the script and grab the result
$stereo_screenResRaw = `system("cscript " + $stereo_tmpFile + " //Nologo")`;
$stereo_screenResArray = stringToStringArray($stereo_screenResRaw, " ");

// clean up
// not really needed right now, since we're trying to re-use the file if it's there...

// return the horizontal pixelvalue
return $stereo_screenResArray[0];
}

On a Mac, things were a bit more flexible, and using system_profiler and grep, the following procedure returns the resolution of the first monitor it encounters:
// Procedure that will grab the screen resolution on a Mac OS X (Intel) machine
global proc int stereo_getScreenResMac() {

// declarations
string $stereo_screenResRaw;
string $stereo_screenResArray[];

// issue the command, and retrieve the reply
$stereo_screenResRaw = `system("/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution")`;
$stereo_screenResArray = stringToStringArray($stereo_screenResRaw, " ");

// return the horizontal pixelvalue
return $stereo_screenResArray[1];
}

Not entirely trusting the return of these system calls, we still set our default horizontal pixelvalue, and if the return from the proc(s) is valid, overwrite the initial value:
// Default offset, if screen res test fails
int $stereo_offset = 1920;

// Attempt to read the screen resolution of the main monitor
int $tmp_res;

if (`about -win`) {
$tmp_res = `stereo_getScreenResWin`;
} else if (`about -mac`) {
$tmp_res = `stereo_getScreenResMac`;
}

// write the new value to the global container if it's valid
if (isValidString($tmp_res, "[0-9]+") && $tmp_res > 0) {
$stereo_offset = $tmp_res;
}

The reason for only grabbing the horizontal pixelvalue (width) of the display, is that we're creating an offset where all consecutive windows (created by the script) place themselves on the secondary monitor (2xHD widescreen for stereo projection).

Anyway, as mentioned, I'm just posting this in case someone else may come across the same problem and find this information useful. :-)

Cheers,
Daniel

CGTalk Moderation
07-13-2009, 12:16 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.