GetDatatypeProperty
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 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 owlDatatypeProperty, out IntPtr values, out Int64 card); public static bool[] GetDatatypeProperty_inBool(Int64 owlInstance, Int64 owlDatatypeProperty) { System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_BOOLEAN); Int64 card = 0; IntPtr valuesPtr = IntPtr.Zero; GetDatatypeProperty(owlInstance, owlDatatypeProperty, out valuesPtr, out card); 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(); return values; } return null; } public static byte[] GetDatatypeProperty_inByte(Int64 owlInstance, Int64 owlDatatypeProperty) { System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_BYTE); Int64 card = 0; IntPtr valuesPtr = IntPtr.Zero; GetDatatypeProperty(owlInstance, owlDatatypeProperty, out valuesPtr, out card); if (card > 0) { byte[] values = new byte[card]; System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values, 0, (int) card); return values; } return null; } public static Int64[] GetDatatypeProperty_inInt64(Int64 owlInstance, Int64 owlDatatypeProperty) { System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_INTEGER); Int64 card = 0; IntPtr valuesPtr = IntPtr.Zero; GetDatatypeProperty(owlInstance, owlDatatypeProperty, out valuesPtr, out card); if (card > 0) { Int64[] values = new Int64[card]; System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values, 0, (int) card); return values; } return null; } public static double[] GetDatatypeProperty_inDouble(Int64 owlInstance, Int64 owlDatatypeProperty) { System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_DOUBLE); Int64 card = 0; IntPtr valuesPtr = IntPtr.Zero; GetDatatypeProperty(owlInstance, owlDatatypeProperty, out valuesPtr, out card); if (card > 0) { double[] values = new double[card]; System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values, 0, (int) card); return values; } return null; } public static string[] GetDatatypeProperty_inString(Int64 owlInstance, Int64 owlDatatypeProperty) { System.Diagnostics.Debug.Assert(GetPropertyType(owlDatatypeProperty) == DATATYPEPROPERTY_TYPE_CHAR); Int64 card = 0; IntPtr valuesPtr = IntPtr.Zero; GetDatatypeProperty(owlInstance, owlDatatypeProperty, out valuesPtr, out card); 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]); } return values; } return null; }
Property owlInstance
Size: 64 bit / 8 byte (value)Property owlDatatypeProperty
Size: 64 bit / 8 byte (value)Property values
Size: 32 bit / 4 byte (reference)Property card
Size: 32 bit / 4 byte (reference)
Example (based on pure API calls)
Here you can find code snippits that show how the API call GetDatatypeProperty 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); } }