Page 1 of 1

Is it possible to export scene to a file via script

Posted: Mon Nov 03, 2014 10:44 pm
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();
}
}

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

Posted: Mon Nov 03, 2014 11:28 pm
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".

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

Posted: Thu Nov 06, 2014 10:56 pm
by dagondev
Thank you, works like a charm!