Dear Jason,
Here is the code that works. Observations: I had to put the model into the
Java class directoryand remove blank space from the model file name.
Overall, the ability to control NetLogo 3D from Java is a show. I am truely
thankfull for this feature. It is a great resource for building multiscale
agent-based models.
Sincerely,
Anton
-------------------------
package netlogofromjava;
import org.nlogo.headless.HeadlessWorkspace;
/**
*
* @author Anton
*/
public class NetLogoFromJava {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
org.nlogo.awt.EventQueue.invokeLater(
new Runnable() {
public void run() {
System.setProperty("org.nlogo.is3d", "true");
HeadlessWorkspace workspace =
HeadlessWorkspace.newInstance();
try {
//workspace.open("models/3D/Sample Models/DLA
3D.nlogo3d");
// I had to put the model into the Java class
directory
// and remove blank space from the model file name.
workspace.open("DLA3D.nlogo3d");
workspace.command("set wiggle-angle 70");
workspace.command("random-seed 0");
workspace.command("setup");
workspace.command("repeat 500 [ go ]");
System.out.println(workspace.report("count patches
with [pcolor = green]"));
workspace.dispose();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
);
}
}
Em quarta-feira, 28 de março de 2018 16:52:05 UTC-3, Jason Bertsche
escreveu:
>
> It's possible that that documentation is a bit out of date. It looks to
> me like `invokeLater` was moved to `org.nlogo.awt.EventQueue`
> <https://github.com/NetLogo/NetLogo/blob/c56cffd5b12cf135efc4c3640b3cc0d5dc2acc3c/netlogo-gui/src/main/awt/EventQueue.scala#L11-L13>
> .
>
> On 3/28/2018 2:35 PM, [email protected] <javascript:> wrote:
>
> Dear Seth,
> I am trying to follow your suggestion and the suggesstion from Github:
> https://github.com/NetLogo/NetLogo/wiki/Controlling-API
>
> However org.nlogo.awt.Utils.invokeLater does not have the class Utils.
>
> I am using Netlogo 6.0.2.
>
> Any suggestion on what to import?
>
> public static void main(String[] args) {
> org.nlogo.awt.Utils.invokeLater(
> new Runnable() {
> public void run() {
> System.setProperty("org.nlogo.is3d", "true");
> HeadlessWorkspace workspace = HeadlessWorkspace.newInstance() ;
> try {
> workspace.open("models/3D/Sample Models/"
> + "DLA 3D.nlogo");
> workspace.command("set wiggle-angle 70");
> workspace.command("random-seed 0");
> workspace.command("setup");
> workspace.command("repeat 50 [ go ]") ;
> System.out.println(workspace.report(
> "count patches with [pcolor = green]"));
> workspace.dispose();
> }
> catch(Exception ex) {
> ex.printStackTrace();
> }}});
> }
>
>
>
>
> Em terça-feira, 23 de janeiro de 2018 20:18:35 UTC-2, Seth Tisue escreveu:
>>
>> I'm not sure if it's been tried before. I think it will probably just
>> work if you do:
>>
>> System.setProperty("org.nlogo.is3d", "true");
>>
>> before calling App.main. It's worth a try.
>>
>> Seth
>>
> --
> You received this message because you are subscribed to the Google Groups
> "netlogo-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> For more options, visit https://groups.google.com/d/optout
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_optout&d=DwMFaQ&c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&r=sxGjFFyk2A6rYHwAdDtnqeTKj3cEcXDGDo_G9va2ruI&m=0c3kzH0iHFAeOFwpAOkh503czEd7r7IQrVY5Pz4aTrk&s=GERLCF_kNnFQ1wptlm133JSmWrsmrQKpy8Yjl9ajceU&e=>
> .
>
>
>
--
You received this message because you are subscribed to the Google Groups
"netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.