New** PSD to LUA +PNG exporter (using Director.lua)

Working on an exporter which uses director.lua as its template. Need to get a few tests on my own CS5 and CS4 at work but its coming along nicely.

http://www.youtube.com/watch?v=Af1-nSr0Tu0

Exports LUA files ready to be used with Director.lua and UI.lua
Exports PNG 32bit

Supports
- _button_ - buttons
+ _default_ - button up state
+ _touch_ -button touched

- Generates handlers and eventlistner code.
- Generates images from normal layers
- Turns PSD groups into CORONA groups
- Merges Groups with _merge_ in the name as one image

Am planning on sharing if people of interested in it..

Features incoming include Spritesheet, video launcher buttons, metadata nesting in PSD layers (e.g. onclick:playsound:blip.mp3),entry tweens e.g onAddedToStage:tweenfrombottom[1.0]

@KevCJones

Consider me interested.

I have been using the exporter provided by Corona, and there was a huge amount of hand editing involved to get things working with the latest UI class, and director.

While the editing would be acceptable for a couple of buttons, for a level select screen with 20 or more buttons, it is very painful.

Drop me a line if you want some testing.

mike at bluerocketlabs dot com

Cheers Mike, will email as soon as I get my own preliminary SC4 and CS5 tests done this end (busy Monday morning at moment though)..expect something this week though.

I agree though, the other exporter is great if your brewing your own format though and just want coordinates. I just wanted to make something which was ideal if like me... you really like the structure director offers and want to have your PNGS ready to go in one click.

Yeah on a complicated PSD you could probably go and make a cup of tea while its saving the images, but is that such a bad thing ;)

That sounds interesting, i'll test as well if you want.

chris at cl-apps dot com

Yes, that's will be useful.

I look forward to it, Kev.

So I only managed to get to do a quickest on CS5 before I left work but it worked after a couple of minor fixes. One being I forgot to force the units to pixels, the other which I need to do a device test tomorrow using it. If my CS4 and CS5 device tests go well I'm going to send out versions for closed group tests. I assume all those interested are CS3 and up. Any Android license holders? I have IOS only on work license.

I also have an Android license.

So I okay here is a version 0.0.3 going up on Github.

https://github.com/KevCJones/Photoshop-to-Corona-Exporter

I haven't used Github before to maintain source like this, I've only ever used SVN but it seems similar so no accidental deletions yet :)

Early testers can download the script plus the PSD which I've been messing around in. NOW I stress this is early days. I haven't tested the following properly myself.

On device =/ I have iOS but work got busy this week so I thought I'd let others have a bash see if it worked well or if its a headache.

I should stress, I used the Director.lua and UI.lua from the monsters and ghosts demo. Updates after that haven't been tested but if you look inside the script you will see how easy it will be for me to do, simple copy + paste and a few escape slashes for return carriages then put in the $injection_hooks.

I like to try and keep my code easy to read but I'm happy to show and tell any bits that don't make sense.

Edit: Last minute thought I chucked in my CPM files for use with the simulator. Test build for 480x320px on landscape.

Please be vocal, good or bad :) lets get this thing on the road to being noticed...

Hello TechnicalSamuraiMac,

Why you are generating "newImage(...)" objects and not "newImageRect(...)" objects for retina support?

Regards.
Francisco.

Both iOS/Android tester here.

Just tried exporting your PSD with Photoshop CS5(mac) and it just crashes Photoshop unexpectedly...

It exports a PNG (backgroundimg.png) to export/images/ then crashes out.

Am I the only one to suffer this so far?

I'll try again in a bit:)

We are also facing the same problem as cl-apps but in Photoshop CS4

Any suggestions ?

We are also facing the same problem as cl-apps but in Photoshop CS4

Any suggestions ?

Hello,

I'm very interested in this exporter, looks great!
But I have the same problem as cl-apps and thewebdepot, the photoshop crashes after exporting "backgroundimg.png"...

Put it down to learning Corona as I create the exporter. Will read up and make the edits in the next version.

Cheers

I'm going to reboot into my Mac now and run a couple of tests... I should of mentioned that at the moment I have been doing more in my windows machine than mac. Its probably just a slash thing... Macs are strict.

Thank you, TechicalSamuraiMac!

Regards!

Okay so a quick test is showing me its because the MAC must use a different script for closing a new document.. when i remove the exporting stages for the PNG's it runs through. I will see if I can patch it quickly and spot the difference between the MAC and Windows JSX for close...

EDIT : Perfect Fix - found the close function syntax...

Fixed but having to try and setup GIT on mac to push the fix so if this keeps dipping me around you can make the fix yourself to the script.

I would only try this if you can read script. Use Ctrl-F to find the code I present below. Search for "charIDToTypeID( "Cls " );"

Find the commands (there are two like this) in the image exporting functions (single and merge versions)

1
2
3
4
5
6
7
8
// =======================================================
       var id247 = charIDToTypeID( "Cls " );
                var desc43 = new ActionDescriptor();
                var id248 = charIDToTypeID( "Svng" );
                var id249 = charIDToTypeID( "YsN " );
                var id250 = charIDToTypeID( "N   " );
                desc43.putEnumerated( id248, id249, id250 );
        executeAction( id247, desc43, DialogModes.NO );

Unfortunately didn't work in CS5... still the same crash at the same point.

If you applied that fix to both functions then could you try to remove the close line using // in both and try that. I will need to install cs5 on mac tonight. I appreciate the tests. I did say early days :)

Okay installing CS5 on a Macbook now and will see if I can spot the issue. Wish me luck...

UPDATE : So CS5 hates close AND back the way I did it.. the hunt continues

Fixed,

I have had to change the way the script works right now. Its a 90% fix 10% workaround.

https://github.com/KevCJones/Photoshop-to-Corona-Exporter

Before the process to export a merged folder was to :

1. merge
2. select all + copy
3. new doc
4. paste
5. save png
6. close (CS5 hates)
7 undo merge (CS5 hates)

BUT CS5 didn't like close OR undo. Removing them, means your PSD remains beaten and there is a ton of untitled windows in PS. SO I have added a clean up function at the end which closes ALL open docs. Not perfect but managable if you know its going to happen.

Later I will add some tests to close all NEW documents which we're created since the export. For now though, could you test your end and tell me if it works. I did the export and ran in the simulator and it works well. I fear now, I need to test on windows again and CS4 and CS3. Although this method is a little simpler and more brutish so in Photoshop coding sense its probably safer :P

Test List open for anyone to assist:

CS5 Mac - PASSED EXPORT - PASSED SIMULATOR - ???? HARDWARE
CS4 Mac - ??
CS3 Mac - ??

CS5 Win -??
CS4 Win - ??
CS3 Win - ??

Thanks Franciso, being newer to Corona i hadn't grasped the difference between the newImage and newImageRect. i changed the exported to use the latter now so Retina display support is feasible.

I actually was thinking if there is a way I could build in an auto saving of the @x2 pngs as a feature of the the Exporter.

Thats me for the night now until the next bug (watch it be windows now), appreciation to the testers for today.

I'll retry again in the morning :) nearly midnight and need some sleep :)

Just trawlin through forums and saw http://developer.anscamobile.com/forum/2011/03/12/crashes-entering-game-menu-htc-desire-hd-works-perfect-android-simulator . If this occurs for now replace images folder string in script with empty "" to export local images to LUA.

SO testing updates showed me my changes to the script broke the windows export SO now i'm going to create two scripts for the moment Win and Mac and maintain them until I find an elegent way to split operations inside like if(WIN)//do win solution etc... will upload the two scripts now hopefully... if GIT lets me.. (the git)

New Scripts : https://github.com/KevCJones/Photoshop-to-Corona-Exporter/tree/master/src

Just test for you platform...

Exported Using | PASS or FAIL

Win CS5 | PASS
Win CS4 | PASS
Mac CS5 | PASS

That being said, I have concerns that long directory names and also system ability to keep up with the large number of operations might be causing crashes so I might do a staged exporting with more alerts to let Photoshop catch its breath.

Merged back into one script...sorry if anyone downloaded the intermediate scripts... don't suppose anyone here has tested either the MAC script or this one on there machines?

Just tried the script on Mac CS5, it crashes Photoshop, I can send you a copy of the error display, plus it launches the script editor when it runs.

him at kevincjones dot co dot uk - the weird part is i've ran it on my MAC OSX with CS5 so its a spot the difference.

Spot the difference time.

I wonder if its directory length (too long maybe PS doesn't like) for a controlled test could you try to run the PSD in a shallow folder called test on the desktop.

Another thought is that it perhaps the Mac OS version? I'm running Snow Leopard on a mac book mini? You?

Not sure what it is that makes it run the script editor but thats not a bad thing. When you run the script it outputs trace messages in the console. I will need to put some more error logging in me thinks..

First let me say, I am so glad you are making this tool. I have tried running it from the root folder, the user folder, and the desktop. I am running a 27inch iMac, Snow Leopard, I have another machine I will try it on to make sure there is not an Adobe configuration issue with this machine. I am using the test.psd file from the latest github package

here is the info from the console, where it stops

Starting the export using version 0.0.38
SCENE - scene1
MERGEDGROUP :scene1->backgroundimg.png
Saving Merged Layer
ArtLayer

Thanks for the support... Photoshop is a weird pedantic child that spits its dummy out a lot it seems :) but we will get there in the end.

I'm going to upload a new script in 5 minutes with a few additions.

try catch block on the main script to see if we can catch it before a full on meltdown.

and a variable or two to turn on/off stages of the process to pinpoint the line it hates.

Your system seems far more spec'd than mine. So not too slow, too fast? :P 5 mins.

New script it up... now i hope the try catch error will stop it from crashing but since I can't recreate the error at the moment I can't tell.

The output console should offer up a version and OS as the first line. I'd like to know what yours says, my OS split might be broke if e.g. yours says Windows... =/

If it fails try again but with

1
var renderImages = false; // turns off image rendering

I have recreated on windows :o with this new try catch its giving me better readouts.. I am going to create a branched version to test with.. when I have a new simpler export version working I will go and try it on the mac too. If CS5 mac and CS3 Windows work I will share...

PS Im also looking at creating a UI panel for this too in the future. Add cool export goodness with progress bars (gasp)...

https://github.com/KevCJones/Photoshop-to-Corona-Exporter/tree/master/src

Please try the CoronaDirectorExporter_newMerge.jsx

I've tried two things.

1. I saw that the export selected layer by name BUT if we had another layer of the same name it would skip to it, this would then fry it in the event that it was a group not a layer... fixed by creating a temp name per layer while exporting and returning it to normal afterwards.

2. I now merge via a different JSX call and call the same save function. Less code and works just the same.

I'm not going to say @.@ its fixed - again.. but it did work on my WIN CS3 and MAC CS5 now.

I will jump for joy if someone manages to get an export. Nothing yet though makes me understand why my machine loves it and others still get hate from it.. if this works I will merge remove the old one and rename this temp testing version.

Hello!
I just tried on an iMac with Snow Leopard with CS5 and it crashes. This are the messages at the consola:
Starting the export using version 0.0.39
Windows
Create folders...
SCENE - scene1
MERGEDGROUP :scene1->backgroundimg.png
temp layer name is 1301588153272
Saving Merged Layer

But runs fine on windows 7 with CS5

Thanks a lot for your job!

Woohoo at least Windows works..... did I mention I'm not actually a lover of macs ;) despite the name.

Spot the difference again, from logs its still something in png save so will add more traces to each step.

Mines an Intel Mac don't suppose thats the difference ? Or that I think I use.extended PS versions on all?

If I have time tonight another build attempt to fix... I'm busy from then till Sunday. If your Windows users, take this version and test it on Android devices for me. ;)

So not much of an update for Mac users i'm afraid. I have added more traces in an effort to spot your own offending code.

https://github.com/KevCJones/Photoshop-to-Corona-Exporter/blob/master/src/CoronaDirectorExporter_newMerge.jsx

It still works on this machine which is running Photoshop v12.0 Extended running on

Model Name : MacBook
Model Identifier: MacBook4,1
Processor Name: Intel Core 2 Duo
Processor Speed: 2.4 GHz

Mac OSX 10.6.6 Build 10J567

I did have one crash randomly and I ran the script again by mistake straight away and it worked from there on out... don't know why. Will run on a couple of Mac's at work and see if any others have varying results... with luck one will...

Updated again - last try until Sunday..

https://github.com/KevCJones/Photoshop-to-Corona-Exporter/blob/master/src/CoronaDirectorExporter_newMerge.jsx

I've removed a lot of code from the auto generator (scriptListener) for PS. Now only use about 3 bits from it.

I will test still tomorrow at work and see if I did it...

Did anyone get a chance to test this on their Mac OSX CS? Still getting successful exports fo myself but would like to try and fix it for anyone whose having trouble.

Cheers

I tried both of the scripts on OSX CS5. The exporter script crashed photoshop almost immediately each time. The new_merge version got considerably further before crashing. I had the Sam experience on Photoshop CS5 on Windows 7 running in parallels. I think the issues is still a Mac issue

UPDATE: Tried the non Merge script just now and it completed succesfully, the Merge script did produce an error!

Tried to export the test.psd again and it crashed photoshop, I didn't do anything differently

@TechnicalSamuraiMac: Yes, exporter now works in CS5 Mac!

However the demo PSD exports fine but the simulator complains of director being missing...

@CL-Apps - Yeah i don't generate Director or UI, if you look in the CPM folder i put up you will see the versions I used, when I update to newer versions of each I will put them in there again.

So hard to fix a script that breaks on some and not on others :/

@Runseld - I had hoped the merge would be the fix all script as my latest one. If you are running the extender to run the script could you possible paste the console output (top right panel) to a post so I could inspect it cheers.

TS

UPDATE: Just exported again and although the exporter complained of files being 'unavailable' I have managed to export a couple of times.

After throwing director.lua, ui.lua and some build settings that set the screen to landscape the demo PSD worked! and the clickable button worked.

Update: Mixed results - First run of Exporter ran without a hitch.
Second Run - errored out with the following message

Starting the export using version 0.0.39
Windows
Create folders...
SCENE - scene1
MERGEDGROUP :scene1->backgroundimg.png
Saving Merged Layer
ArtLayer

Exproter_newMerge results as follows

Error with following output

Starting the export using version 0.0.391
Windows
Create folders...
SCENE - scene1
MERGEDGROUP :scene1->backgroundimg.png
temp layer name is 1301921755483
-- Called savePNGLayer --
--Select the layer by name --1301921755483
--Creating a new document of width and height 480 320
--Pasting the copied clipboard data--
--Resizing the canvas to add padding--
--Save the image as a PNG --~/Desktop/export/images/backgroundimg.png
--Add the file to the close list--
SCENEIMAGE:scene1->title.png
temp layer name is 1301921757465
-- Called savePNGLayer --
--Select the layer by name --1301921757465
--Creating a new document of width and height 368 15
--Pasting the copied clipboard data--
--Resizing the canvas to add padding--
--Save the image as a PNG --~/Desktop/export/images/title.png
--Add the file to the close list--
SCENEIMAGE:scene1->textbody.png
temp layer name is 1301921758486
-- Called savePNGLayer --
--Select the layer by name --1301921758486
--Creating a new document of width and height 271 229
--Pasting the copied clipboard data--
--Resizing the canvas to add padding--
--Save the image as a PNG --~/Desktop/export/images/textbody.png
--Add the file to the close list--
BUTTONGROUP:scene1->test_1_
temp layer name is 1301921759655
-- Called savePNGLayer --
--Select the layer by name --1301921759655
--Creating a new document of width and height 146 35
--Pasting the copied clipboard data--
--Resizing the canvas to add padding--
--Save the image as a PNG --~/Desktop/export/images/exampleBut_touch_.png
--Add the file to the close list--
temp layer name is 1301921760442
-- Called savePNGLayer --
--Select the layer by name --1301921760442
--Creating a new document of width and height 146 35
--Pasting the copied clipboard data--
--Resizing the canvas to add padding--
--Save the image as a PNG --~/Desktop/export/images/exampleBut_default_.png
--Add the file to the close list--
Your file was saved at ~/Desktop/export/scene1.lua
SCENE - scene2
SCENEIMAGE:scene2->Layer1.png
temp layer name is 1301921761257
-- Called savePNGLayer --
--Select the layer by name --1301921761257
--Creating a new document of width and height 480 320
--Pasting the copied clipboard data--
--Resizing the canvas to add padding--
--Save the image as a PNG --~/Desktop/export/images/Layer1.png
--Add the file to the close list--
BUTTONGROUP:scene2->test_2_
1
temp layer name is 1301921763609
-- Called savePNGLayer --
--Select the layer by name --1301921763609
--Creating a new document of width and height 146 35
--Pasting the copied clipboard data--
--Resizing the canvas to add padding--
--Save the image as a PNG --~/Desktop/export/images/exampleBut_touch__1_.png
--Add the file to the close list--
1
temp layer name is 1301921765058
-- Called savePNGLayer --
--Select the layer by name --1301921765058
--Creating a new document of width and height 146 35
--Pasting the copied clipboard data--
--Resizing the canvas to add padding--
--Save the image as a PNG --~/Desktop/export/images/exampleBut_default__1_.png
--Add the file to the close list--

Sidenote - I am still very excited about this tool and really appreciate the amount of work you are putting in to its development

@Runseld - Im glad you are excited. looking at your log i think we're looking at a new issue here, this is crashing after the png exports and this time its probably crashing at the creation of the .lua files.

I'll add more traces tonight or tomorrow and let you know when the new version is ready to test, hopefully we can pinpoint which save it has a problem with.

I wonder IF you make a point of deleting the export folder and its contents and run again does it work again? Might be a write permissions setting on the OS?

Cheers

I was thinking something similar, It will run the test the first time in any folder, after which it will only create a main.lua file and the quit. If I delete the export folder it will either crash or just create a main.lua file. However, I have to restart Photoshop between runs or it will crash right away

Update, to get it to initialize the script I have to change the filename to something new each time. I have tried to find the cache in photoshop and delete, but I am not sure I even deleted the right cache file

views:1896 update:2011/10/13 9:25:17
corona forums © 2003-2011