2d Cutout Image Import Script

Hi.

When preparing images for cutout animation (say, a character) it is convenient to work on a single PSD file to see all the pieces match but then when you have to export every layer as a different image which is tiring.
There are some scripts that automatically export layers as individual images but they would not respect the actual size of the layer. All of them would be the same size. When importing them into blender it doesn´t look nice.

I made a little javascript for Photoshop to help me with that. I post it here in case it can be useful for anybody. I would have liked to do it in python for gimp but it seemed compicated and I didn´t find good documentation (even the pygimp installation seems difficult)…

One more thing. I have been using your script a little bit and there is a feature I would like it to have (if it doesn´t, yet): The materials that are generated don´t have the trasparency shadows option on by default so one has to manually change that to have the planes reciveving siloueted shadows instead of just rectangles…

Congratulations again.!


  /////////////////////////////
  // 
  //  ALL_layersToFiles.js
  //
  //    phostoshop javascript to export layers in a PSD as different PNGS with the right image size each, so no manual cropping is needed.
  //    Prepare your cutout character on photoshop, run the script and then  you can import the PNGS into blender. tested on photoshop CS3
  //    The script will make a folder for every opened document in photoshop and export them into layers. Your psds must have been just saved. Works better if all layers are visible. Experimental script use at your own risk etc.
  //    

displayDialogs = DialogModes.NO;

saveOptions = new PNGSaveOptions();

for (q =0; q<= (documents.length);q++){

	if ((documents.length != 0) && (activeDocument.saved)){
		
		var AD = activeDocument; 
		$.write ("*****************");
		$.write ("
");
		$.write (AD.name);
		$.write ("
");
		var CurrentFolder = AD.path;
		var newFolder = AD.name+"_separated"
		var tempFolder = new Folder (CurrentFolder+"/"+newFolder)
		tempFolder.create();

		var tempLayer = AD.artLayers.add();
		var checkArray = new Array(AD.layers.length);

	  for(a=1;a<=AD.layers.length;a++){//Para cada layer comprueba si es de texto y actua en consecuencia
		var CL = AD.layers[a-1];
		if(!((CL.kind == LayerKind.TEXT)||(CL.kind == LayerKind.NORMAL)||(CL.kind == LayerKind.LayerSet))){
			checkArray[a-1] = 1;
		}
		if(CL.visible == 0){
			checkArray[a-1] = 2;
		}
	}


	  for(a=1;a<=AD.layers.length;a++){//Para cada layer	los esconde
		AD.layers[a-1].visible = 0;
	  }

	  for(a=2;a<=AD.layers.length;a++){//Va mostrando de uno en uno

		AD.layers[a-2].visible = 0;
		AD.layers[a-1].visible = 1;

		if((checkArray[a-1]!= 1)&&(checkArray[a-1]!= 2)){	
			//newFile = new File(tempFolder+"/("+(a-1)+")_"+AD.layers[a-1].name+".png");
			newFile = new File(tempFolder+"/"+AD.layers[a-1].name+".png");//mejor naming
			//Aqui esta el meollo en lugas de save as hay que seleccionar los bounds del layer, copiarlo, crear una nueva
			// y pegarlo antes de salvar
			$.write (AD.layers[a-1].name);
			$.write ("----->");
			$.write (AD.layers[a-1].bounds);
			$.write ("
");
			var bunds = (AD.layers[a-1].bounds);

			AD.saveAs (newFile,saveOptions, true, Extension.LOWERCASE);
			var cropeable = open (File (newFile));//       *********+     esto es mio
			cropeable.crop (bunds); 
			cropeable.save();
			cropeable.close()
		}


	  }

	  for(a=1;a<=AD.layers.length;a++){
		if(checkArray[a-1] == 2){
			AD.layers[a-1].visible = 0;
		}else{
			AD.layers[a-1].visible = 1;
		}
	  }
	  AD.layers[0].remove();

	}else{
		alert("You either did not save the document or have no document opened !");
	}
	AD.save();
	AD.close();
}

Hey thanks for the script! I don’t have PS so I can’t test it (I use Gimp) but it should be a nice companion to this script.

I actually started working on an update that will allow you to have any materials options you want set by making a template material and then having the script copy that onto all of the imports (with proper image mapping of course). Unfortunately, I don’t know when this update will be finished since I’m quite busy right now. Adding the actual functionality should not be extremely difficult when I start to tackle it, but I’ve also had to redo the GUI to make it usable which is taking longer than I expected since I didn’t design the original GUI to be as easily changeable as I’d like (which I’m in the process of redesigning it somewhat in terms of its look and organization as well as the code).

just Thank you. A lot. :wink:

I just love that script! It have been so useful! I have i little request, for anyone who can help.
This script could be a third option “load sequence”, for apply in a plane a sequence of images . Actually I do that creating the plane and use the regular tools.
I think that will be nice.

I found a solution for this problem, I don’t know if will help you, I hope so! (works for me):

http://blenderartists.org/forum/showthread.php?t=114409

So the feature would be to take a directory of images and then apply them to a single plane, correct? Could you elaborate a little more on this, like how you presently do this and perhaps what the end result looks like?

Could you elaborate a little more on this, like how you presently do this and perhaps what the end result looks like?

I will try to elaborate a little bit more. The feature will work mos like the function “sequence” in the texture buttons (F6). When you select a single image and click on the “sequence” options. So, if I select the image “sample_0001.png” they recognizes all the images with the same name “sample_*.png” as part of a filmstrip in the same texture.

So the feature would be to take a directory of images and then apply them to a single plane, correct?

Not all images in directory, but yes, the images go to the same plane.

I can send a .blend to you if you wanted.

I’d appreciate a .blend, thanks.

Well, i post in media fire one sample for you.

http://www.mediafire.com/?ymjqzxztg9l

(sample2d.zip)

Thanks for the script forTe, it looks really useful!
Anyway I’m not finding the Alpha button and the Texture Face panel.
I’m using one of the latest SVN.
I assume that the UV select mode is now called Texture Paint. Am I right?

TIA

UV Edit Mode was integrated with general Edit Mode. The Texface panel should now appear when your in your mesh tools buttons in edit mode, but you have to have a UV layer.

In RC2, though, I don’t see any options in it (and the way the panels operate is messed up as well), so not sure why its there or if something is going wrong :(. It works in the SVN builds from a couple days ago, though. :slight_smile:

Bump For a New Version :D:

Version 1.2 Here

Features:

  • Offsets, making it so that each plane is offset by a certain amount from the last imported (i.e. they’re not all imported to the same location)
  • Material Templates (i.e. you make a material and then its copied to all of your imported images with the proper texture and name)
  • Import as a sequence (only for single images). Should be about the same as you would set up in the normal image panel.
  • Pack images into the blend file (for single and multiple image imports).
  • Refreshed UI

The only issue is that the UI is getting cramped with some of the feature creep. The next revision (hopefully it won’t take another year) should have a new UI thats much smaller, but less cramped, probably a tabbed interface or something. I also want to try to get it so it can import multiple directories at a time. I don’t know the feasibility at this point necessarily, but I’ll certainly look into it.

Let me know if you find any bugs as well. I’ll try to hammer them out ASAP.

If any Wiki Scripts Catalog maintainers see this post, I’d appreciate it if you would update the entry there!

Thanks for looking…

hi forTe,
wiki updated,
i’ll try to add proper docs & images soon.
very very useful script!
Also, I found this Video Tutorial here:

I simply don’t know how to express my gratitude.
The script are much better now!

I use this script a lot and the image sequence fits like a glove in much of my work.

For now I have only two observations:

1- Since blender work with premul default off, we could use this option (a premul button) to the script. Otherwise I have to turn they on one by one (a very boring task to do).

2- Another default option is the repeat texture, that option creates a little edge when I use the hand drawing animation in blender. the solution is change that to the extend option (that option extends the alpha of my png images), this can be a option in the script. Otherwise I also have to change one by one.

Can you do it? p-p-p–p-please!

Thanks one more time!

This is not available with the current API as far as I can tell. I’ve added an option to the API on my own build that lets this be possible. Its literally two lines of code (plus a line of documentation). I can submit a patch if none of the devs read this and go and add it to the API.

2- Another default option is the repeat texture, that option creates a little edge when I use the hand drawing animation in blender. the solution is change that to the extend option (that option extends the alpha of my png images), this can be a option in the script. Otherwise I also have to change one by one.

That will be relatively easy to add. I’ll do it tonight and release a small update.

On a side note, the first issue likely can be fixed in a non-blender-source-code editing way. My ultimate goal is to have template materials and textures, rather than just trying to reinvent the wheel and recode the texture button panels. It’d likely take me some time to fully edit the script for this, but it would be possible.

Edit: Change 2 has been made…

See for version 1.2.1:
http://gamulabs.freepgs.com/blends/scripts/2dcutout.py

Thanks a lot forTe!

I can manage the premul problem for now. If I find some trouble in my work I’ll scream for help! =)

A great hug!

Thank you so much , this script is awesome , now i can do after fx like stuff faster , it saves sooooo muach time.

Thanx !

such a cool script, thanks for the update on the repeat-texturing forTe :slight_smile:

This is freaking amazing! I would love to see this incorporated in the next version of Blender it’s that useful.

I’ve been looking for a way to use Blender to do layering with planes and rid myself of After Effects and this looks like it could do it.

One problem though I can’t seem to get it installed properly. I’m using OSX and I’ve simply dragged it into my scripts folder. But when I start up blender it’s not within the scripts dialog. Am I doing something wrong? This is where all my other scripts are…which menu is it under Import?

sorry for the noob question

First off I’d like to say that this is HUGE!

I’ve been looking to move from working primarily in After Effects to entirely on Blender for simple plane layering and so on. Unfortunately I can’t figure out what I’m doing wrong when I try to install this script. I’m using OSX and putting the .py file into my scripts folder but it doesn’t seem to be appearing in the scripts dialog.

what am I doing wrong?

sorry for the noob question.

Never mind… I found it.
damn mac hidden folders