Menu

#869 Support for JavaScript scripting in SH3D (Nashorn or Rhino)

Future_Release
open
nobody
plugin (1)
5
2018-02-18
2018-02-18
No

Please, add support for JavaScript scripting directly from SH3D.

Workaround: run SH3D using Nashorn shell (builtin in Java8) or Rhino Shell.

Example:

Create copy of SH3D startup script and replace com.eteks.sweethome3d.SweetHome3D with jdk.nashorn.tools.Shell , then run this script.

In Nashorn command line write:

// Load XRay function for introspection of JavaObjects (optional)
load('https://gist.githubusercontent.com/lorenzoongithub/7273902ac628b2761f46de2d0c2a31cd/raw/a80b9369f3b63517da5eba4d962d3632cc26882c/xr.js');

// Extend class to access protected methods
var extended = new (Java.extend(Java.type("com.eteks.sweethome3d.SweetHome3D"), { create_instance: function() { return Java.super(extended); } }));

// Run SweetHome3D
extended.init([""]);

// Open your home in SH3D window...

// Do what you want
var h=extended.homes[0];
h.name;

var f=h.furniture;

// Print coordinates of furniture
for(var i in f) { print("i="+i+", name="+f[i].name+", x="+f[i].x+", y="+f[i].y); }

// Round coordinates of furniture
function toInt(n){ return Math.round(Number(n)); }
for(var i in f) { f[i].x=toInt(f[i].x); f[i].y=toInt(f[i].y); }

// Etc.

2 Attachments

Discussion


Log in to post a comment.