Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Production Management

About code items

  • Last UpdatedApr 07, 2025
  • 2 minute read

Code items store C# code classes of custom functionality. Code items are provided for the purpose of storing blocks of multi-line C# code in a central location, which can be called from multiple locations, and stops duplicated code appearing throughout your project.

Studio project hierarchy view showing a C# code item under an Application folder renamed us Code.

Because the methods in a code item class can be called by any expression in the project, this also provides multi-line code functionality to items which only support a single line of code; for example, CalculatedVariable item expression elements.

You can use code items to group your methods providing similar functionality together in one place. When declared properly, the class that contains your methods has global scope in the project and your methods can be called from any expression or other code item. You only use the ClassName.MethodName, and not the full project path to the methods, to access code items.

The functions (termed methods) contained in a code item are available to any expression element in the project. For example, expressions are contained in CalculatedVariable items, however, could be present in any customized (extended) item in the project.

A code item can access any property of any item in Project Explorer hierarchy through the Framework object model.

Note: Do not use any of the C# reserved keywords as names for your classes or their methods.

Guidelines about code items

Follow these guidelines when you create custom code in code items.

  • When you use code items, each code item must contain one or more public C# class declarations which in-turn contains one or more public static methods.

  • Use the following syntax to reference the code from an expression or another code item.

    <ClassName>.<MethodName>(<ParameterList)>

    as in this example:

    Increments.IncBy1();

The method parameter is passed inside the brackets.

  • C# is case sensitive, so use consistent class and method names.

There is no requirement to fully qualify the path to a code item in Studio.

"project.Folder.Increments.IncBy1();"

When the project compiles, paths to code item classes are included in the global name space list.

  • A code item must contain at least one public class, which in turn must contain at least one public static method. Any class variables must also be declared static.

Because expressions must result in a value, when called from an expression, the code item method must return a value, or the code does not compile.

TitleResults for “How to create a CRG?”Also Available in