Re: Built-in Macro Functions

Posted by Wayne Rasband on
URL: http://imagej.273.s1.nabble.com/Built-in-Macro-Functions-tp3701725p3701727.html

You can get the index of the selected ROI using the roiManager("index")
function, which was added in ImageJ 1.37q, due by the end of the week.
You can get the name by using the call() function to call the
RoiManager's getName() method. Here is an example:

   requires("1.37q");
   index = roiManager("index");
   if (index==-1)
       exit("Exactly one item must be selected in the ROI Manager");
   name = call("ij.plugin.frame.RoiManager.getName", index);
   print("Index:", index);
   print("Name:", name);

-wayne

> Dear ImageJ Community
>
> I’ve spent a considerable amount of time trying to figure the
> following problem out, but I have not gotten very far. If there is
> anyone out there who is familiar with the built-in macro functions in
> ImageJ and macro programming, I could really use your help
>
>
> Are there any built-in functions that allow you to get the index and
> name of an ROI that is selected in the ROI manager, and then find a
> number that is contained in the ROI name? The number could be 1 to 4
> digits long, and it will not always begin at the same string index of
> the ROI name.
>
> Below is some pseudo-code for what I’m trying to do. After selecting
> an ROI in the ROI Manager, I want to find out a number in the ROI name
> and rename the remainder of the ROIs in the list based on that number.
>
> i=index of a selected ROI in the ROI Manager; (e.g., i = 867)
> string=name of ROI at index i in the ROI Manager; (e.g., string =
> “a508n”)
> index1=index of first number in string; (e.g. 1 if string is “a508n”,
> assuming indexing begins at 0)
> index2= index of last number in string; (e.g. 3 if string is “a508n”)
> j=parseInt(substring(string,index1,index2))+1; (for previous e.g., j =
> 509)
> i++;
> while(i<=roiManager("count")) {
> roiManager("Rename","a"+j+"n");
> i++;
> }
>
> Thanks so much in advance,
>
> Roberto
>
> _________________________________________________________________
> Check the weather nationwide with MSN Search: Try it now!  
> http://search.msn.com/results.aspx?q=weather&FORM=WLMTAG
>