Author Topic: Run process icons programmatically  (Read 184 times)

Offline robyx

  • Newcomer
  • Posts: 25
    • View Profile
Run process icons programmatically
« on: 2019 October 08 14:34:02 »
Hi all,

I'm wondering if PSJR allows to do the following operations programmatically:

1. list the set of process icons existing in the workspace
2. read/update the parameters stored inside
3. open the process dialog (like what happens by double-clicking on the icon)
4. run one instance of the selected process setting the input and output images

Shortly, I would script the operation of dragging a process icon on an image (or just running it if input images are more than one) and control on which target image should be the output programmatically.

Does anyone have an idea if and eventually how to do it?

Thx,
Robyx

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 6842
    • View Profile
    • http://pixinsight.com/
Re: Run process icons programmatically
« Reply #1 on: 2019 October 09 15:33:09 »
Hi Robyx,

Quote
1. list the set of process icons existing in the workspace

The following static function:

Array ProcessInstance.icons()

returns an array with the identifiers of all existing process icons.

Quote
2. read/update the parameters stored inside

ProcessInstance ProcessInstance.fromIcon( String iconId )

This function returns a copy of the instance being transported by a process icon with the specified identifier. Once you get the instance, you can modify it by changing its properties, just as any JavaScript object. For example:

let P = ProcessInstance.fromIcon( "Process01" );
if ( P.processId() == "ImageIntegration" )
{
   P.sigmaHigh = 4.2;
   P.executeGlobal();
}


Quote
3. open the process dialog (like what happens by double-clicking on the icon)

void ProcessInstance.launch()

Continuing with the previous example:

let P = ProcessInstance.fromIcon( "Process01" );
if ( P.processId() == "ImageIntegration" )
   P.launch();


A word of caution here: This should only be done from a script that does not block the platform's event queue. This is a complex topic that I can describe in depth if necessary, but let's keep things simple for now.

Quote
4. run one instance of the selected process setting the input and output images

For example, let's suppose that we have a 'Process01' icon transporting an instance of CurvesTransformation (just to put an example of a process that can be executed on views). You can execute it on the current view very easily:

ProcessInstance.fromIcon( "Process01" ).executeOn( ImageWindow.activeWindow.currentView );

I hope this helps as a starting point. Let me know if you need more information.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline robyx

  • Newcomer
  • Posts: 25
    • View Profile
Re: Run process icons programmatically
« Reply #2 on: 2019 October 10 15:14:53 »
Hi Juan,

thanks for your exhaustive answer, this really helps.

I've got your point about not blocking the platform's event queue, it's a common fact to be taken into account in other platforms too but I'm curious about the specific PI details on how event queue management works and maybe on multithreading (if any relevant detail worths to be explained), since I cannot find anything detailed about it.

Moreover, I guess there is nor documentation neither books specifically addressing the development with PI, correct? The pain point for me at the very beginning was to understand the basic "principles" about the main script and Dialog lifecycle, how the Parameters class works, difference between being executed in global context or on a target view etc...

It would be really worth to have a place that describes at least these fundamentals.

Thx
Robyx

Hi Robyx,

Quote
1. list the set of process icons existing in the workspace

The following static function:

Array ProcessInstance.icons()

returns an array with the identifiers of all existing process icons.

Quote
2. read/update the parameters stored inside

ProcessInstance ProcessInstance.fromIcon( String iconId )

This function returns a copy of the instance being transported by a process icon with the specified identifier. Once you get the instance, you can modify it by changing its properties, just as any JavaScript object. For example:

let P = ProcessInstance.fromIcon( "Process01" );
if ( P.processId() == "ImageIntegration" )
{
   P.sigmaHigh = 4.2;
   P.executeGlobal();
}


Quote
3. open the process dialog (like what happens by double-clicking on the icon)

void ProcessInstance.launch()

Continuing with the previous example:

let P = ProcessInstance.fromIcon( "Process01" );
if ( P.processId() == "ImageIntegration" )
   P.launch();


A word of caution here: This should only be done from a script that does not block the platform's event queue. This is a complex topic that I can describe in depth if necessary, but let's keep things simple for now.

Quote
4. run one instance of the selected process setting the input and output images

For example, let's suppose that we have a 'Process01' icon transporting an instance of CurvesTransformation (just to put an example of a process that can be executed on views). You can execute it on the current view very easily:

ProcessInstance.fromIcon( "Process01" ).executeOn( ImageWindow.activeWindow.currentView );

I hope this helps as a starting point. Let me know if you need more information.