Google sheets scripts question on drawing object. Looking for a way to tell which script is assigned to which drawing object

Solution for Google sheets scripts question on drawing object. Looking for a way to tell which script is assigned to which drawing object
is Given Below:

I have a Google spreadsheet with four drawings that have scripts assigned. One of them is a delete image. Trying to use this button to first draw checkboxes next to the items which could possibly be deleted and then later delete the rows which have boxes checked.

Is there a way to check the action assigned to a drawing prior to changing it. Appreciate any help. Thanks.

There is no ‘beforechange’ nor ‘oldvalue’ feature.

You may consider to watch all the assigned actions upon onLoad or onEdit to track the change indirectly.

How to identify Drawings and the attached function with Apps Script

function getMacros(){
  const file = SpreadsheetApp.getActive();
  const sheet = file.getSheetByName("Sheet1");
  const drawings = sheet.getDrawings()

  drawings.forEach(d => {
    Logger.log(d.getOnAction()) // Gets name of function
    Logger.log(d.getContainerInfo().getAnchorColumn())
    Logger.log(d.getContainerInfo().getAnchorRow())
    Logger.log(d.getContainerInfo().getOffsetX())
    Logger.log(d.getContainerInfo().getOffsetY())
    Logger.log(d.getZIndex())
  })
}

You said that the order of the buttons changed each time the script was called, however this was not what I found. Though it is likely to change if you modify the drawings.

You can use getOnAction() to specifically get the function attached to a drawing. It will return the name of the function.

You can use the methods related to ContainerInfo, which will give you anchor columns and rows and X and Y offsets, which you could also use to identify drawings. Finally the getZIndex() method might come in handy, even if you aren’t layering the drawings, to use as an ID of sorts. You can setZIndex() too.

To keep track of the numbers you associate with different drawings, you could use the PropertiesService so that you can save information within the script.

For example. Once you have your drawings set up, you can run a variation of the above script to get all the numbers associated with the different drawings and keep them with the PropertiesService. Then you have a sort of “fingerprint” with which to identify them in the future.

References