SetDatatypeProperty

This function sets 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 given in the values 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.

Note: the client application needs to make sure the cardinality of
    the property is within the boundaries.

Syntax

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

[DllImport(enginedll, EntryPoint = "SetDatatypeProperty")]
public static extern Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, ref byte values, Int64 card);

[DllImport(enginedll, EntryPoint = "SetDatatypeProperty")]
public static extern Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, byte[] values, Int64 card);

[DllImport(enginedll, EntryPoint = "SetDatatypeProperty")]
public static extern Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, ref Int64 values, Int64 card);

[DllImport(enginedll, EntryPoint = "SetDatatypeProperty")]
public static extern Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, Int64[] values, Int64 card);

[DllImport(enginedll, EntryPoint = "SetDatatypeProperty")]
public static extern Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, ref double values, Int64 card);

[DllImport(enginedll, EntryPoint = "SetDatatypeProperty")]
public static extern Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, double[] values, Int64 card);

[DllImport(enginedll, EntryPoint = "SetDatatypeProperty")]
public static extern Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, ref string values, Int64 card);

[DllImport(enginedll, EntryPoint = "SetDatatypeProperty")]
public static extern Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, string[] values, Int64 card);

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, bool value)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_BOOLEAN);
            const Int64 card = 1;
            byte value_inByte = Convert.ToByte(value);
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, ref value_inByte, card);
        }

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, byte value)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_BYTE);
            const Int64 card = 1;
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, ref value, card);
        }

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, Int64 value)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_INTEGER);
            const Int64 card = 1;
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, ref value, card);
        }

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, double value)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_DOUBLE);
            const Int64 card = 1;
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, ref value, card);
        }

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, string value)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_CHAR);
            const Int64 card = 1;
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, ref value, card);
        }

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, bool[] values)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_BOOLEAN);
            Int64 card = values.Length;
            byte[] values_inByte = values.Select((v) =>
                {
                    return Convert.ToByte(v);
                }).ToArray();
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, values_inByte, card);
        }

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, byte[] values)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_BYTE);
            Int64 card = values.Length;
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, values, card);
        }

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, Int64[] values)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_INTEGER);
            Int64 card = values.Length;
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, values, card);
        }

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, double[] values)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_DOUBLE);
            Int64 card = values.Length;
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, values, card);
        }

public static Int64 SetDatatypeProperty(Int64 owlInstance, Int64 owlDatatypeProperty, string[] values)
        {
            System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_CHAR);
            Int64 card = values.Length;
            return SetDatatypeProperty(owlInstance, owlDatatypeProperty, values, 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 owlDatatypeProperty

Size: 64 bit / 8 byte (value)
This attribute represents a handle to the datatype property (attribute). 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 input array for datatype properties content. The contents memory is allocated by the host

Property card

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

Example (based on pure API calls)

Here you can find code snippits that show how the API call SetDatatypeProperty 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   classAbcd = RDF.engine.CreateClass(model, "ABCD");

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

        //
        //  Instances
        //
        Int64   instanceAbcd = RDF.engine.CreateInstance(classAbcd, (string) null);

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

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

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

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

        //
        //  Get Properties
        //

        {
            Int64   card = 0;
            IntPtr  valuesPtr = IntPtr.Zero;
            RDF.engine.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;
            RDF.engine.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;
            RDF.engine.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;
            RDF.engine.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 = RDF.engine.GetClassByName(model, "Cylinder");

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

        //
        //  Instances (creating)
        //
        Int64   myInstanceCylinder = RDF.engine.CreateInstance(classCylinder, (string) null);

        double  length = 1.8,
                radius = 1.3;
        Int64   segmentationParts = 36;
        
        RDF.engine.SetDatatypeProperty(myInstanceCylinder, propertyLength, ref length, 1);
        RDF.engine.SetDatatypeProperty(myInstanceCylinder, propertyRadius, ref radius, 1);
        RDF.engine.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;
        RDF.engine.SetDatatypeProperty(myInstanceCylinder, propertyClosed, ref closed_inByte, 1);
        RDF.engine.SetDatatypeProperty(myInstanceCylinder, propertyName, ref name, 1);

        System.Diagnostics.Debug.Assert(RDF.engine.GetArea(myInstanceCylinder, (IntPtr) 0, (IntPtr) 0) > 0);

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