PDA

View Full Version : Maya - Paste image from clipboard into Maya.


TeriyakiStyle
08-29-2011, 05:21 PM
Hi guys...

What I have so far:

Photoshop:
1.Action Script that saves out a X.jpg into windows/temp

Maya:
2. Script that will call up X.jpg and put it into a surface shader.
3. Script that creates a plane and assigns the above surface shader.

It kind of works. But not elegant or useful as it could be (I am an armchair scripter).

What I want:
1.Simply copy image from Photoshop (or any program) into the clipboard.
2. Script in Maya recognizes the clipboard image and creates a plane. This plane is scaled based upon the clipboards image dimensions (Pixel to Unit). It creates the necessary shader and assigns it to the plane. Essentially pasting the clipboard image into 3d space.


Are there any scripts out there like that? I haven't found any. If there is a scripter willing to tackle this I and I'm sure many other Maya users would be grateful!

malcolm
08-29-2011, 07:39 PM
That would be nice, I find I spend a lot of time creating planes with the exact resolution of a reference image.

TeriyakiStyle
08-29-2011, 10:48 PM
Thanks for the +1 malcolm. I'm asking around a little and it sounds like Mel can't interface with the windows clipboard properly. Maybe Python can though... It seems simple enough! :)

It might be easier to let the Action script create the image file so the script can reference it's dimensions for scaling the plane geometry. I'll try to cobble something hideous together and maybe some handsome angel can swoop in and clean it up.

throttlekitty
08-30-2011, 12:28 AM
Working with the clipboard is beyond me.
But malcom, funkybunnies (http://www.funkybunnies3d.com/tools.php) has a script that automatically creates a properly sized image plane for you.

TeriyakiStyle
08-30-2011, 12:53 AM
waaaa... nice one. I'll have to check that out! Thanks.

TeriyakiStyle
08-30-2011, 02:56 AM
I was happy to find this script from here: http://ndhaussy.free.fr/melScript/importModelingReference.mel

and changed some of the settings, pointed the script to my temp directory:


/*
importModelingReference by Nicolas d'Haussy
Description : Imports a reference image file and place it over a plane in 3d view. Helps in speeding up workflow setup for modeling scenes.
Usage : Just run this script or place it as a shelf button.
*/

string $file = `fileDialog -dm "/windows/temp/*.jpg"`;

if (`exists $file`) { // Check if the user has not "pressed cancel" on fileDialog


// Create a texture material
string $lambert = `shadingNode -asShader lambert`;
setAttr ($lambert+".diffuse") 1;
string $fileTexture = `shadingNode -asTexture file`;
setAttr -type "string" ($fileTexture+".fileTextureName") $file;
connectAttr -f ($fileTexture+".outColor") ($lambert+".color");

// Create a plane with image proprotions to apply the image
float $sizeFactor = 1;
float $imageSize[2] = `getAttr ($fileTexture+".outSize")`;
string $plane[] = `polyPlane -w ($imageSize[0]*$sizeFactor) -h ($imageSize[1]*$sizeFactor) -sx 1 -sy 1 -n (substring(basename($file,""), 1, (size($file)-4))) -ch 0`;
scale -r 1 1 -1 ;
FreezeTransformations;
assignSG $lambert $plane[0];

}


It's very close to what I want. Tomorrow I'll mess with it and get it to try to grab the .jpg without using fileDialog. And then create a copy of the .jpg from temp and save a new one into the maya project directory. That way anything you drop from photoshop, maya will pick up and save a copy to the project. Kind of hacky but getting better.

TeriyakiStyle
08-30-2011, 06:01 PM
http://www.flickr.com/photos/27501768@N08/6097888953/

Here's a video showing how it's working so far. Photoshop outputs a .jpg and maya picks it up and creates a plane with the .jpg assigned.

It uses different updated images, but only for the session or until you reload images. It'd be nice if the script would grab each output .jpg and save it into the project directory somewhere (creating a repository of the reference images you used while modeling). I couldn't figure out how to do it, so maybe later.

Scipt so far:

string $filepath = "C:/windows/temp/ot_001.jpg";

{


// Create a texture material
string $lambert = `shadingNode -asShader lambert`;
setAttr ($lambert+".diffuse") 1;
string $fileTexture = `shadingNode -asTexture file`;
setAttr -type "string" ($fileTexture+".fileTextureName") $filepath;
connectAttr -f ($fileTexture+".outColor") ($lambert+".color");

// Create a plane with image proportions to apply the image
float $sizeFactor = 1;
float $imageSize[2] = `getAttr ($fileTexture+".outSize")`;
string $plane[] = `polyPlane -w ($imageSize[0]*$sizeFactor) -h ($imageSize[1]*$sizeFactor) -sx 1 -sy 1 -n (substring(basename($filepath,""), 1, (size($filepath)-4))) -ch 0`;
scale -r 1 1 -1 ;
FreezeTransformations;
assignSG $lambert $plane[0];

}

haiddasalami
08-31-2011, 09:04 AM
Hey Teriyaki, for any moving stuff python would probably be your best bet. Actually, you could do this all in one swoop with python and photoshop COM. Im kinda swamped right now with summer job crap so will try to get something this weekend.

TeriyakiStyle
08-31-2011, 12:04 PM
Hey thanks for the response haiddasalami! You say I could do it but you're wrong :) a good coder could definitely do it so if you find the time to whip up something slick with Python and COM I would be thrilled.