How to get id of View that has multiple copies?

dmccallie

Member
Another newbie PJSR question:

I have a script that is using PixelMath (and other tools) to create new images, as combinations of previous images.
There are occasions when I create a second new image with the same name as an existing image.
PJSR handles this nicely by appending a number to the end of the view name (as displayed in the title bar) to distinguish the new view from the similarly named previous view.

So I might end up with a view whose title reads "HOO" and another instance with title "HOO1"

However, when I go to find the name of the new view whose name is "HOO1", the code always returns just the "HOO" part.
In other words, both View.id and View.fullId return just "HOO" even when pointing to the "HOO1" view
Of course View.uniqueId returns the UUID string, but that doesn't help me get the display name of "HOO1" or "HOO2", etc.

I am sure I am doing something wrong, but I can't find the right way to get the full name as displayed on the view's title bar?

Thanks.
David McCallie
 
I think there is something wrong in the way you're referencing your images since any view must have an unique ID, disregarding the containing Window ID.
This means that when you say "even when pointing to the HOO1 view" are you sure you're really pointing at it?

an example trying to reproduce the issue you've described that runs PixelMath twice on the same image and prints the id and fullId calues of the two images (which are unique and correctly assigned):

JavaScript:
let w = new ImageWindow(4000, 3000,1, 32, true, false, "MAIN");

var P = new PixelMath;
P.expression = "$T";
P.expression1 = "";
P.expression2 = "";
P.expression3 = "";
P.useSingleExpression = true;
P.symbols = "";
P.clearImageCacheAndExit = false;
P.cacheGeneratedImages = false;
P.generateOutput = true;
P.singleThreaded = false;
P.optimization = true;
P.use64BitWorkingImage = false;
P.rescale = false;
P.rescaleLower = 0;
P.rescaleUpper = 1;
P.truncate = true;
P.truncateLower = 0;
P.truncateUpper = 1;
P.createNewImage = true;
P.showNewImage = true;
P.newImageId = "MYID";
P.newImageWidth = 0;
P.newImageHeight = 0;
P.newImageAlpha = false;
P.newImageColorSpace = PixelMath.prototype.SameAsTarget;
P.newImageSampleFormat = PixelMath.prototype.SameAsTarget;
/*
 * Read-only properties
 *
P.outputData = [ // globalVariableId, globalVariableRK, globalVariableG, globalVariableB
];
 */

P.executeOn(w.mainView);
P.executeOn(w.mainView);

w.forceClose();

let myid = ImageWindow.windowById("MYID");
let myid1 = ImageWindow.windowById("MYID1");


console.noteln("myid.mainView.id      : ",myid.mainView.id);
console.noteln("myid.mainView.fullId  : ",myid.mainView.fullId);
console.noteln("myid1.mainView.id     : ",myid1.mainView.id);
console.noteln("myid1.mainView.fullId : ",myid1.mainView.fullId);
 
Roberto,

Thank you for responding in such detail.
(And thank you for your excellent YouTube presentation on how to script Pixinsight:
)

You are correct that I am pointing to the "wrong" window, when I ask it for it's Id.
In your example, you know in advance what the name should be, so you can call ImageWindow.windowById("MYIDn") to find the window that you expect to be there.

Where I am running into trouble is that I don't know in advance what the full name ought to be, since I (currently) have no way to know how many times the user might have run the PixelMath routine that creates the new window. It could be MyID1, MyID2, MyID3, etc.

So I think my question ought to be "How do I find the name of the window/view that PixelMath just created for me?"

What does NOT work is to query the value of P.newImageId() right after the P.executeOn(w.mainview) has been run. That was my mistake, as that will simply return "MyID" over and over.

Is there any easy way to find the name of the View that was just created by the script?

Thanks for all your help!

--david
 
I think you have to approach it differently; what you describe is what happens manually:
1. you instantiate your PixelMath with an expression (using $T I guess)
2. you let PixelMath create a new image as a result
3. you apply PixelMath on the source image and it creates the new result image
4. now you have to find the created image...

I would to the following instead:
1. I create the result window programmatically
2. I instantiate PixelMath and use the source image id instead of $T
3. I run P.executeOn() passing the result window
4. at this point, the result is stored in the window created in point 1

Does this work?
 
... or, generate a name you know to be unique and pass this as the newImageId parameter with createNewImage set to true. The code snippet below will generate a unique name for you.

JavaScript:
//----------------------------------
// get a unique name for a new image|
//----------------------------------
function getNewName(name)
{
   var newName = name;
   let n = 1;
   while (!ImageWindow.windowById(newName).isNull)
   {
      ++n;
      newName = name + n;
   }
   return newName;
}
 
Thank you Robyx and Mike,

Programmatically creating the output window will certainly work. I was being lazy hoping to save a step and let PixelMath create the window. I now see the limits of the lazy approach :(

And getNewName() is now a nice addition to my code.
Thanks!

--david
 
Back
Top