Removing items in a window through project script?

Is there a way to remove an object (e.g. a button) from a project script? I can use the .getWindow and .getRootContainer to access the window’s components, but I’m trying to find a component.delete or something to that effect.

1 Like

To that effect, simply make it invisible (.visible = False). I don’t believe there is a way to actually delete it. The only other way is if you were to use a template canvas or repeater, but it doesn’t sound like that is what you’re looking for.

Good thought, but I need it gone.

Why must it be completely gone? If its not visible, it wont be clicked so unless there’s something else its doing, it should be effectively gone. If it is doing something else, just check if its visible and do it if it is, don’t do it if its not.

The reason being, is that if a customer doesn’t have a particular object (on my template that gets generated for our customers) then there is no reason to keep around except to give me problems if the tag behind it does not exist or something else. I’m wanting to remove what does not exist in the PLC. I did a quick test and pointed to a non-existing value, and fair enough that stays invisible. Will that work for a template with a UDT attached? I’d just rather remove.

It should. However if you’re using a UDT as a parameter in a template, I’d heavily suggest you don’t. Just pass the path to the tag in and read it like that. Especially if you have many of these templates on a window - the reason is, it will load the entire UDT into each template even if you only read one or two things from it. It can really slow things down overall.

Bigger picture: I have a set of window templates that I control. I want to be able to configure that template for my customer via a simple script (fed in via XML or SQL table). Run the script, and configure (preferably delete) so that the user will never see it. The problem is, I will never be rid of a customer who wants to customize the screens, so they will eventually get to it. Therefore, I’d rather delete than hide what functionality (or elements) they didn’t pay for.

I do appreciate you input. I’m just pigeon-holed to some degree.

The container’s .remove() method should do it, but you might have to remove all of that component’s bindings first. Totally unsupported, of course.


I can verify that the .remove() method does indeed work whether or not it is bound to anything. I tested it with tag bindings and a few component property bindings and have not had a problem yet!

-Code Snippet-

Window = system.gui.getWindow(“Test”)
Container = Window.getRootContainer()

Component_Array = Container.getComponents()

for Component in Component_Array:

if( component.getName() == "Button 3"):
1 Like