So ... I went on a bit of a journey once I discovered The Illustrator export script that comes with Spine doesnt include an option to export the JSON like the Photoshop one does. So I decided to write it in using the photoshop script as a guide. I only intended to slap something together real quick in an afternoon, about a week later here we are. Actually I dont know how long it took cause im not quite sure what day it is.
Not only is adobe scripting a pain in the butt but its also highly addictive. Once I got the Json out I thought wouldn't it be cool if it could export the skeleton data as well. And then once I did that I thought wouldnt it be cool if Illustrator had a bone system too that way I could rotate all the joints around in illustrator and fix any overlapping issues right away rather then having to go back and forth between Spine and Illustrator all day long.
So I built that to. Well, I hacked it all together since Illustrator doesnt have a 2d bone system.
Ill upload both scripts as well as a template AI file already configured but heres how it works.
Each "bone" will consist of 4 layers, one root layer, the name of which will be the name of your bone and image thats exported, nothing goes on this layer, its just for control.
And 3 child layers, One will be your artwork, it can be named anything
The other 2 will have a single Point on them made by the pen tool. One Layer will be named Origin and the other Dest.
The XY of the Origin point will the starting point for your bone in Spine, it will also be the pivot point for rotating with the second script.
The Dest point is only used to calculate the bone length and its default angle.
For Ex
Arm_R <
control layer with nothing on it
Origin
Dest
Artwork
Currently there is an issue with rotation not working if Origin isnt the first child layer. It shouldnt need to be but im too lazy to fix it right away. And since it doesnt hurt to make Origin first.....meh
One of the main reasons I wrote the rotation script is Illustrators rotation tool sucks. You can change the pivot point easily enough but you cant save it. I found a tip online to group a single point with your layer and then offset it so the center is located where you want the pivot. But I found this method to be a pain the the butt to work with and prone to failure. So now you can just choose whatever pivot you want by clicking with the pen tool.
One more thing. In order to control bone hierarchy with the rotation script I decided to use the name of the orgin layer as a control mechanism. I originally though to use the layer hierarchy but that would also control the draw order. This way each "bone" control layer is a top level layer and you can order them any way you want.
So.. Origin isnt just Origin it is Origin with a code after it. The code can be anything... sort of , but its alpha sorted so its best to use something like the following example
When you rotate a bone it will rotate any other bone that has an origin layer that starts with the same characters as its own, THis way you can setup any bone hierarchy you want.
For example
Origina = Torso
Originaa = Head
Originab = L Arm
Originaba = L Forearm
Originabaa = L Hand
Originac = R Arm
Originaca = R Forearm
Originacaa = R Hand
So in this case Torso will rotate everything, Head just rotates itself, Larm also rotates L Forearm and L HAnd etc.....
This is just for the rotation script, the json exporter just looks for a layer that starts with "Origin" and ignores the rest. Although it could be utilized to work out the skeleton hierarchy.
One more thing. The json doesnt create the bone hierarchy or assign slots to bones, it just creates the bones and aligns them, you just have to drag and drop that all around in Spine which is pretty easy. There is no reason the exporter couldnt do that though, but there are 2 reasons I didnt.
1) I dont fully know how the math works with Spines Image compensation mode and since the images will be exported in whatever rotated position you drew them in, the bones then applying rotation on top of that screws up the position/alignment.
2) I wrote the JSON exporter before I wrote the rotational tool and thus the hacked bone system. In order to assign parenting youd need to process them in order and I had no way of doing that. But there is code in the rotation script that sorts the array so it would be possible to bring that into the exporter if anyone wants to....
All in all I put way more into this then I thought I would so Im definitely done for now. If anyone else wants to improve it and share the results please feel free. I also didnt include the popup window in the exporter with the options. PNGscale is a hard coded variable at the top, so you can change that if need be. And I commented out some of the other photoshop features that I didnt understand. If they are still relevant to Illustrator they could be added back in. I was just focused on getting it to work.
Also all of the images will be exported to the same folder as the Illustrator file. Since I use so many sub layers I didnt want to make that part of the path..
********** Very Important*********
Illustrator has crashed on me several times, not sure if its just illustrator or if the scripts are a bit heavy, never during an export though, usually when clicking on a layer. So just in case it is the script, SAVE YOUR WORK FREQUENTLY!!!!!! that should go without saving but just in case.
Let me know what your experiences with it are and if you have any suggestions for improvements. I didnt intend to build this much when I started, it was a bit of a journey so the code is a bit messier than it could be.
Also I have a template Illustrator file i was also going to attach but the system wont allow it. I could rename it to something else if thats allowed. Otherwise just make your own template using the above guide.
I see that someone downloaded them both already, wow that was fast. My apologies, I just realized that the Export script was hiding the Dest and Origin layers after it was done with them which isnt good for the rotation tool, so I just uploaded a new version removing those 2 lines of code which were at the very bottom. I recommend using the new one I just uploaded instead.
Also Here are a couple screenshots showing it in action

I uploaded a new version of rotate.jsx. I added reset buttons to each individual bone and a reset all button which resets the slider and angle to 0. This is so you dont have to use Undo a billion times to get back to the original default position. As long as you dont undo any of the rotations yourself the reset buttons will work, otherwise it will be offset by which ever angle you hit undo on.
Also made the text boxes bigger and you can now manually enter the angle you want in the text box.
I was also able to clean up the code a lot, i couldnt figure out how to instantiate all the controls in a for loop and still have the callback functions know which control you were using cause there's no ID or NAME property. I ended up using the helpText property to store the index of each control this way a single callback can be used to control the entire set.
I also wanted to make the window a palette instead of a dialog that way you could interact with the image while the sliders were still up on the screen, but for some reason in palette mode I couldnt access any of the layer properties. If anyone knows why that is let me know and ill change it.
But I did change the targetengine to session that way the sliders preserve their value every time you close and open the dialog. They will be preserved until you close Illustrator so you can move the bones in any position you need to fix your artwork, close the dialog work on the drawing, then re open the dialog when your done and hit the reset button to get back to the default pose.