Creating a new Tool - ArtStation

Hello, I have created a tool I would like to share with the community, but I built it as a stand alone Java application. It functions in that respect, but I think that it would be most useful as a tool that you could access from the Processing IDE.

I have followed the steps for creating a tool in eclipse to the best of my abilities, and I was finally able to get it to build. But I am very unfamiliar with eclipse and now I just have this “HelloTool.java” file that doesn’t even run. When I try is just says the selection cannot be launched. Did I do something wrong in the set up?

Or if I have a working java application is there an easier way to turn it into a tool?

Thank you for your help!

1 Like

I believe you follow either of these instructions:

Tool Basics · processing/processing Wiki · GitHub

GitHub - processing/processing-tool-template: Processing Tool Template for Eclipse

If the instructions did not work for you, then the docs needs to be updated. Do you have the code in github and publicly available?

Kf

2 Likes

Sorry for the delayed response. I was able to get the example project to work. The issue was on my end, not the instructions. I was using the incorrect sketchbook location, causing the tool to not show up in the tools menu.

Now I will attempt to get it to work with my actual tool instead of the default. Thank you for your response! If I face additional issues, should I add a response here to keep from cluttering the boards, or would a new post be better for visibility?

It did not take very long for me to face additional issues >_<

So I am very new to Eclipse but I am struggling to understand the tool file structure. So say I have a separate package (the one that holds my application) that I want my tool to run. Where in the structure do I need to put my package so that I can access it from the tool? This is my current structure from following the instructions on tool template creation:

structure

Where do I put the code for my application?

Honestly this is the first time I have tried to increase the scope of my project from something personal that I have made to something that can be distributed to others, and I am really lost here.

This is the application that I am trying to incorporate into the tool:
https://github.com/jwilder4690/ArtStationApplication

Perhaps you should take a look on some other PDE tool source code, so you can have a better idea how to pull 1 out as well. :face_with_monocle:

How about this 1: :grinning:

1 Like

I believe you need to change the folder name from template to the name of your tool. Note that I am referring to your your Eclipse screenshot.

Then follow these instructions to add the library to your project: http://www.oxfordmathcenter.com/drupal7/node/44

This is probably not a full solution as more tweaking might be needed it to get it to work.

Kf

1 Like

Thank you both for your assistance getting me pointed in the right direction! With GoToLoop’s help I was able to get a dummy application to launch from the template tool.

Unfortunately there was a compatibility issue with my current application using lamba expressions and newer java version. The instructions state " Remember to compile the tool with compliance to java version 1.7 or 1.8 ( javac -source 1.7 -target 1.7 ) or your Tool will not load properly."

Will using a .jar file allow me to wrap up my application and run on the newer compiler? Or am I going to have to go through my code and make it compatible with 1.8?

At the end here you will find a discussion about Java versions.

I don’t think lambda expressions are supported atm as describe here

Kf

1 Like

Hmmm, getting this to work is proving to be quite troublesome. After replacing all of my lambda expressions, I am able to get the tool to build. But when I run my tool from the processing window I get a very generic error message:

java.lang.NullPointerException
	at artstationapplication.GUI.initializeGUI(Unknown Source)
	at artstationapplication.ArtStationApplication.initSurface(Unknown Source)
	at processing.core.PApplet.runSketch(PApplet.java:10767)
	at template.tool.ArtStation$1.run(Unknown Source)

I don’t have any issues when running the my app independently, only when launched from within the tool, so I am at a loss as to how to debug this. I am also curious about the proper workflow for working on something like this. Currently I am forced to do the full build (30 seconds), boot up Processing (10 seconds) and then attempt to launch my tool. There has to be a better way to see if it will work without needing to do the full build.

  • Lambda is a Java 8 feature. Yet, the PDE can’t compile such code. :-1:
  • However, you can compile code w/ lambda outside the PDE. :wink:
  • You just need to make sure it’s javac -source 1.8 -target 1.8. :face_with_monocle:
  • The PDE can’t use code compiled w/ Java 9 and beyond yet. :poop:
3 Likes

Thank you so much for the tips! :hugs:

I did some practicing exporting and importing jars in eclipse, and I was able to get my application working when imported into a practice project by invoking the main method. Then I tried the same in my tool and it finally works!

Now I just need to do some ironing out the details, verifying that everything is working, and follow the rest of the tool instructions. Soon I should be able to share this with other Processing users! I am super grateful to both of you for helping me along :smiling_face_with_three_hearts:

1 Like

I am back with a new question. I am happily able to launch my application from my processing tool with something that looks like this:

  public void run() {

    System.out.println("Hello Tool. ##tool.name## ##tool.prettyVersion## by ##author##");
    System.out.println("Art Station may take a few moments to launch.");
    
    new Thread() {
        @Override
        public void run() {
        	String[] args = {""};
        	ArtStationApplication.main(args);
        }
    }.start();
  }
}

Using a separate thread for my application allowed me to continue interacting with Processing as normal when my tool was launched. However I get an error when I close my Application window and try to relaunch it from the tool menu. I get:

java.lang.IllegalStateException: Application launch must not be called more than once

Is this because my thread is still running, and therefore thinks that I cannot launch a new app? Is there a way to close my thread when my application closes? Or a better way to do this in general?

Here is my main method. I receive the same error if I duplicate the runSketch() line, so I know that calling the main again is the issue.

    public static void main(String[] args) {
            String[] processingArgs = {"Art Station"};
            ArtStationApplication app = new ArtStationApplication();
            PApplet.runSketch(processingArgs, app);
    }

I am looking for a better way of doing this that allows me to relaunch if the user happens to close my application, so that they don’t need to completely relaunch Processing each time.

Both PApplet.main() & PApplet.runSketch() static methods “ignite” a PApplet as a Thread.

Thread::start() may throw an IllegalStateException:

  1. Thread (Java SE 11 & JDK 11 )
  2. IllegalThreadStateException (Java SE 11 & JDK 11 )

It is never legal to start a thread more than once.

3 Likes

It doesn’t seems to be an issue with restarting the threads, as near as I can tell the JVM is only allowed to call Application.launch() once, and if you call it a second time you get the java.lang.IllegalStateException which I was receiving.

It wont even let me hide and show the application, because I received this error when trying to show it again from the tool run method:

java.lang.IllegalStateException: Not on FX application thread; currentThread = AWT-EventQueue-0

I think the best I can do is just minimize the window when the user closes. It is not my favorite solution, but I can’t think of any other way to make it work.

Process proc = Runtime.getRuntime().exec("java -jar .\\tool\\ArtStation\\tool\\ArtStationApplication.jar");

This only way I have found that will allow me to run my application more than once. Everything else that I have tried either gives me the previously mentioned errors or something similar. I have like four alternative ideas that I tried but nothing works. :sob:

Is this method acceptable? It seems like it will be prone to errors because it is platform dependent and relies on getting the correct path to the jar file. But if I can go this route I will flesh it out and make sure it works.

EDIT:
Nevermind, I got around the issue I had previously with the show call not being on the FX application thread! It looks to be working now!

I sent my links to Elie Zananiri per the instructions in the tool basics, but it also says to post on the forum to let them know about the existence of my tool.

My tool is available here:
https://jwilder4690.github.io/tools/ArtStation/index.html

So I guess now I just wait to hear if everything is good to go.

After working with Elie I have repaired my tool’s project structure. I definitely created it incorrectly initially, which was causing some of my issues.

Now I am facing a new issue using third party libraries. Per the instructions, I need to add any external libraries to my libs folder, and also list them in the classpath in my build.properties file. I did so, but after I launch my tool from within Processing, I receive this error:

java.lang.RuntimeException: The processing.svg.PGraphicsSVG renderer is not in the class path.
at processing.core.PApplet.makeGraphics(PApplet.java:2280)
at processing.core.PApplet.createGraphics(PApplet.java:2188)
at artstationapplication.ArtStationApplication.exportSVGFile(Unknown Source)
(many more lines)...

Did I miss an instruction for using an external library?

My current project is here https://github.com/jwilder4690/Art_Station_Tool