Create an object with custom behavior

Create an object with custom behavior

Create an object type with a simple NetLogic that sums two integers.
Prerequisites
Set the default external code editor. See Set the default code editor.
  1. To create an object type with custom behavior
  2. In
    Project view
    , right-click
    Model
    and select
    New
    Object
    .
    Under
    Model
    ,
    Object1
    appears.
  3. Hover-over
    Object1
    , select
    Edit
    and enter
    MyObject
    .
  4. Right-click
    MyObject
    and select
    Refactor
    Transform instance into type
    .
    MyObject
    changes into
    MyObject (type)
    .
  5. Right-click
    MyObject (type)
    and select
    Add custom behavior
    .
  6. Right-click
    MyObject (type)
    and select
    Edit with .NET code editor (external)
    .
    The external code editor opens.
  7. In the external code editor, make
    the following edits
    :
    #region Using directives using System; using UAManagedCore; using OpcUa = UAManagedCore.OpcUa; using FTOptix.UI; using FTOptix.HMIProject; using FTOptix.NativeUI; using FTOptix.Retentivity; using FTOptix.CoreBase; using FTOptix.Core; using FTOptix.NetLogic; #endregion [CustomBehavior] public class ObjectBehavior : BaseNetBehavior { public override void Start() { // Insert code to be executed when the user-defined behavior is started } public override void Stop() { // Insert code to be executed when the user-defined behavior is stopped }
    [ExportMethod] public void sumNumbers(int a, int b, out int c){ c=a+b;
    } #region Auto-generated code, do not edit! protected new Object Node => (Object)base.Node; #endregion }
  8. Save the NetLogic code and close the external editor.
  9. In
    FactoryTalk Optix Studio
    , right-click
    Model
    and select
    New
    MyObject
    .
MyObject1
appears under
Model
.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.