Dear Expert.
I have an issue in factory studio please.
In the normally working in display, I can create object like button, square, etc by Drag and Drop available object menu.
For my project requirements, I need to create and delete Objects by use code behind the screen instead of that traditional way.
Is this possible? If yes, How can I do that?
Many thank your support.
Hi Thanos
Yes, it is possible to dynamically create objects in a display using CodeBehind in FactoryStudio.
You can use the OnCreateDisplay method together with TSymbol.CreateSymbol(...) to add objects at runtime instead of using drag-and-drop.
Below is a simple example that creates a Button dynamically:
public void OnCreateDisplay(Canvas canvas)
{
// Create a dictionary to hold symbol properties
var labels = new Dictionary<string, object>();
// Optional: internal name of the object
labels["Name"] = TK.DoubleQuotes("BtnExample");
// Create a Button at position (100, 100)
TSymbol.CreateSymbol(
"Button", // Symbol type
canvas, // Target canvas
labels, // Properties (can be null)
100, // Left position
100, // Top position
false, false, false, false,
null
);
}
With this approach, you can:
-
Dynamically create objects at runtime
-
Control their position
-
Define properties
-
Combine this with logic (loops, conditions, tag values, etc.)
In addition to creation, you can also control object behavior such as visibility or interaction through code, depending on your use case.
To better guide you, it would be helpful to understand a bit more about your scenario, for example:
-
Are you creating objects based on tag values or database data?
-
Do you need to frequently add/remove objects, or just show/hide them?
-
Are these objects static after creation, or do they change dynamically during runtime?
With a bit more detail about your project requirements, we can suggest the best approach and structure for your implementation.