2

Given a multi-slice lineplot, one of the slices can be selected by clicking it in the legend with the mouse. From the scripting side, there is a command to imgdsp.ImageDisplaySetSliceSelected(). But I can't find a command that lets me determine which slice is currently selected. imgdsp.ImageDisplayGetSliceSelected() shows only 'No match' in the output window and I was not successful looking through the help under 'F1'. I also tried ImageDisplayGetDisplayedLayers() but it returned 0 always.

How can I determine which slice is currently selected in a multi-slice lineplot?

BmyGuest
  • 6,331
  • 1
  • 21
  • 35
E Voelkl
  • 259
  • 1
  • 6

1 Answers1

2

As a matter of fact, one can have multiple slices selected in LinePlot display, not just one, just hold CTRL while clicking for multi-select.

The command you're looking for is:
Boolean ImageDisplayIsSliceSelected( ImageDisplay id, ScriptObject slice_id ) And an example of its use is:

imageDocument  doc = NewImageDocument("SliceTest")
imageDisplay disp = doc.ImageDocumentAddImageDisplay( RealImage("",4,100)=icol, "best" )
disp.LinePlotImageDisplaySetLegendShown(1)
disp.ImageDisplayAddImage(RealImage("",4,100)=icol**2/iwidth,"Second")
disp.ImageDisplayAddImage(RealImage("",4,100)=icol**3/iwidth**2,"Third")
disp.ImageDisplayAddImage(RealImage("",4,100)=icol**4/iwidth**3,"Fourth")

disp.ImageDisplaySetSliceSelected( disp.ImageDisplayGetSliceIDByIndex(2), 1 )
doc.ImageDocumentShow()
ClearResults()
Result("Current slice selection states:\n")
For( number i=0; i<disp.ImageDisplayCountSlices(); i++){
    Result("Slice #"+i+": '"+disp.ImageDisplayGetSliceLabelByIndex(i)+"'")
    object sliceID = disp.ImageDisplayGetSliceIDByIndex(i)
    Result("\t: Selected:"+disp.ImageDisplayIsSliceSelected(sliceID,""))
    Result("\n")
}

But I would further encourage you to look at the example scripts of the F1 help documentation here:

F1 Help examples

BmyGuest
  • 6,331
  • 1
  • 21
  • 35
  • 1
    Thank you, the "As a matter of fact, one can have multiple slices selected in LinePlot display, not just one, just hold CTRL while clicking for multi-select" is the key and explains why the function I was looking for isn't there. – E Voelkl May 29 '23 at 01:21