GetDatatypeProperty

This function gets the value(s) of a certain datatypeTypeProperty in the context of an instance.
The value of card gives the actual card of the values list.
The list values of undefined (void) items is a list of booleans, chars, integers or doubles, this list has a length as givin in the value card. The actual used type is given by the definition of the dataTypeProperty.
The return value always should be 0, if not something is wrong in the way this property is called.

Syntax

public const string EngineDLL = @"engine.dll";[DllImport(EngineDLL, EntryPoint = "GetDatatypeProperty")]
public static extern Int64 GetDatatypeProperty(Int64 owlInstance, Int64 rdfProperty, out IntPtr values, out Int64 card);    

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 rdfProperty

Size: 64 bit / 8 byte (value)
This attribute represents a handle to the property, this can be either a datatype property (attribute), an object property (relation) or non-defined property. The handle will be static during the life-time of the model, when the model (or part of it) is saved and opened again, the handle will most probably be different.

Property values

Size: 64 bit / 8 byte (reference)
The output array for datatype properties content. The contents memory is allocated by the library

Property card

Size: 64 bit / 8 byte (reference)
The cardinality (i.e. number of elements) of the array as given or returned.

Example

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

using Engine;

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

    if (model != 0)
    {
        //
        //  Classes
        //
        Int64   classAbcd = Engine.x86_64.CreateClass(model, "ABCD");

        //
        //  Datatype Properties (attributes)
        //
        Int64   propertyAb = Engine.x86_64.CreateProperty(model, Engine.x86_64.DATATYPEPROPERTY_TYPE_BOOLEAN, "Ab"),
                propertyCd = Engine.x86_64.CreateProperty(model, Engine.x86_64.DATATYPEPROPERTY_TYPE_CHAR, "Cd"),
                propertyEf = Engine.x86_64.CreateProperty(model, Engine.x86_64.DATATYPEPROPERTY_TYPE_INTEGER, "Ef"),
                propertyGh = Engine.x86_64.CreateProperty(model, Engine.x86_64.DATATYPEPROPERTY_TYPE_DOUBLE, "Gh");

        //
        //  Instances
        //
        Int64   instanceAbcd = Engine.x86_64.CreateInstance(classAbcd, (string) null);

        //
        //  Set Properties
        //
        
        {
            bool[] valuesAb = { true, false };
            byte[] valuesAb_inByte = valuesAb.Select((v) =>
            {
                return v ? (byte) 1 : (byte) 0;
            }).ToArray();
            Engine.x86_64.SetDatatypeProperty(instanceAbcd, propertyAb, valuesAb_inByte, 2);

            string[] valuesCd = { "First Line", "Second Line" };
            Engine.x86_64.SetDatatypeProperty(instanceAbcd, propertyCd, valuesCd, 2);

            Int64[] valuesEf = { 1234, 5678 };
            Engine.x86_64.SetDatatypeProperty(instanceAbcd, propertyEf, valuesEf, 2);

            double[] valuesGh = { 12.34, 56.78 };
            Engine.x86_64.SetDatatypeProperty(instanceAbcd, propertyGh, valuesGh, 2);
        }

        //
        //  Get Properties
        //

        {
            Int64   card = 0;
            IntPtr  valuesPtr = IntPtr.Zero;
            Engine.x86_64.GetDatatypeProperty(instanceAbcd, propertyAb, out valuesPtr, out card);

            System.Diagnostics.Debug.Assert(card == 2);

            if (card > 0)
            {
                byte[] values_inByte = new byte[card];
                System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values_inByte, 0, (int)card);
                bool[] values = values_inByte.Select((v) =>
                {
                    return v != 0;
                }).ToArray();

                System.Diagnostics.Debug.Assert(values[0] == true && values[1] == false);
            }
        }

        {
            Int64   card = 0;
            IntPtr  valuesPtr = IntPtr.Zero;
            Engine.x86_64.GetDatatypeProperty(instanceAbcd, propertyCd, out valuesPtr, out card);

            System.Diagnostics.Debug.Assert(card == 2);

            if (card > 0)
            {
                IntPtr[] valuesRef = new IntPtr[card];
                System.Runtime.InteropServices.Marshal.Copy(valuesPtr, valuesRef, 0, (int) card);
                string[] values = new string[card];
                for (int i = 0; i < (int) card; i++)
                {
                    values[i] = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(valuesRef[i]);
                }

                System.Diagnostics.Debug.Assert(values[0].Equals("First Line") && values[1].Equals("Second Line"));
            }
        }

        {
            Int64   card = 0;
            IntPtr  valuesPtr = IntPtr.Zero;
            Engine.x86_64.GetDatatypeProperty(instanceAbcd, propertyEf, out valuesPtr, out card);

            System.Diagnostics.Debug.Assert(card == 2);

            if (card > 0)
            {
                Int64[] values = new Int64[card];
                System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values, 0, (int) card);

                System.Diagnostics.Debug.Assert(values[0] == 1234 && values[1] == 5678);
            }
        }

        {
            Int64   card = 0;
            IntPtr  valuesPtr = IntPtr.Zero;
            Engine.x86_64.GetDatatypeProperty(instanceAbcd, propertyGh, out valuesPtr, out card);

            System.Diagnostics.Debug.Assert(card == 2);

            if (card > 0)
            {
                double[] values = new double[card];
                System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values, 0, (int) card);

                System.Diagnostics.Debug.Assert(values[0] == 12.34 && values[1] == 56.78);
            }
        }

        //
        //  The same can be applied to existing classes and properties
        //

        //
        //  Classes
        //
        Int64   classCylinder = Engine.x86_64.GetClassByName(model, "Cylinder");

        //
        //  Datatype Properties (attributes)
        //
        Int64   propertyClosed = Engine.x86_64.GetPropertyByName(model, "closed"),
                propertyLength = Engine.x86_64.GetPropertyByName(model, "length"),
                propertyName = Engine.x86_64.GetPropertyByName(model, "name"),
                propertyRadius = Engine.x86_64.GetPropertyByName(model, "radius"),
                propertySegmentationParts = Engine.x86_64.GetPropertyByName(model, "segmentationParts");

        //
        //  Instances (creating)
        //
        Int64   myInstanceCylinder = Engine.x86_64.CreateInstance(classCylinder, (string) null);

        double  length = 1.8,
                radius = 1.3;
        Int64   segmentationParts = 36;
        
        Engine.x86_64.SetDatatypeProperty(myInstanceCylinder, propertyLength, ref length, 1);
        Engine.x86_64.SetDatatypeProperty(myInstanceCylinder, propertyRadius, ref radius, 1);
        Engine.x86_64.SetDatatypeProperty(myInstanceCylinder, propertySegmentationParts, ref segmentationParts, 1);

        //
        //  non related / restricted properties (user defined and pre defined) can be connected in any quantity
        //
        bool    closed = true;
        string  name = "Example text added";

        byte    closed_inByte = closed ? (byte) 1 : (byte) 0;
        Engine.x86_64.SetDatatypeProperty(myInstanceCylinder, propertyClosed, ref closed_inByte, 1);
        Engine.x86_64.SetDatatypeProperty(myInstanceCylinder, propertyName, ref name, 1);

        System.Diagnostics.Debug.Assert(Engine.x86_64.GetArea(myInstanceCylinder, (IntPtr) 0, (IntPtr) 0) > 0);

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