7 Appendix
Copy
This section describes the Document Element classes that represent an Application Programming Interface (API) for implementing a Content Generator. Each subsection describes the class for each Document Element Type along with an example implementation and helpful information for the use of each.
7.1.1 Table Document Element
7.1.1.1 Code Sample
// create table with 4 rows and 4 columnsTableDocumentElement tableElement = (TableDocumentElement) this.Factory.NewTable(“table”, 4, 4);// or this.Factory.NewTable();// or this.Factory.NewTable(“table”);// merge first cell to the righttableElement.MergeCells(0, 0, MergeDirection.Right);// merge third cell in the second row to the left, twicetableElement.MergeCells(1, 2, MergeDirection.Left);tableElement.MergeCells(1, 2, 3);// merge last cell in second row with cell below, twicetableElement.MergeCells(1, 3, MergeDirection.Down);tableElement.MergeCells(1, 3, 2);// unmerge first celltableElement.UnmergeCells(0, 0);// delete last row deletiontableElement.RemoveRow(tableElement.RowCount - 1);// add new row at the endtableElement.AddRow();// add new row at the beginningtableElement.AddRow(0);// add new column at the endtableElement.AddColumn();// add new column before the secondtableElement.AddColumn(1);// remove third columntableElement.RemoveColumn(2);targetElement.AddChild(tableElement);
7.1.1.2 Additional Information
- If table element Name is not explicitly passed in the NewTable() constructor, then first appropriate schema element will be used.
- Factory method NewTable() takes as parameters rowCount and columnCount values. If these parameters are omitted, then table will be created with 2 rows and columns (default value).
- In methods like AddRow(), AddColumn(), RemoveRow() and etc., Index parameter can be omitted. In this case method will be applied to the last row or column. Table must have at least one row and column.
- In method MergeCells() parameter mergeDirection can take one of the enumeration values: (MergeDirection.Up,MergeDirection.Right, MergeDirection.Down, MergeDirection.Left) or integer value (0, 1, 2, 3), numbers correspond to the enumeration.
7.1.2 List Document Element
7.1.2.1 Code Sample
ListDocumentElement listElement = (ListDocumentElement) this.Factory.NewList(“list1", 3);// or this.Factory.NewList();// or this.Factory.NewList(“list1");// set list stylelistElement.ListType = ListTypes.Numeric;// create new list item at the endlistElement.AddItem();// create new list item at the beginninglistElement.AddItem(0);// remove second itemlistElement.RemoveItem(1);targetElement.AddChild(listElement);
7.1.2.2 Additional Information
- If list element Name isn’t passed in NewList() constructor, then first appropriate schema element will be used.
- Factory method NewList() takes as a second parameter itemCount value. If this parameter is omitted and there is no information about default children count in the schema definition, then list will be empty (there is no default value).
- In methods AddItem(), RemoveItem() parameter Index can be omitted. In this case method will be applied to the last list Item.
- Property ListType can take one of the following enumeration values: ListTypes.Bullet, ListTypes.Numeric, ListTypes.Alpha.
7.1.3 Text Document Element
7.1.3.1 Code Sample
// create text element with «Hello World!» contentTextDocumentElement textElement = (TextDocumentElement) this.Factory.NewText(“ptxt”,“Initial Text!\n”);// or this.Factory.NewText();// or this.Factory.NewText(“ptxt”);// replace all existing strings with a new onetextElement.Text = “Hello, World!\n";// add new stringtextElement.AddString(“How are you, World?\n”);// add new string with «italic» styletextElement.AddString(“Bye, World!\n”, “bold”);// set style for second stringtextElement.Strings[1].SetStyle(“italic bold under strike”);// set style for substringtextElement.Strings[2].SetStyle(“sub”, 3, 7);// set link on element of another document (root element in this case)textElement.Strings[4].SetLink(“1D93C56E1EBA4F6A9B68D348444C9C17",“1D93C56E1EBA4F6A9B68D348444C9C17");// remove linktextElement.Strings[4].RemoveLink();targetElement.AddChild(textElement);
7.1.3.2 Additional Information
- Factory method NewText() has an optional second parameter initialText value.
- Text Document Elements contain StringDocumentElements as its children. Separate StringDocumentElements can be obtained with indexer property Strings.
StringDocumentElement stringElement = textElement.Strings[1];
o StringCount property identifies the number of StringDocumentElements. - Property Text returns concatenated content of all strings of the TextDocumentElement. If property used as a setter, then all current strings will be replaced by the given string.
- Method SetStyle() of StringDocumentElement takes text Style string as a parameter. It contains desired styles, which are delimited by the ‘space’ character. Additionally the SetStyle() method can take startRange and endRange parameters, in this case string may be split on substrings and total number of strings in the TextDocumentElement will be increased.
// after this command, the number of strings in the text Element will increase to two
textElement.Strings[2].SetStyle(“sub”, 3, 7); - Method SetLink() takes targetBlockId (id of existing Technical Document) and targetElementId (id of any element in this Document). Currently will work properly for root document element and its children.
7.1.4 Image Document Element
7.1.4.1 Code Sample
ImageDocumentElement imageElement = (ImageDocumentElement) this.Factory.NewElement(“graphic”);// get tp_Image item from InnovatorItem imageItem = this.Factory.InnovatorInstance.newItem(“tp_Image”, “get”);imageItem.setID(“70CA6215D95C4658ACA68BFDB73E4DEE”);imageItem = imageItem.apply();// set reference on image itemimageElement.SetImage(imageItem);targetElement.AddChild(imageElement);
7.1.4.2 Additional Information
- Currently there is no explicit constructor for ImageDocumentElement in SchemaElementFactory. It should be created with base element constructor (Factory.NewElement).
- By default, ImageDocumentElements are empty. Method SetImage() can be used to set the image Item reference and takes an Item as a parameter. Currently ImageDocumentElements can have refences only to tp_Image Items.
7.1.5 Item Document Element
7.1.5.1 Code Sample
ItemDocumentElement itemElement = (ItemDocumentElement) this.Factory.NewElement(“aras-part”);// get item from InnovatorItem itemItem = this.Factory.InnovatorInstance.newItem(“Part”, “get”);itemItem.setID(“CD2B48A0C3C042898AC00254930FC8A1");itemItem = itemItem.apply();// set item referenceitemElement.SetItem(itemItem);targetElement.AddChild(itemElement);
7.1.5.2 Additional Information
- Currently there is no explicit constructor for ItemDocumentElement in SchemaElementFactory. It should be created with base element constructor (Factory.NewElement).
- By default, ItemDocumentElements are empty. Method SetItem()can be used to set the Item reference and takes an Item as a parameter. Currently ItemDocumentElements can have refences only to tp_Item Polysource Items.
7.1.6 Item Property Document Element
7.1.6.1 Code Sample
Item partItem = bomItem.getPropertyItem(“related_id”);ItemDocumentElement itemElement = (ItemDocumentElement)this.Factory.NewElement(“PartItemRow”);// set item referenceitemElement.SetItem(partItem);ItemPropertyDocumentElement nameText = (ItemPropertyDocumentElement) this.Factory.NewItemProperty(“NameProperty”, “name”);…itemElement.AddChild(nameText);
7.1.6.2 Additional Information
- This example adds an ItemPropertyDocumentElement based on the following Schema Definition:
<xs:element name="NameProperty"> <xs:complexType> <xs:complexContent> <xs:extension base="aras:itemProperty"> <xs:attribute name="property" type="xs:string" fixed="name"/> <xs:attribute name="mode" type="aras:itemPropertyModeEnum" fixed="write"/> </xs:extension> </xs:complexContent> </xs:complexType> </xs:element> - Note that in the example above, the property attribute is fixed for the ‘name’ Property and the mode is fixed to ‘write’. These are optional in the schema although it’s useful to define default values.
- The example above includes the name of the Property in the NewItemProperty method. This is required even though it was defaulted to a value in the schema.