Is it possible to export scene to a file via script

General discussion about the R.U.B.E editor
Post Reply
dagondev
Posts: 6
Joined: Sat Jul 12, 2014 8:01 pm

Is it possible to export scene to a file via script

Post by dagondev »

Hi,

my question is as stated in subject. I made some hacky support for layers. I`m not going into details, but it is important that every body has custom property: layer. With value from 0 to 3.
And I need to export every layer to separate json.
So for now I am using script that removes all bodies except specific layer, then I am manually exporting scene to json, then undo script execution (by ctrl+z) so I can have all layers again. And then specify another layer in script and so on...
As you can see it is not effective way, especially when I am testing something on all layers. So is it possible to make this process by script/other way automatic?

Script:

Code: Select all

body[] bodies = ab();
for (uint i = 0; i < bodies.length; i++) {
body b = bodies[i];
if(b.layer!=2) {
	b.delete();
}
}
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Is it possible to export scene to a file via script

Post by iforce2d »

Yes, it can be automated. Scripts inside the editor cannot trigger an export directly, but you can use the command line interface to open a file, run script(s), and save/export the result. This is useful for dealing with many files in a large batch. For an example usage you can see this video, from around 7:32
https://www.youtube.com/watch?v=XM_yYvk3AKk

In the built-in help, search for "command line".
dagondev
Posts: 6
Joined: Sat Jul 12, 2014 8:01 pm

Re: Is it possible to export scene to a file via script

Post by dagondev »

Thank you, works like a charm!
Post Reply