How to know what type of element is selected (rectangle, ellipse, polygon...)

Hello dear community,

I would like to know the selected element type of graphicNode, but do not really know how to proceed.
I tried the following trying to know if the selected item is a Rectangle, but it seems that .includes() do not work, at least in my attempt:

currentNode = selection.items[0];
if (currentNode.includes("Rectangle (")){ /*do smthg*/ };

Any idea?
thanks :slight_smile:

1 Like

Hi @valentindb, welcome to the community!

Try this:

const currentNode = selection.items[0];
const { Rectangle } = require("scenegraph");
if (currentNode instanceof Rectangle){ /*do smthg*/ };
1 Like

Hi Steve!

Thanks a lot for your quick reply.
This works perfectly :ok_hand:
I was able to implement it in my little ongoing plugin project that only works on Rectangles and Polygons for now.

I was looking for a way to detect when other type of graphicNodes are selected, so that I could display a Dialog when the plugin is triggered on a “not supported yet” graphicNode. So, perfect :slight_smile:

Thanks a lot!

Glad to hear it was helpful!