Add component using scripting

Hello everyone,

I need to add a new component like a Label (“X”) every time that user clicks in some area in the picture like the “X” in green below.
If the click again in the “X” will remove the Label “X”.

image

Use the ‘View Canvas’ component.
https://docs.inductiveautomation.com/display/DOC81/Perspective+-+View+Canvas

1 Like

Thanks, but I don’t know how can I do that by script?
How can I create a new label component by script?

I would like to add a new “X” every time the user clicks on some part of the script.

I can collect the X and Y position from the user’s click.
vX = event.clientX
vY = event.clientY

The view canvas has a property instances that represents the inner views it contains. Your inner view can detect if it’s clicked and broadcast a message back to the parent, telling it to remove that instance. The view canvas itself can intercept clicks (meaning they weren’t caught by an inner view) and create an instance at the given location.

1 Like

Thanks for the answer, it was very helpful.
Could you tell me how to add a new instance when the user clicks?

Not exactly, but it would basically involve creating a Python object with the same structure as the existing elements in the instances array, then adding it to that list.