GetInstancesByIterator

Returns a handle to an instance.
If input instance is zero, the handle will point to the first relevant instance.
If all instances are past (or no relevant instances are found), the function will return 0.

Syntax

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

[DllImport(enginedll, EntryPoint = "GetInstancesByIterator")]
public static extern Int64 GetInstancesByIterator(Int64 model, Int64 owlInstance);    

Property model

Size: 64 bit / 8 byte (value)
The handle to the model. The model handle is static during its existance. Several models can be opened simultaniously within one session. Different models are always independent, threads are allowed to be running on different models simultaniously.

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.

Example (based on pure API calls)

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

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

public Int64 GetInstanceCnt(Int64 model)
{
    Int64   instanceCnt = 0,
            myIteratedInstance = RDF.engine.GetInstancesByIterator(model, 0);
    while (myIteratedInstance != 0) {
        IntPtr    instanceNamePtr = IntPtr.Zero;
        RDF.engine.GetNameOfInstance(myIteratedInstance, out instanceNamePtr);
        string instanceName = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(instanceNamePtr);
        Console.WriteLine(instanceName);
        IntPtr    classNamePtr = IntPtr.Zero;
        RDF.engine.GetNameOfClass(RDF.engine.GetInstanceClass(myIteratedInstance), out classNamePtr);
        string className = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(classNamePtr);
        Console.WriteLine(className);
        myIteratedInstance = RDF.engine.GetInstancesByIterator(model, myIteratedInstance);
        instanceCnt++;
    }
    Console.WriteLine();

    return  instanceCnt;
}

public void Example()
{
    Int64 model = RDF.engine.CreateModel();

    if (model != 0)
    {
        Int64   instanceCnt = GetInstanceCnt(model);

        //
        //  Add a new instance
        //
        RDF.engine.CreateInstance(RDF.engine.GetClassByName(model, "Collection"), "CreatedInstanceToTestInstanceCnt");

        System.Diagnostics.Debug.Assert(GetInstanceCnt(model) == instanceCnt + 1);

        Int64   instanceCntThroughAPI = 0;
        RDF.engine.OrderedHandles(model, (IntPtr) null, (IntPtr) null, out instanceCntThroughAPI, 0, 0);

        System.Diagnostics.Debug.Assert(GetInstanceCnt(model) == instanceCntThroughAPI);

        RDF.engine.CloseModel(model);
    }
}