RemoveInstanceRecursively

This function removes an instance recursively from the internal structure.
In case checkInverseRelations is non-zero only instances that are not referenced by other existing instances.

Return value is total number of removed instances

Syntax

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

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

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 RemoveInstanceRecursively 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"),
                classCylinder = RDF.engine.GetClassByName(model, "Cylinder"),
                classMatrix = RDF.engine.GetClassByName(model, "Matrix"),
                classTransformation = RDF.engine.GetClassByName(model, "Transformation");

        //
        //  Object Properties (relations)
        //
        Int64   propertyMatrix = RDF.engine.GetPropertyByName(model, "matrix"),
                propertyObject = RDF.engine.GetPropertyByName(model, "object");

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

        //
        //  Instances (creating)
        //
        Int64   instanceCube = RDF.engine.CreateInstance(classCube, (string) null),
                instanceCylinder = RDF.engine.CreateInstance(classCylinder, (string) null),
                instanceMatrix = RDF.engine.CreateInstance(classMatrix, (string) null),
                instanceTransformation = RDF.engine.CreateInstance(classTransformation, (string) null);

        RDF.engine.SetObjectProperty(instanceTransformation, propertyObject, ref instanceCylinder, 1);
        RDF.engine.SetObjectProperty(instanceTransformation, propertyMatrix, ref instanceMatrix, 1);

        double  lengthCube = 2.1,
                lengthCyl = 2.8,
                radiusCyl = 1.3,
                offsetY = -1.2;

        RDF.engine.SetDatatypeProperty(instanceCube, propertyLength, ref lengthCube, 1);
        RDF.engine.SetDatatypeProperty(instanceCylinder, propertyLength, ref lengthCyl, 1);
        RDF.engine.SetDatatypeProperty(instanceCylinder, propertyRadius, ref radiusCyl, 1);
        RDF.engine.SetDatatypeProperty(instanceMatrix, property_42, ref offsetY, 1);

        Int64   instanceCnt = 0;
        RDF.engine.OrderedHandles(model, (IntPtr) 0, (IntPtr) 0, out instanceCnt, 0, 0);
        System.Diagnostics.Debug.Assert(instanceCnt == 4);

        RDF.engine.RemoveInstanceRecursively(instanceCylinder); //  this will not remove the Cylinder instance as it is referenced

        RDF.engine.OrderedHandles(model, (IntPtr) 0, (IntPtr) 0, out instanceCnt, 0, 0);
        System.Diagnostics.Debug.Assert(instanceCnt == 4);

        RDF.engine.RemoveInstanceRecursively(instanceTransformation);

        RDF.engine.OrderedHandles(model, (IntPtr) 0, (IntPtr) 0, out instanceCnt, 0, 0);
        System.Diagnostics.Debug.Assert(instanceCnt == 1);

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