How to get the type of object that has an interaction?

When I run the code,

console.log(interactions.allInteractions[0].triggerNode)

I get something like this:

Rectangle ('Rectangle 1') {
  width: 407, height: 175
  global X,Y: 99, 143
  parent: Group ('Group 1')
  stroke: ff707070
  fill: ffff9a9a

I want to be able to isolate for the first word “Rectangle”, since it indicates the type of object that has an interaction. I’ve checked the docs and am still unsure how I can get this string. Same thing goes for the “parent” property. I can get the parent’s name, “Group 1”, but I can’t get the parent type, "Group"

Any help would be much appreciated thank you! :persevere:

1 Like

console.log(interactions.allInteractions[0].triggerNode.constructor.name)

is the correct answer, figured it out!

3 Likes

Hello jz530, I am having trouble getting the whole interactions thing to work.
let interactions = require(‘interactions’);
let allInteractions = interactions.allInteractions;

trace(allInteractions.length);
trace(${allInteractions.length}); //returns 0 even though I do have interactions in my artboard.

trace(incomingInteractions ${xdNode.incomingInteractions}); //incomingInteractions is null

trace(triggeredInteractions ${JSON.stringify(xdNode.triggeredInteractions)}); // triggeredInteractions is null also.

all these return null or 0 (in case it is a list) I can’t seem to find a way to get those interactions from an SceneNode, and I am sure they do have them bc of two things:

  1. I set them up in xd, and I verified they worked on the preview.
  2. I know the scenenode is the one I am trying to get the interactions from bc it’s children change depending on the component’s actual state when I run the plugin.

Your help will be greatly appreciated.

Did you find a solution to your issue?
I concur what you experience and I filed a bug for it ([Bug report] Interactions return nothing).

Thanks,

Are you still experiencing an issue with listing interactions? I provided more information on working with interactions.allInteractions here:

For tracing triggeredInteractions and incomingInteractions, this code works for me in XD 34 after selecting a shape or artboard that has interactions:

    let selectedNode = selection.items[0];
    let interactionsTriggered = selectedNode.triggeredInteractions;
    if (interactionsTriggered) {
        console.log("interactionsTriggered on " + selectedNode.name.normalize() + ": ", interactionsTriggered);
    }
    let interactionsIncoming = selectedNode.incomingInteractions;
    if (interactionsIncoming) {
        console.log("interactionsIncoming on " + selectedNode.name.normalize() + ": ", interactionsIncoming);
    }
2 Likes