SetNameOfInstance

Sets or updates the name of the instance, it returns 0 on success.

Error return codes:
    0 successful
    1 argument owlInstance is incorrect (not a proper handle to an active instance)
    2 argument name is incorrect (nullptr or zero length name)
    3 the name of instance is locked
    4 name is already used by another class
    5 name is already used by a property
    6 name is already used by an instance
    7 undefined error

Syntax

public const string enginedll = @"engine.dll";

[DllImport(enginedll, EntryPoint = "SetNameOfInstance")]
public static extern Int64 SetNameOfInstance(Int64 owlInstance, string name);

[DllImport(enginedll, EntryPoint = "SetNameOfInstance")]
public static extern Int64 SetNameOfInstance(Int64 owlInstance, byte[] name);    

Property owlInstance

Size: 64 bit / 8 byte (value)
The handle to the specific instance in the design tree. The instance handle is static within one open model but is most probably different when the same instance is opened in another model. The instance is always exactly of one unique class.

Property name

Size: 64 bit / 8 byte (reference)
This attribute represents the name of the instance (given as char array / ASCII). The name is given by the host and the attribute is not changed.

Example (based on pure API calls)

Here you can find code snippits that show how the API call SetNameOfInstance can be used.

using RDF;      //  include at least engine.cs within your solution

static void Main(string[] args)
{
    Int64 model = RDF.engine.CreateModel();

    if (model != 0)
    {
        //
        //  Classes
        //
        Int64   classCube = RDF.engine.GetClassByName(model, "Cube");

        //
        //  Datatype Properties (attributes)
        //
        Int64   propertyLength = RDF.engine.GetPropertyByName(model, "length");

        //
        //  Instances (creating)
        //
        Int64   myInstanceI = RDF.engine.CreateInstance(classCube, ""),
                myInstanceII = RDF.engine.CreateInstance(classCube, "secondInstance");

        System.Diagnostics.Debug.Assert(RDF.engine.GetVolume(myInstanceI, (IntPtr) 0, (IntPtr) 0) == 0.0);

        double  length = 2.0;
        RDF.engine.SetDatatypeProperty(myInstanceI, propertyLength, ref length, 1);

        IntPtr  instanceNamePtrI = IntPtr.Zero;
        RDF.engine.GetNameOfInstance(myInstanceI, out instanceNamePtrI);
        string  instanceNameI = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(instanceNamePtrI);

        length += 1.0;
        RDF.engine.SetDatatypeProperty(myInstanceII, propertyLength, ref length, 1);

        IntPtr  instanceNamePtrII = IntPtr.Zero;
        RDF.engine.GetNameOfInstance(myInstanceII, out instanceNamePtrII);
        string  instanceNameII = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(instanceNamePtrII);

        RDF.engine.SetNameOfInstance(myInstanceI, "firstInstance");
        RDF.engine.SetNameOfInstance(myInstanceII, (string) null);

        System.Diagnostics.Debug.Assert(RDF.engine.GetArea(myInstanceI, (IntPtr) 0, (IntPtr) 0) == 24.0);
        System.Diagnostics.Debug.Assert(RDF.engine.GetVolume(myInstanceII, (IntPtr) 0, (IntPtr) 0) == 27.0);

        IntPtr  instanceNamePtrIII = IntPtr.Zero;
        RDF.engine.GetNameOfInstance(myInstanceI, out instanceNamePtrIII);
        string  instanceNameIII = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(instanceNamePtrIII);

        IntPtr  instanceNamePtrIV = IntPtr.Zero;
        RDF.engine.GetNameOfInstance(myInstanceII, out instanceNamePtrIV);
        string  instanceNameIV = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(instanceNamePtrIV);

        //
        //  The retrieved instance names have the following values 
        //      instanceNameI   :  ''
        //      instanceNameII  :  'secondInstance'
        //      instanceNameIII :  'firstInstance'
        //      instanceNameIV  :  null
        //

        //
        //  The resulting model can be viewed in 3D-Editor.exe
        //
        RDF.engine.SaveModel(model, "c:\\created\\myFile.bin");
        RDF.engine.CloseModel(model);
    }
}