原廠安裝完畢後,開始使用Technical Document如下圖
現在,我需要將ItemInfo改寫成有包含子階工程圖的表格,步驟如下
首先進入Schema
在Content 加入新功能CADInfo
在Xml Schema Element新增CADInfo的物件
新增一個Method,複製tp_ItemInfoContentGenerator的方法內容,加入CAD Structure的邏輯
//MethodTemplateName=CSharp:Aras.TDF.ContentGenerator(Strict);
ItemDocumentElement targetItem = targetElement as ItemDocumentElement;
if (targetItem != null) {
targetItem.ClearChilds();
// if referenced item was set, then
if (!targetItem.IsEmpty)
{
TableDocumentElement tableElement = (TableDocumentElement) this.Factory.NewTable("Table", 3, 5);
tableElement.GetCell(0, 0).AddChild(this.Factory.NewText("Title", "Item Info Table"));
for (int i = 0; i < tableElement.CellCount; i++)
{
tableElement.MergeCells(0, i, MergeDirection.Right);
}
tableElement.GetCell(1, 0).AddChild(this.Factory.NewText("Title", "Id"));
tableElement.GetCell(1, 1).AddChild(this.Factory.NewText("Title", "Name"));
tableElement.GetCell(1, 2).AddChild(this.Factory.NewText("Title", "Classification"));
tableElement.GetCell(1, 3).AddChild(this.Factory.NewText("Title", "Status"));
tableElement.GetCell(1, 4).AddChild(this.Factory.NewText("Title", "Date of creation"));
tableElement.GetCell(2, 0).AddChild(this.Factory.NewText("Title", targetItem.ItemId));
tableElement.GetCell(2, 1).AddChild(this.Factory.NewText("Title", targetItem.GetItemProperty("name", " ")));
tableElement.GetCell(2, 2).AddChild(this.Factory.NewText("Title", targetItem.GetItemProperty("classification", " ")));
tableElement.GetCell(2, 3).AddChild(this.Factory.NewText("Title", targetItem.GetItemProperty("state", " ")));
tableElement.GetCell(2, 4).AddChild(this.Factory.NewText("Title", targetItem.GetItemProperty("created_on")));
targetItem.AddChild(tableElement);
Item components = this.Factory.InnovatorInstance.newItem("CAD Structure","get");
components.setAction("get");
components.setAttribute("where","CAD_Structure.source_id='" + targetItem.ItemId + "'");
components = components.apply();
// if referenced item was set, then
if (!components.isError())
{
TableDocumentElement tableElementBOM = (TableDocumentElement) this.Factory.NewTable("Table", (components.getItemCount() + 2), 5);
tableElementBOM.GetCell(0, 0).AddChild(this.Factory.NewText("Title", "Components List"));
for (int i = 0; i < tableElementBOM.CellCount; i++)
{
tableElementBOM.MergeCells(0, i, MergeDirection.Right);
}
tableElementBOM.GetCell(1, 0).AddChild(this.Factory.NewText("Title", "Sort"));
tableElementBOM.GetCell(1, 1).AddChild(this.Factory.NewText("Title", "Number"));
tableElementBOM.GetCell(1, 2).AddChild(this.Factory.NewText("Title", "Name"));
tableElementBOM.GetCell(1, 3).AddChild(this.Factory.NewText("Title", "Classification"));
tableElementBOM.GetCell(1, 4).AddChild(this.Factory.NewText("Title", "File"));
for (int i = 0; i < components.getItemCount(); i++)
{
Item c = components.getItemByIndex(i);
Item p = c.getItemsByXPath("related_id/Item");
int r = i + 2;
tableElementBOM.GetCell(r, 0).AddChild(this.Factory.NewText("Text", c.getProperty("sort_order", " ")));
tableElementBOM.GetCell(r, 1).AddChild(this.Factory.NewText("Text", p.getProperty("item_number")));
tableElementBOM.GetCell(r, 2).AddChild(this.Factory.NewText("Text", p.getProperty("name")));
tableElementBOM.GetCell(r, 3).AddChild(this.Factory.NewText("Text", c.getProperty("classification", " ")));
tableElementBOM.GetCell(r, 4).AddChild(this.Factory.NewText("Text", p.getProperty("native_file","")));
}
targetItem.AddChild(tableElementBOM);
}
}
}
外觀修改