-
Notifications
You must be signed in to change notification settings - Fork 8
basic
These code examples show basic principles for AutomationML application development using the AMLEngine. The CAEX classes, used in the examples, are shown in the diagram. The CAEX Classes are all defined in the Aml.Engine.CAEX namespace.
The CAEXDocument represents the base class for creating and processing AutomationML documents. There are various loading methods for processing existing documents. The most common is loading a document from a file. Other loading methods exist for streams or strings. Loading a document from a stream is required for processing packed documents of an AutomationML container.
using Aml.Engine.CAEX;
using Aml.Engine.AmlObjects;
// loading from a file
var document = CAEXDocument.LoadFromFile ("myFile.aml");
// loading a stream from an AutomationML container
var container = new AutomationMLContainer ("myContainer.amlx");
var rootDocument = CAEXDocument.LoadFromStream ( container.RootDocumentStream());
CAEX documents can be saved as a file, a stream or a string.
using Aml.Engine.CAEX;
CAEXDocument.SaveToFile ("myFile.aml", true);
With the introduction of CAEX version 3.0, CAEX documents can be created in different versions. The standard, without explicit version specification, is the use of CAEX 3.0.
using Aml.Engine.CAEX;
// a version CAEX 3.0 document
var document = CAEXDocument.New_Document ();
// appending some content
var myIH = document.CAEXFile.InstanceHierarchy.Append("myIH");
var myIE = myIH.InternalElement.Append("myIE");
// a version 2.15 document
var document2 = CAEXDocument.New_Document (CAEXSchema.CAEX2_15);
There are index based access methods to get a specific element in a sequence. In most sequences in CAEX, name uniqueness is required. The element name can therefore be used as an index. Another index used is a name-value pair, the name denotes a property of an element and the value denotes the property value.
using Aml.Engine.CAEX;
var document = CAEXDocument.New_Document ();
var myIH = document.CAEXFile.InstanceHierarchy.Append("myIH");
myIH.Version = "1.0";
// Get the first CAEXElement from the sequence of elements
myIH = document.CAEXFile.InstanceHierarchy[0];
// Get the first CAEXElement from the sequence of elements with the name "myIH"
myIH = document.CAEXFile.InstanceHierarchy["myIH"];
// Get the first CAEXElement with a specific attribute AND value from the sequence of elements
myIH = document.CAEXFile.InstanceHierarchy[(Name:"Version", Value:"1.0")];
The most common way to process elements is to search the element hierarchy. The direct children of an element can be searched or all descendants of an element or all descendants with certain properties.
using Aml.Engine.CAEX;
var document = CAEXDocument.LoadFromFile("myFile.aml");
// browse the Instance Hierarchies in the file to import some elements
foreach (var instanceHierary in document.CaexFile.InstanceHierarchy)
{
// browse all InternalElements deep and import the internal Elements to your system
foreach (var internalElement in instanceHierarchy.Descendants<InternalElementType>())
{
// ToDo: add code to import the InternalElement
}
}
Home | Installation | API | Solutions
Getting Started
- Install
- First Steps with CAEX
- Working with CAEX Libraries
- Working with CAEX Relations
- Managing Inheritance
- Attribut Values
- Document Versions
Extended Examples
API Reference Guide