Organize reusable classes for scripts.
Reference → Modules →Scripts → UI → Code Editor | Classes | Expressions | Monitor | References | Tasks
ScriptsClasses (Reference) provide a repository of reusable code
ScriptClasses allow you to create a repository of class libraries, methods, and functions that you can use across the application. You can call them from tasks, other classes, and the display's code behind functionality.
On this page:
Table of Contents | ||||
---|---|---|---|---|
|
Tip | ||
---|---|---|
| ||
accessible throughout your FrameworX solution. The platform automatically manages these classes as static objects with built-in exception handling.
ScriptClasses enable code reuse across:
The platform provides automatic:
Table of Contents maxLevel 2 minLevel 2 indent 10px exclude Steps style none
Click
on thethe plus icon
.Inputto create a
class name and description, select the desired language and choose the domain of the class.Choose to either create a new code or import one from an existing library.
Choose the content type for the class.
Click Ok.
Now, you can double-click the newly created row to access the Code Editor, where you can insert the code for the ScriptClass.
Info |
---|
To edit a property of an existing object, click the desired property to select it and click it again after a second to edit it. See a list of available properties in the next section. |
The image below illustrates the process described above.
All solutions include the following built-in ScriptClasses:
The following is a table describing each available property field for ScriptClasses:
new class. Three options are available:
Property | Description |
---|---|
Name | Class identifier used in code references |
Code | Programming language (C#, Python, VB.NET) |
Domain | Execution location: Server (global) or Client (local) |
ClassContent | Type: Methods or Namespace |
Edit Security | Permission level required to modify |
Build Order | Compilation sequence when multiple classes exist |
Build Status | Green check (success) or Red X (errors) |
Build Errors | Compilation error details |
Description | Documentation for the class purpose |
<ac:structured-macro ac:name="warning"> ac:rich-text-body CRITICAL: Do not include class declarations or namespace definitions in ScriptClasses
When creating a ScriptClass with Methods or MCP Tool:
public class MyClass { }
namespace MyNamespace { }
using
statements directly in codeusing
statementsThe platform automatically wraps your code in the appropriate class structure using the Name from the configuration table. </ac:rich-text-body> </ac:structured-macro>
csharp
// Methods directly - NO class wrapper, NO using statements
public string ProcessData(double value)
{
return $"Processed: {value:F2}";
}
public int Calculate(int a, int b)
{
return a + b;
}
To add using
statements (C#) or Import
statements (VB.NET):
using
statements directly in the codeMost common type for reusable code:
@Script.Class.ClassName.MethodName()
Example:
csharp
// In ScriptClass named "Calculations"
public double CalculateEfficiency(double actual, double target)
{
if (target == 0) return 0;
return (actual / target) * 100;
}
// Usage anywhere in solution:
// double eff = @Script.Class.Calculations.CalculateEfficiency(95, 100);
Special class type for AI integration:
Example:
csharp
[MCPMethod(Description = "Get tank level")]
public double GetTankLevel(
[MCPParameter(Description = "Tank ID")] string tankId)
{
return @Tag[$"Tank_{tankId}_Level"];
}
<ac:structured-macro ac:name="note"> ac:rich-text-body Advanced Feature Warning: Full Namespace is for experienced developers only. Most applications should use standard Class with Methods. This option requires manual object instantiation and exception handling like Visual Studio development. </ac:rich-text-body> </ac:structured-macro>
Complete .NET namespace implementation:
Example:
csharp
namespace MyCompany.Utilities
{
public class AdvancedProcessor
{
private int counter = 0;
public void Process()
{
// Implementation
}
}
}
// Usage requires instantiation:
// var processor = new MyCompany.Utilities.AdvancedProcessor();
// processor.Process();
All solutions include:
Global methods library executed on server:
<ac:structured-macro ac:name="info"> ac:rich-text-body ServerMain has special integration with TServer process. Additional documentation on advanced ServerMain features will be provided in future updates. </ac:rich-text-body> </ac:structured-macro>
Local methods library executed on each client:
ScriptClasses can be shared between solutions using the Library feature:
Library.dbsln
repositoryThe Library serves as a centralized repository for reusable components across all your solutions.
FrameworX enables calling between languages transparently:
csharp
// C# ScriptClass calling Python method
double result = @Script.Class.PythonClass.calculate_value(10, 20);
python
# Python ScriptClass calling C# method
efficiency = TK.Script.Class.CSharpClass.CalculateEfficiency(95.5, 100.0)
<ac:structured-macro ac:name="info"> ac:rich-text-body For detailed Python/.NET integration including type conversions and limitations, see [Python.NET Integration (Reference)] </ac:rich-text-body> </ac:structured-macro>
ScriptClasses can directly access all solution namespaces:
csharp
public void UpdateProduction()
{
// Access Tags
double rate = @Tag.ProductionRate;
// Access Alarms
bool hasAlarm = @Alarm.HasActive("Line1");
// Access Historian
var history = @Historian.GetValues("Temperature", 100);
// Access other Script Classes
var result = @Script.Class.OtherClass.Method();
// Access Script Tasks
@Script.Task.MyTask.Run();
}
To use external .NET assemblies:
using
statements in code itself<ac:structured-macro ac:name="warning"> ac:rich-text-body Avoid circular references between classes. While not blocked by the system, they cause:
If circular references exist, temporarily comment one reference to allow compilation. </ac:rich-text-body> </ac:structured-macro>
using
statements in codeRed X Build Status
Methods not accessible
@Script.Class.ClassName.MethodName()
Class wrapper errors
public class
declarationsusing
statements from code (use Namespace Declarations button)Cannot find external types
Page Tree | ||
---|---|---|
|
Property
Description
Name
The name of the class.
Code
Specifies the language used for the code of this Class. By default, this is the language you selected when you created the solution.
Domain
The location where the class executes, there are two options:
ClassContent
The type of the content in the class (Methods or Namespace)
Edit Security
The security to enable who can edit the tasks.
Build Order
The order to build the classes.
Build Status
The Status of the class code from the continuous compiling process.
Build Errors
Displays any errors encountered during the last build.
Description
The description of this class.
A circular reference occurs when two classes mutually depend on each other. For example:
This structure creates a “circularity” between the classes, leading to compilation failures and complicating code maintenance.
How Compilation Caching Works with Circular References:
When Saving a Class Individually: When a class (e.g., Class A) is saved, the system caches the last successfully compiled version. Therefore, if Class B references Class A, and Class A is then altered in a way that causes a compilation error, this error may not immediately appear in Class B because the cache retains the last valid version.
During a Complete Solution Build: During a full build, the cache is cleared, and all classes are recompiled from scratch. In this process:
Note |
---|
We emphasize that using circular references is not a recommended practice. This kind of mutual dependency compromises code stability and maintainability, complicates debugging, and leads to complete build failures. |
Recommendations:
In this section: