Author Topic: Parameters.isGlobalTarget returns false  (Read 5481 times)

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Parameters.isGlobalTarget returns false
« on: 2013 January 10 11:27:30 »
Hi folks,

Busy writing my first PI script and it's going quite well but I'm having trouble with the Parameters class. I'm using PI 1.7.

Specifically, both Parameters.isGlobalTarget and Parameters.isViewTarget return false so I'm unable to initialise data saved using Parameters.set(). This happens whether I run the script from the script editor or from the Script menu.

Is there a special condition which has to be fulfilled in order to get Parameters.isGlobalTarget to return true?

Here is a much abbreviated code snippet. This is right near the top of the script

Code: [Select]
// Define a data "structure" and create an instance
function DarkMaskLayersData()
{
   this.initialize = function()
   {
      this.outputBlown = false;
      // more data in the real script

      if (Parameters.isViewTarget || Parameters.isGlobalTarget)
      {
         if (Parameters.has("outputBlown")) this.outputBlown = Parameters.getBoolean("outputBlown");
        // more lines in the real script
      }
   }  // End this.initialize

   this.exportParameters = function()
   {
      with (this)
      {
         Parameters.set("outputBlown", data.outputBlown);
        // more lines in the real script
      }
   }  // End this.exportParameters

   this.initialize();
}
var data = new DarkMaskLayersData();

Bob.
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: Parameters.isGlobalTarget returns false
« Reply #1 on: 2013 January 10 11:50:56 »
Parameters.isGlobalTarget is true when the script is executed in the global context. Example: find a script that has an instance icon, drag it to create an icon, right click it, and choose execute in global context. Parameters.isGlobalTarget will be true. In this case, if you need a target then ImageWindow.activeWindow.currentView is a good choice. Be sure to check it for null.

Parameters.isViewTarget is true when a target has been identified for the script's execution. Use Parameters.targetView. Be sure to check it for null (just defensive, should not happen).

If neither is true, then the choice is yours. If you need a target do as in isGlobalTarget and use ImageWindow.activeWindow.currentView.

Mike

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Re: Parameters.isGlobalTarget returns false
« Reply #2 on: 2013 January 10 16:05:04 »
.
.
Parameters.isViewTarget is true when a target has been identified for the script's execution. Use Parameters.targetView. Be sure to check it for null (just defensive, should not happen).

.
.
Hi Mike,

Thanks for the quick reply. Unfortunately Parameters.targetView is null when I test it by inserting the following code snippet into my previous example:

Code: [Select]
      var tim = Parameters.targetView;
      console.writeln("Parameters.targetView = ", (tim == null) ? "Null" : tim.id);
      console.writeln("Parameters.isGlobalTarget = ", Parameters.isGlobalTarget);
      console.writeln("Parameters.isViewTarget = ", Parameters.isViewTarget);

The resultant console output is:
Parameters.targetView = Null
Parameters.isGlobalTarget = false
Parameters.isViewTarget = false

As Parameters.targetView is marked as Read Only that puts me fresh out of ideas. I have tested that the "exportParameters" is working simply by reading back and displaying the retrieved value of one of the saved items. All I am writing is a simple dialog with an OK and a Cancel button and I'd just like a little persistence with the slider settings. :(

Bob.
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: Parameters.isGlobalTarget returns false
« Reply #3 on: 2013 January 10 16:14:37 »
Sorry my post was probably not clear enough.

Use Parameters.targetView only when Parameters.isViewTarget is true.

If Parameters.isViewTarget is false no target view has been specified. If you need a target, you can choose one (per my post) or display an error alert, or whatever.

Mike

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Re: Parameters.isGlobalTarget returns false
« Reply #4 on: 2013 January 10 16:40:20 »
Hi Mike,

Thanks for your patience. Sorry to be dumb but how, programmatically, do I choose a view so that the Parameters calls work? I have a pointers to the active window/image but I don't know how to associate that with the Parameters class.

Bob.
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: Parameters.isGlobalTarget returns false
« Reply #5 on: 2013 January 10 17:12:09 »
Hi Bob,

IMO, to get something working now, don't use Parameters at all.

If you need a view target use ImageWindow.activeWindow.currentView. Display your dialog, let the user specify values and do your work on this target. That's it. No Parameters object usage at all.

Parameter object usage comes into play when instances of your script are created and executed. But just to get something working you don't need to bother with this machinery.

Thanks,
Mike

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Re: Parameters.isGlobalTarget returns false
« Reply #6 on: 2013 January 11 01:29:56 »
Hi Mike,

I'm not ready to give up on this yet. The script is working pretty well but the nature of the processing involved means two of the three parameters (ugh, that word again!) have to be tuned by trial and error so it would be really useful if they were sticky between invocations of the script.

Can anyone offer a reason why both Parameters.isGlobalTarget and Parameters.isViewTarget are returning false near the start of my script?

Thanks.

Update: Maybe it isn't possible as I see that the author of my favourite script (Masked Stretch) has chosen to use the Settings class to achieve the same goal so I guess that's the way to go. Manipulating Windows Registry keys using C++ was never this difficult but I guess that's the price for a platform independent programming environment.

Update 2: And the "Settings" code works a treat. Took half an hour to unpick all that nasty Parameters stuff (!), add suitably modified Settings code and debug. In stark contrast to the half a day it took to fail to get persistent data using Parameters.  ::)

Bob.
« Last Edit: 2013 January 11 02:46:22 by Bob Andersson »
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: Parameters.isGlobalTarget returns false
« Reply #7 on: 2013 January 11 09:35:35 »
Hi Bob,

I am glad you got what you want working!

As you have found, Settings lets multiple script executions share values. Note that this sharing extends between relaunches of PixInsight.

Parameters on the other hand serves a different purpose. If you are familiar with process icons in PixInsight, you will note that multiple icons of the same process (e.g. MultiscaleMedianTransform) have their own, private values for their dialog parameters. Parameters is designed to maintain this state across multiple executions of a particular icon, but at the same time to maintain separate sets of values across multiple icons.

The reason you have up to this point seen the Parameters flags false is because you have not yet created an instance of your script and then executed that instance.

Thanks,
Mike
« Last Edit: 2013 January 11 10:35:03 by mschuster »