Author Topic: PJSR view id filter?  (Read 3827 times)

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
PJSR view id filter?
« on: 2012 September 25 09:13:56 »
Never mind: I wrote a function to do this.

When PI open an image, PI uses its name as a mainView id, but filtered for invalid characters (no spaces, no leading digits, etc). I'd like to do this same filtering in PJSR when my script opens images. Is there a PJSR function that does this filtering?

Thanks,
Mike
« Last Edit: 2012 September 25 16:45:39 by mschuster »

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: PJSR view id filter?
« Reply #1 on: 2012 September 25 23:12:55 »
Would you be kind enought to post it (I am lazy ...)
-- bitli

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: PJSR view id filter?
« Reply #2 on: 2012 September 26 08:58:04 »
Here is my attempt. For example something strange like l`~!@#$%^&()_-+= {}[];',ïnput.fit maps to l___nput.
-Mike

Code: [Select]
function filterViewId(id) {
   var fId = "";
   if (id.length == 0) {
      return "_";
   }
   var c = id.charAt(0);
   if ("0" <= c && c <= "9") {
      fId = fId + "_";
   }
   for (var i = 0; i != id.length; ++i) {
      c = id.charAt(i);
      fId = fId + (
         (("0" <= c && c <= "9") || ("a" <= c && c <= "z") || ("A" <= c && c <= "Z")) ? c : "_"
      );
      if (fId.length > 3 && fId.substring(fId.length - 4, fId.length) == "____") {
         fId = fId.substring(0, fId.length - 1);
      }
   }
   return fId;
}