Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Screenshot inside maya #MEL

jayantbhatt07
Advocate

Screenshot inside maya #MEL

jayantbhatt07
Advocate
Advocate

Hi, there is any way to screen capture / Screen shot inside Maya using #mel code. I know we can do this by using the snipping tool but I don't want to do that. Any idea?

0 Likes
Reply
Accepted solutions (1)
3,410 Views
15 Replies
Replies (15)

rajasekaransurjen
Collaborator
Collaborator

Hi,

Try this...

string $imageSnapshot = "D:/Img/Snapshot.jpg"; //Set your path here.
refresh -cv -fe "jpg" -fn $imageSnapshot;

jayantbhatt07
Advocate
Advocate

Hi, thank you so much might be this conversation can go longer. The screenshot I'm getting is a bit blur and the screenshot quality is 75 near about. Any Idea?

0 Likes

rajasekaransurjen
Collaborator
Collaborator

Ok...Try this...

string $imageSnapshot = "D:/Img/Snapshot";
setAttr "defaultRenderGlobals.imageFormat" 8;
playblast -st 1 -et 1 -v 0 -fmt "image" -qlt 100 -p 100 -w 1000 -h 1000 -f $imageSnapshot;

 

 

0 Likes

jayantbhatt07
Advocate
Advocate
Hi, Again thank you so much for you help. Here is the rough output which I have been trying to figure out from last 4-5 hours. I modified other Artist script. So, Any mistakes forgive me. Your command is working fine but I have 2 more doubts. (*) If I run your command twice it is replacing the old snapshot which I don't want. Whenever I run the "capture" button It should save new screenshot. ( Because sometimes My model is complex so I have to take multiple screenshots from different angels. (CHECK THE CODE) //Code by rajasekaransurjen { string $sn = `file -q -sn`; string $cfp = `dirname( $sn )`; if (`window -exists ScreenCapture`) //closes window if already open deleteUI ScreenCapture; window -title "ScreenCapture" ScreenCapture; //creates window rowColumnLayout -numberOfColumns 4 -columnAttach 1 "left" 0 -columnWidth 1 40 -columnWidth 50 500; text -label "Path"; textField -w 200 -h 10 -tx $cfp -ed true filepath; button -w 60 -h 28 -label "Capture" -command "Capture"; // show the window we last created showWindow;; } global proc Capture() { string $path = `textField -q -tx filepath`; string $k = ($path + "/snapshot"); string $ff = ".png"; string $node[] = `ls -sl`; { setAttr "defaultRenderGlobals.imageFormat" 8; playblast -st 1 -et 1 -v 0 -fmt "image" -qlt 100 -p 100 -w 2000 -h 2000 -f $k; } clear $node; }
0 Likes

jayantbhatt07
Advocate
Advocate

Would be great if you can check that command here -

 

https://polycount.com/discussion/215147/maya-screenshot-overwrite-mel/p1?new=1

0 Likes

jayantbhatt07
Advocate
Advocate

Would be great if you can check that command here -

 

https://polycount.com/discussion/215147/maya-screenshot-overwrite-mel/p1?new=1

0 Likes

jayantbhatt07
Advocate
Advocate

Would be great if you can check that command here -

 

https://polycount.com/discussion/215147/maya-screenshot-overwrite-mel/p1?new=1

0 Likes

rajasekaransurjen
Collaborator
Collaborator

Ok....Try this..

global proc Capture() 
{
    string $path = `textField -q -tx filepath`;
    string $rsFileList[] = `getFileList -folder $path`;
    int $rsFileCount = size($rsFileList);
    string $k =  ($path + ("/snapshot"+$rsFileCount+".jpg"));
    string $ff = ".png";
    string $node[] = `ls -sl`;
    setAttr "defaultRenderGlobals.imageFormat" 8;
    playblast -st 1 -et 1 -v 0 -fmt "image" -qlt 100 -p 100 -w 2000 -h 2000 -fp 0 -cf $k;
    clear $node;
}
0 Likes

jayantbhatt07
Advocate
Advocate

Hi, thanks as you can see that in the attachment I have made one more text field. I want to give a custom name to that file rather than a snapshot. So I have make a custom string for that right?

 

I know that the string which  I assigned is wrong because I don't know how to query that. 

 

For your help thank you.

 

string $path = `textField -q -tx filepath`;
string $FileName = `textField -q -tx rename `;
string $rsFileList[] = `getFileList -folder $path`;
int $rsFileCount = size($rsFileList);
string $k = ($path + ("/snapshot"+$rsFileCount+".jpg"));
string $ff = ".png";
string $node[] = `ls -sl`;
setAttr "defaultRenderGlobals.imageFormat" 8;
playblast -st 1 -et 1 -v 0 -fmt "image" -qlt 100 -p 100 -w 2000 -h 2000 -fp 0 -cf $k;
clear $node;

 

 

Capture.PNG

0 Likes

rajasekaransurjen
Collaborator
Collaborator

can you share the script for the window "ScreenCapture".

0 Likes

jayantbhatt07
Advocate
Advocate

//Code by rajasekaransurjen


{ string $sn = `file -q -sn`;
string $cfp = `dirname( $sn )`;

if (`window -exists ScreenCapture`) //closes window if already open
deleteUI ScreenCapture;

window -title "ScreenCapture" ScreenCapture; //creates window

rowColumnLayout -numberOfColumns 4 -columnAttach 1 "left" 0
-columnWidth 1 40 -columnWidth 50 500;
text -label "Path";
textField -w 200 -h 10 -tx $cfp -ed true filepath;
button -w 60 -h 28 -label "Capture" -command "Capture";
rowColumnLayout -numberOfColumns 4 -columnAttach 1 "left" 5
-columnWidth 1 40 -columnWidth 50 500;
text -label "Name";
textField -w 200 -h 28 -tx $cfp -ed true filepath;


// show the window we last created
showWindow;;
}




global proc Capture()
{

string $path = `textField -q -tx filepath`;
string $FileName = `textField -q -tx rename `;
string $rsFileList[] = `getFileList -folder $path`;
int $rsFileCount = size($rsFileList);
string $k = ($path + ("/snapshot"+$rsFileCount+".jpg"));
string $ff = ".png";
string $node[] = `ls -sl`;
setAttr "defaultRenderGlobals.imageFormat" 8;
playblast -st 1 -et 1 -v 0 -fmt "image" -qlt 100 -p 100 -w 2000 -h 2000 -fp 0 -cf $k;
clear $node;
}

0 Likes

jayantbhatt07
Advocate
Advocate

Here is the full command.

0 Likes

rajasekaransurjen
Collaborator
Collaborator
Accepted solution

Try this...

proc ScreenCaptureWin()
{ 
    global string $rsTxtPath, $rsTxtName;
    string $sn = `file -q -sn`;
    string $cfp = `dirname( $sn )`;

    if (`window -exists ScreenCapture`) //closes window if already open
        deleteUI ScreenCapture;

    window -title "ScreenCapture" ScreenCapture; //creates window

    rowColumnLayout -numberOfColumns 4 -columnAttach 1 "left" 0 -columnWidth 1 40 -columnWidth 50 500;
    text -label "Path";
    $rsTxtPath = `textField -w 200 -h 10 -tx $cfp -ed true `;
    button -w 60 -h 28 -label "Capture" -command "Capture";
    rowColumnLayout -numberOfColumns 4 -columnAttach 1 "left" 5 -columnWidth 1 40 -columnWidth 50 500;
    text -label "Name";
    $rsTxtName = `textField -w 200 -h 28 -ed true `;

    // show the window we last created
    showWindow;;
}




global proc Capture()
{
    global string $rsTxtPath;
    global string $rsTxtName;
    string $path = `textField -q -tx $rsTxtPath`;
    string $FileName = `textField -q -tx $rsTxtName`;
    string $rsFileList[] = `getFileList -folder $path`;
    int $rsFileCount = size($rsFileList);
    string $k = ($path + ("/"+$FileName+".jpg"));
    string $ff = ".png";
    string $node[] = `ls -sl`;
    setAttr "defaultRenderGlobals.imageFormat" 8;
    playblast -st 1 -et 1 -v 0 -fmt "image" -qlt 100 -p 100 -w 1000 -h 1000 -fp 0 -cf $k;
    clear $node;
}

Use global verifiable for the txtfield.

jayantbhatt07
Advocate
Advocate

Hi, thanks. When I hit the capture button something happens, even when the textfield is empty or blank. So to avoid it I tried to add condition but seems to be like doing something else.

 

proc ScreenCaptureWin()
{
global string $rsTxtPath, $rsTxtName;
string $sn = `file -q -sn`;
string $cfp = `dirname( $sn )`;

if (`window -exists ScreenCapture`) //closes window if already open
deleteUI ScreenCapture;

window -title "ScreenCapture" ScreenCapture; //creates window

rowColumnLayout -numberOfColumns 4 -columnAttach 1 "left" 0 -columnWidth 1 40 -columnWidth 50 500;
text -label "Path";
$rsTxtPath = `textField -w 200 -h 10 -tx $cfp -ed true `;
button -w 60 -h 28 -label "Capture" -command "Capture";
rowColumnLayout -numberOfColumns 4 -columnAttach 1 "left" 5 -columnWidth 1 40 -columnWidth 50 500;
text -label "Name";
$rsTxtName = `textField -w 200 -h 28 -ed true `;

// show the window we last created
showWindow;;
}

 


global proc Capture()
{

global string $rsTxtPath;
global string $rsTxtName;

//HERE IS THE CONDITION


if (textField($rsTxtPath) < 0)
{
confirmDialog -t " Check your object selection. " -b "OK" -bgc 0.8 0.5 0 -ma "center" -m " You have selected several objects. Select ONLY 1 mesh. ";
error "Select The Path";
}

string $path = `textField -q -tx $rsTxtPath`;
string $FileName = `textField -q -tx $rsTxtName`;
string $rsFileList[] = `getFileList -folder $path`;
int $rsFileCount = size($rsFileList);
string $k = ($path + ("/"+$FileName+".jpg"));
string $ff = ".png";
string $node[] = `ls -sl`;
setAttr "defaultRenderGlobals.imageFormat" 8;
playblast -st 1 -et 1 -v 0 -fmt "image" -qlt 100 -p 100 -w 1000 -h 1000 -fp 0 -cf $k;
clear $node;
}

0 Likes