Can I get the filter name from a view?

jamiesmithnc

Well-known member
In my processing I tend to rename my views to like "Red", "Green", etc., which makes many of the other processes quickly repeatable.

This is my first endeavor with PI scripting...

I threw together a (very fragile) script that changes the ID for a file based on an "indexOf", but what I'd rather is grab the filter name out of the properties or FITS headers (wherever I can) and use that instead.

Is there a way to do that? In the long run I'd like to be able to:
  • have it iterate all open views in the current workspace
  • include a prefix or suffix

Thanks,
-jamie

My script thus far is:
Code:
function getFilter(view)
{
   newId = "WTH";
  
   if (view.id.indexOf("Lum") > 0)
   {
       newId = "Lum"
   }
   else if (view.id.indexOf("Red") > 0)
   {
       newId = "Red"
       Console.writeln("ZZZZ");
   }
   else if (view.id.indexOf("Green") > 0)
   {
       newId = "Green"
   }
   else if (view.id.indexOf("Blue") > 0)
   {
       newId = "Blue"
   }
   else if (view.id.indexOf("Sii") > 0)
   {
       newId = "Sii"
   }
   else if (view.id.indexOf("Ha") > 0)
   {
       newId = "Ha"
   }
   else if (view.id.indexOf("Oiii") > 0)
   {
       newId = "Oiii"
   }
   else
   {
      newId = "WTH";
   }

   return newId;
}

function main()
{
   if (Parameters.isViewTarget)
    {
        filter = getFilter(Parameters.targetView);
        Parameters.targetView.id = filter;
    }
}

main();
 
I was able to figure it out using a couple of the view methods, now it's a lot cleaner, too!
JavaScript:
function main()
{
    if (Parameters.isViewTarget)
    {
        var filterProperty = "Instrument:Filter:Name"
        targetView = Parameters.targetView;
        if (targetView.hasProperty(filterProperty))
        {
            targetView.id = targetView.propertyValue(filterProperty);
        }
        else
        {
            console.show();
            console.warningln("Unable to determine filter, Instrument:Filter:Name not set");
        }
    }
}

main();
 
I had missed part of this and it didn't work for FITS files, only XISF. Juan shared this in another thread and it seems to work either way:
JavaScript:
function keywordValue( window, name )
{
   let keywords = window.keywords;
   for ( let i = 0; i < keywords.length; ++i )
      if ( keywords[i].name == name )
         return keywords[i].strippedValue;
   return null;
}

console.writeln( "<end><cbr>" + keywordValue( ImageWindow.activeWindow, "FILTER" ) );

So I thought I'd put it here in case someone found this older thread
 
Back
Top