IntelliJ IDEA, on the other hand, has excellent support for Groovy (QuPath's preferred scripting language) - and can quite easily be set up to work nicely with QuPath. This gives autocompletion and a whole load of other valuable features that makes scripting QuPath a lot more enjoyable and effective.
Note: java qupath.lib.scripting.QP is a Java class that contains various static methods that can be useful during scripting, described here. java qupath.lib.scripting.QPEx could also be used instead, since it contains everything in QP plus a bit more (the 'ex' stands for 'extended').
Since all the methods in both QP and QPEx are imported in QuPath by default, you don't actually need to type them to get the script to run. So in other words the following three lines all do the same:
This sounds simple but there are more details at each step. In the first place, why do you need to clean up resources from the previous execution? The reason for the cleanup is that if a plugin registers, for example, an IDE event listener, there is no way for the garbage collector to know when the listener is no longer used. So there is a common pattern in IntelliJ IDEs to pass an instance of com.intellij.openapi.Disposable class which represents a lifetime of the listener (or some other resource). Each time LivePlugin executes a script, it creates a new pluginDisposable object and passes it to the script. The script then will need to use it with IDE APIs or add an explicit cleanup callback (e.g. using .whenDisposed() function). When LivePlugin unloads the script, or before script is executed again, it disposes pluginDisposable from the previous execution.
The final step is running plugin code. At the JVM level, plugin script is really just a class which can be reflectively instantiated with some parameters (including pluginDisposable). The construction basically runs all the code in plugin.kts (or plugin.groovy) file. This happens on the event dispatch thread (EDT) so it is safe to modify IDE state at the top level of the plugin script (see IntelliJ threading rules). On the other hand, this means that intense calculations or anything like Thread.sleep() should be done on a background thread, to avoid freezing IDE UI. Just like any other plugin it has access to all objects in the IDE JVM, so it is possible to use any functionality from other plugins or IDE itself.
Being able to show notifications or print messages is one of the most fundamental ways to get feedback when using LivePlugin. There is no way to debug plugins with breakpoints because there is only one instance of the JVM. In theory, you could test-drive all plugin functionality, but in practice, many APIs are not very TDD-friendly. So notifications are the most useful way to know why something is (not) working.
Using notifications and tool windows for what is essentially logging is ok on a small scale to get fast feedback, but not ideal for a larger volume of data. There is a logging API based on com.intellij.openapi.diagnostic.Logger which works pretty much as expected appending info/warn/error messages to the IDE log file. And if you want something really simple, you can always use println() which ends up in the IDE log anyway:
All action groups implement the com.intellij.openapi.actionSystem.ActionGroup class. The simplest way to create one is by instantiating DefaultActionGroup, however, when used as a menu item it will add all actions without sub-menu, unless the isPopup property is set to true. For this reason there is liveplugin.PopupActionGroup() which makes the group a popup.
Another option is to display an action group as a popup window. LivePlugin comes with createPopup() extension function which has few useful default parameters and uses JBPopupFactory under the hood. Note that there is a special Separator action in IntelliJ API which represents a separator in the menu.
Writing software is still mostly based on textual representation of code and even though IDEs are good at manipulating syntax tree, being able to programmatically control text editor can be quite useful. This can be achieved using com.intellij.openapi.editor.Editor and Document APIs.
If you feel like experimenting, one of the simplest ways might be to use the current editor without any actions directly in the plugin script. The code below uses caretModel to move cursor to the beginning of the file and selectionModel to select all text:
The next step is to get the word under the caret. The trick here is to use offset from editor.caretModel which represents a shift in characters from the beginning of the current file. There is always a potential for off-by-one errors on the edges around words and beginning/end of file but the code below seems to be good enough for the job.
This happens because modifying the state of a document without a write lock violates IntelliJ Threading Rules. I recommend reading the rules to understand the details, but overall the rules can be summarized by the following table, where ReadAction and WriteAction are classes with static run(ThrowableRunnable) method and in spite of the name are not related to AnAction class and IDE action system described in the section above (yes, naming is hard ?️).
So i tried to make the script to a jar file by going to project structure/artifacts/new jar/empty and i choose the "compile output" file from avaliable elements and then applied the settings. After i build it, i get the jar file and when i start OSBOT i can't find it in the bot scripts...
[INFO][03/21 03:37:41 em]: Started bot #1
[ERROR][03/21 03:37:43 em]: Failed to load local script : Main.class
[ERROR][03/21 03:37:44 em]: Failed to load local script : Main.class
[ERROR][03/21 03:37:44 em]: Failed to load local script : Main.class
[ERROR][03/21 03:37:45 em]: Failed to load local script : Main.class
@obrands Doesn't look like it's a script issue. If the jar is in the script folder and it's not showing up then it's something to do with the compile part. Look at this intellij setup and see if you did anything wrong. Only need to look at part 1
-script-development-setup/?tab=comments#comment-2011973
There are several built-in formats as you can see. Some of them let you export data as a set of INSERT/UPDATE statements, while others export data as text such as CSV, JSON, HTML, etc. For more details on how they work, please visit this page.
For the more complicated cases, consider using scripting extractors. Several of them are already there such as CSV-Groovy.csv.groovy, HTML-Groove.html.groovy, and others. These scripts are written in Groovy, but they can also be written in JavaScript. Our examples use Groovy.
By submitting this form, I agree that JetBrains s.r.o. ("JetBrains") may use my name, email address, and location data to send me newsletters, including commercial communications, and to process my personal data for this purpose. I agree that JetBrains may process said data using third-party services for this purpose in accordance with the JetBrains Privacy Policy. I understand that I can revoke this consent at any time in my profile. In addition, an unsubscribe link is included in each email.
If the main reason you're asking about an external IDE is for some of the nice features that most IDEs have, rest assured we have quite a few tickets in our system to improve our script editor / Python dev environment. It currently does fine, but there are quite a few things we could do to improve things in the future. Although it's a ways off, we will certainly be making some improvements down the road.
Yep, the main reason I'm exploring this is to have a better scripting editor, and not to run Ignition scripts outside of Ignition. In terms of general programming I'm used to working with things like Visual Studio for c#, so I find the functionality of Ignition's built in scripting editors somewhat sparse. And I say that as someone who has also spent a large amount of time developing CimBasic code in the CIMPLICITY HMI, using their built in IDE.
I mentioned IntelliJ as I have been using that as an IDE for learning Java. I have seen references for also using it for Jython (and also CPython) development, but that is predicated on a separate Jython installation being present. In hindsight I'm guessing that Jython is embedded in Ignition and not installed as a separate installation, which makes my question kind of moot.
I'm also vaguely aware that there are requests for better scripting editor support. But I want it now!!!!! Hence my exploring other alternatives (and in the process learning the a lot about what I can and can't do with Ignition)
From what I saw online yesterday, it should be trivial to use IntelliJ IDEA Community edition to support Jython/Python development. It just requires pointing the IDE at the Python installation. And that location was what I was trying to discern yesterday.
we have some steps to get the command line,
After the installation is complete, invoke jython.exe from the bin directory inside the destination directory. Assuming that Jython is installed in C:\jython27, execute the following from the [command line](Jython - Installation - Tutorialspoint. A Python prompt (>>>) will appear, in front of which any Python statement or Python script can be executed.
I'm currently using IntelliJ + Rust plugin. The one thing I miss is Emacs-level extensibility. In particular, as far as I could tell, scripting IntelliJ required building a new Java / Kotlin / Scala project, importing the IntelliJ classes, building a *.jar into a plugin, loading that plugin, and restarting IntelliJ.
c80f0f1006