|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections;
|
|
|
using System.Text;
|
|
|
using System.IO;
|
|
|
using System.Data;
|
|
|
|
|
|
using Autodesk.AutoCAD.DatabaseServices;
|
|
|
using Autodesk.AutoCAD.Runtime;
|
|
|
using Autodesk.AutoCAD.Geometry;
|
|
|
using Autodesk.AutoCAD.ApplicationServices;
|
|
|
using Autodesk.AutoCAD.EditorInput;
|
|
|
|
|
|
using Teamcenter.Services.Strong.Query._2007_06.SavedQuery;
|
|
|
using Teamcenter.Hello;
|
|
|
using Teamcenter.Soa.Client;
|
|
|
using Teamcenter.ClientX;
|
|
|
using Teamcenter.Services.Strong.Core;
|
|
|
using Teamcenter.Soa.Client.Model;
|
|
|
using Teamcenter.Soa.Exceptions;
|
|
|
using Teamcenter.Services.Strong.Query;
|
|
|
|
|
|
using Teamcenter.Services.Strong.Core._2007_06.DataManagement;
|
|
|
using Teamcenter.Schemas.Soa._2006_03.Exceptions;
|
|
|
using Teamcenter.Services.Strong.Query._2006_03.SavedQuery;
|
|
|
|
|
|
using User = Teamcenter.Soa.Client.Model.Strong.User;
|
|
|
using Folder = Teamcenter.Soa.Client.Model.Strong.Folder;
|
|
|
using WorkspaceObject = Teamcenter.Soa.Client.Model.Strong.WorkspaceObject;
|
|
|
using ImanFile = Teamcenter.Soa.Client.Model.Strong.ImanFile;
|
|
|
using Item = Teamcenter.Soa.Client.Model.Strong.Item;
|
|
|
using ItemRevision = Teamcenter.Soa.Client.Model.Strong.ItemRevision;
|
|
|
using ImanQuery = Teamcenter.Soa.Client.Model.Strong.ImanQuery;
|
|
|
using DataSet = Teamcenter.Soa.Client.Model.Strong.Dataset;
|
|
|
|
|
|
using SavedQueryResults = Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults;
|
|
|
namespace HelloTeamcenter.hello
|
|
|
{
|
|
|
public class SortMXL1 : IComparer<OriginMXL>
|
|
|
{
|
|
|
public int Compare(OriginMXL one, OriginMXL two)
|
|
|
{
|
|
|
return (Convert.ToInt32(one.Mxldatatable["序号"].ToString())).CompareTo((Convert.ToInt32(two.Mxldatatable["序号"].ToString())));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
class OriginTool
|
|
|
{
|
|
|
|
|
|
private Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
|
|
|
private static User loginuser;
|
|
|
|
|
|
public static User Loginuser
|
|
|
{
|
|
|
get { return OriginTool.loginuser; }
|
|
|
set { OriginTool.loginuser = value; }
|
|
|
}
|
|
|
|
|
|
//获取标题栏信息
|
|
|
public OriginBTL GetTitleInfo(string filepath,string btlname)
|
|
|
{
|
|
|
//OriginTool origintool = new OriginTool();
|
|
|
OriginBTL btlinfo = new OriginBTL();
|
|
|
OriginReadXml originreadxml = new OriginReadXml();
|
|
|
btlinfo = originreadxml.OriginReadBTL(filepath,btlname);
|
|
|
if(btlinfo ==null)
|
|
|
return null;
|
|
|
|
|
|
Database db = HostApplicationServices.WorkingDatabase;
|
|
|
using (Transaction tran = db.TransactionManager.StartTransaction())
|
|
|
{
|
|
|
BlockTable blt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
|
|
|
if (blt.Has(btlname))
|
|
|
{
|
|
|
BlockTableRecord bltr = tran.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
|
|
|
foreach (ObjectId item in bltr)
|
|
|
{
|
|
|
Entity ent = tran.GetObject(item, OpenMode.ForRead) as Entity;
|
|
|
if (ent.GetType().Name == "BlockReference")
|
|
|
{
|
|
|
BlockReference bref = (BlockReference)ent;
|
|
|
if (bref.Name == btlname)
|
|
|
{
|
|
|
ed.WriteMessage("块名称:" + bref.Name + "\n");
|
|
|
if (bref.AttributeCollection.Count != 0)
|
|
|
{
|
|
|
System.Collections.IEnumerator bRefEnum = bref.AttributeCollection.GetEnumerator();
|
|
|
while (bRefEnum.MoveNext())
|
|
|
{
|
|
|
ObjectId aId = (ObjectId)bRefEnum.Current;//这一句极其关键
|
|
|
|
|
|
AttributeReference aRef = (AttributeReference)tran.GetObject(aId, OpenMode.ForRead);
|
|
|
if (btlinfo.Btldatatable.ContainsKey(aRef.Tag))
|
|
|
{
|
|
|
btlinfo.Btldatatable = this.TableHasKey(btlinfo.Btldatatable, aRef.Tag, aRef.TextString);
|
|
|
}
|
|
|
|
|
|
btlinfo.Btlinfotable = this.TableHasKey(btlinfo.Btlinfotable, aRef.Tag, aRef.TextString);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
return btlinfo;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetTitleInfo(string btlname, Hashtable tempvaluetable)
|
|
|
{
|
|
|
Database db = HostApplicationServices.WorkingDatabase;
|
|
|
using (Transaction tran = db.TransactionManager.StartTransaction())
|
|
|
{
|
|
|
BlockTable blt = tran.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
|
|
|
if (blt.Has(btlname))
|
|
|
{
|
|
|
BlockTableRecord bltr = tran.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
|
|
|
foreach (ObjectId item in bltr)
|
|
|
{
|
|
|
Entity ent = tran.GetObject(item, OpenMode.ForWrite) as Entity;
|
|
|
if (ent.GetType().Name == "BlockReference")
|
|
|
{
|
|
|
BlockReference bref = (BlockReference)ent;
|
|
|
if (bref.Name == btlname)
|
|
|
{
|
|
|
ed.WriteMessage("块名称:" + bref.Name + "\n");
|
|
|
if (bref.AttributeCollection.Count != 0)
|
|
|
{
|
|
|
System.Collections.IEnumerator bRefEnum = bref.AttributeCollection.GetEnumerator();
|
|
|
while (bRefEnum.MoveNext())
|
|
|
{
|
|
|
ObjectId aId = (ObjectId)bRefEnum.Current;//这一句极其关键
|
|
|
|
|
|
AttributeReference aRef = (AttributeReference)tran.GetObject(aId, OpenMode.ForWrite);
|
|
|
if (tempvaluetable.Contains(aRef.Tag.ToString()))
|
|
|
{
|
|
|
ed.WriteMessage("设置" + aRef.Tag.ToString() + "\t" + tempvaluetable[aRef.Tag.ToString()].ToString() + "\n");
|
|
|
aRef.TextString = tempvaluetable[aRef.Tag.ToString()].ToString();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//判断当前table是否还有指定key值,如果有,则用新的value值替换
|
|
|
public Hashtable TableHasKey(Hashtable target, object key, object value)
|
|
|
{
|
|
|
if(target.Contains(key))
|
|
|
{
|
|
|
target.Remove(key);
|
|
|
}
|
|
|
target.Add(key, value);
|
|
|
|
|
|
return target;
|
|
|
}
|
|
|
|
|
|
|
|
|
//获取明细栏信息
|
|
|
public List<OriginMXL> GetMXLInfo(string filepath, string mxlname)
|
|
|
{
|
|
|
//OriginTool origintool = new OriginTool();
|
|
|
List<OriginMXL> mxllist = new List<OriginMXL>();
|
|
|
Database db = HostApplicationServices.WorkingDatabase;
|
|
|
using (Transaction tran = db.TransactionManager.StartTransaction())
|
|
|
{
|
|
|
BlockTable blt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
|
|
|
//string mxlname = mxlinfo.Mxlname;
|
|
|
if (blt.Has(mxlname))
|
|
|
{
|
|
|
BlockTableRecord bltr = tran.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
|
|
|
foreach (ObjectId item in bltr)
|
|
|
{
|
|
|
Entity ent = tran.GetObject(item, OpenMode.ForRead) as Entity;
|
|
|
if (ent.GetType().Name == "BlockReference")
|
|
|
{
|
|
|
BlockReference bref = (BlockReference)ent;
|
|
|
if (bref.Name == mxlname)
|
|
|
{
|
|
|
ed.WriteMessage("块名称:" + bref.Name + "\n");
|
|
|
if (bref.AttributeCollection.Count != 0)
|
|
|
{
|
|
|
System.Collections.IEnumerator bRefEnum = bref.AttributeCollection.GetEnumerator();
|
|
|
OriginMXL onemxlinfo = new OriginMXL();
|
|
|
OriginReadXml originreadxml = new OriginReadXml();
|
|
|
onemxlinfo = originreadxml.OriginReadMXL(filepath);
|
|
|
|
|
|
|
|
|
while (bRefEnum.MoveNext())
|
|
|
{
|
|
|
ObjectId aId = (ObjectId)bRefEnum.Current;//这一句极其关键
|
|
|
|
|
|
AttributeReference aRef = (AttributeReference)tran.GetObject(aId, OpenMode.ForRead);
|
|
|
if (onemxlinfo.Mxldatatable.ContainsKey(aRef.Tag))
|
|
|
{
|
|
|
onemxlinfo.Mxldatatable = this.TableHasKey(onemxlinfo.Mxldatatable, aRef.Tag, aRef.TextString);
|
|
|
}
|
|
|
|
|
|
onemxlinfo.Mxlinfotable = this.TableHasKey(onemxlinfo.Mxlinfotable, aRef.Tag, aRef.TextString);
|
|
|
|
|
|
}
|
|
|
|
|
|
mxllist.Add(onemxlinfo);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
return mxllist;
|
|
|
}
|
|
|
|
|
|
//获取指定块参照名称中对应的属性值
|
|
|
public string GetValueByBlock(string blockname,string attributename)
|
|
|
{
|
|
|
|
|
|
string attrvalue = "";
|
|
|
Database db = HostApplicationServices.WorkingDatabase;
|
|
|
using (Transaction tran = db.TransactionManager.StartTransaction())
|
|
|
{
|
|
|
BlockTable block = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
|
|
|
//string mxlname = mxlinfo.Mxlname;
|
|
|
if (block.Has(blockname))
|
|
|
{
|
|
|
BlockTableRecord bltr = tran.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
|
|
|
foreach (ObjectId item in bltr)
|
|
|
{
|
|
|
Entity ent = tran.GetObject(item, OpenMode.ForRead) as Entity;
|
|
|
if (ent.GetType().Name == "BlockReference")
|
|
|
{
|
|
|
BlockReference bref = (BlockReference)ent;
|
|
|
if (bref.Name == blockname)
|
|
|
{
|
|
|
ed.WriteMessage("块名称:" + bref.Name + "\n");
|
|
|
if (bref.AttributeCollection.Count != 0)
|
|
|
{
|
|
|
System.Collections.IEnumerator bRefEnum = bref.AttributeCollection.GetEnumerator();
|
|
|
|
|
|
while (bRefEnum.MoveNext())
|
|
|
{
|
|
|
ObjectId aId = (ObjectId)bRefEnum.Current;//这一句极其关键
|
|
|
|
|
|
AttributeReference aRef = (AttributeReference)tran.GetObject(aId, OpenMode.ForRead);
|
|
|
if (aRef.Tag.ToString() == attributename)
|
|
|
{
|
|
|
attrvalue = aRef.TextString;
|
|
|
return attrvalue;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
return attrvalue;
|
|
|
}
|
|
|
|
|
|
|
|
|
//获取数据集.xml文件配置信息
|
|
|
public OriginDataSet GetDataSetInfo(OriginDataSet dataset, OriginBTL btlinfo)
|
|
|
{
|
|
|
string ds_name = "";
|
|
|
|
|
|
for (int i = 1; i < dataset.Dsnametable.Count+1; i++)
|
|
|
{
|
|
|
string[] tempstring = dataset.Dsnametable[i].ToString().Split('.');
|
|
|
string blockname = tempstring[0];
|
|
|
string attributename = tempstring[1];
|
|
|
if (blockname == btlinfo.Btlname)
|
|
|
{
|
|
|
if (btlinfo.Btlinfotable.ContainsKey(attributename))
|
|
|
{
|
|
|
ds_name = ds_name + btlinfo.Btlinfotable[attributename].ToString();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ds_name = ds_name + this.GetValueByBlock(blockname, attributename);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
ed.WriteMessage(ds_name+"\n");
|
|
|
dataset.Ds_name = ds_name;
|
|
|
|
|
|
return dataset;
|
|
|
}
|
|
|
|
|
|
//对bomline进行排序
|
|
|
public List<OriginMXL> sortbomlist(List<OriginMXL> sortbomlist)
|
|
|
{
|
|
|
sortbomlist.Sort(new SortMXL1());
|
|
|
return sortbomlist;
|
|
|
}
|
|
|
|
|
|
|
|
|
//根据item_id搜索
|
|
|
public SavedQueryResults getSearchItem(string item_id)
|
|
|
{
|
|
|
ImanQuery query = null;
|
|
|
SavedQueryService queryService = SavedQueryService.getService(Session.getConnection());
|
|
|
try
|
|
|
{
|
|
|
GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();
|
|
|
if (savedQueries.Queries.Length == 0)
|
|
|
{
|
|
|
ed.WriteMessage("There are no saved queries in the system.\n");
|
|
|
}
|
|
|
for (int i = 0; i < savedQueries.Queries.Length; i++)
|
|
|
{
|
|
|
|
|
|
if (savedQueries.Queries[i].Name.Equals("OriginSearchItemID"))
|
|
|
{
|
|
|
query = savedQueries.Queries[i].Query;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("GetSavedQueries service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (query == null)
|
|
|
{
|
|
|
ed.WriteMessage("There is not an 'OriginSearchItemID' query.\n");
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
// Search for all Items, returning a maximum of 25 objects
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[] savedQueryInput = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[1];
|
|
|
savedQueryInput[0] = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput();
|
|
|
savedQueryInput[0].Query = query;
|
|
|
//savedQueryInput[0].Entries = new String[] { "Item ID" };
|
|
|
savedQueryInput[0].Entries = new String[] { "零组件 ID" };
|
|
|
savedQueryInput[0].Values = new String[1];
|
|
|
savedQueryInput[0].Values[0] = item_id;
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.ExecuteSavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults found = savedQueryResult.ArrayOfResults[0];
|
|
|
|
|
|
ed.WriteMessage("Found Items:" + found.NumOfObjects + "\n");
|
|
|
return found;
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("ExecuteSavedQuery service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//根据item_id,name,type,owner搜索
|
|
|
public SavedQueryResults getSearchItem(string item_id, string name, string type, string owner)
|
|
|
{
|
|
|
ImanQuery query = null;
|
|
|
SavedQueryService queryService = SavedQueryService.getService(Session.getConnection());
|
|
|
try
|
|
|
{
|
|
|
GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();
|
|
|
if (savedQueries.Queries.Length == 0)
|
|
|
{
|
|
|
ed.WriteMessage("There are no saved queries in the system.\n");
|
|
|
}
|
|
|
for (int i = 0; i < savedQueries.Queries.Length; i++)
|
|
|
{
|
|
|
|
|
|
if (savedQueries.Queries[i].Name.Equals("OriginSearchForItem"))
|
|
|
{
|
|
|
query = savedQueries.Queries[i].Query;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("GetSavedQueries service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (query == null)
|
|
|
{
|
|
|
ed.WriteMessage("There is not an 'OriginSearchForItem' query.\n");
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[] savedQueryInput = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[1];
|
|
|
savedQueryInput[0] = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput();
|
|
|
savedQueryInput[0].Query = query;
|
|
|
//savedQueryInput[0].Entries = new String[] { "Name", "Item ID", "Type", "Owning User" };
|
|
|
savedQueryInput[0].Entries = new String[] { "名称", "零组件 ID", "类型", "所有权用户" };
|
|
|
savedQueryInput[0].Values = new String[4];
|
|
|
savedQueryInput[0].Values[0] = name;
|
|
|
savedQueryInput[0].Values[1] = item_id;
|
|
|
savedQueryInput[0].Values[2] = type;
|
|
|
savedQueryInput[0].Values[3] = owner;
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.ExecuteSavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults found = savedQueryResult.ArrayOfResults[0];
|
|
|
|
|
|
ed.WriteMessage("Found Items:" + found.NumOfObjects + "\n");
|
|
|
return found;
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("ExecuteSavedQuery service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//查询所有用户
|
|
|
public SavedQueryResults getSearchUser()
|
|
|
{
|
|
|
ImanQuery query = null;
|
|
|
SavedQueryService queryService = SavedQueryService.getService(Session.getConnection());
|
|
|
try
|
|
|
{
|
|
|
GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();
|
|
|
if (savedQueries.Queries.Length == 0)
|
|
|
{
|
|
|
ed.WriteMessage("There are no saved queries in the system.\n");
|
|
|
}
|
|
|
for (int i = 0; i < savedQueries.Queries.Length; i++)
|
|
|
{
|
|
|
|
|
|
if (savedQueries.Queries[i].Name.Equals("OriginSearchForUser"))
|
|
|
{
|
|
|
query = savedQueries.Queries[i].Query;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("GetSavedQueries service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (query == null)
|
|
|
{
|
|
|
ed.WriteMessage("There is not an 'OriginSearchForUser' query.\n");
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
// Search for all Items, returning a maximum of 25 objects
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[] savedQueryInput = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[1];
|
|
|
savedQueryInput[0] = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput();
|
|
|
savedQueryInput[0].Query = query;
|
|
|
//savedQueryInput[0].Entries = new String[] { "User Id" };
|
|
|
savedQueryInput[0].Entries = new String[] { "用户 ID" };
|
|
|
savedQueryInput[0].Values = new String[1];
|
|
|
savedQueryInput[0].Values[0] = "*";
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.ExecuteSavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults found = savedQueryResult.ArrayOfResults[0];
|
|
|
|
|
|
ed.WriteMessage("Found Users:" + found.NumOfObjects + "\n");
|
|
|
return found;
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("ExecuteSavedQuery service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//获得指定名称首选项:站点类型
|
|
|
public Hashtable getTCPreferences(string prefername)
|
|
|
{
|
|
|
Hashtable prefValues = new Hashtable();
|
|
|
SessionService sessionservice = SessionService.getService(Session.getConnection());
|
|
|
Teamcenter.Services.Strong.Core._2007_01.Session.ScopedPreferenceNames[] prefNames = new Teamcenter.Services.Strong.Core._2007_01.Session.ScopedPreferenceNames[1];
|
|
|
Teamcenter.Services.Strong.Core._2007_01.Session.ScopedPreferenceNames scopedPref = new Teamcenter.Services.Strong.Core._2007_01.Session.ScopedPreferenceNames();
|
|
|
scopedPref.Names = new String[] { prefername };
|
|
|
scopedPref.Scope = "site";
|
|
|
prefNames[0] = scopedPref;
|
|
|
|
|
|
|
|
|
Teamcenter.Services.Strong.Core._2007_01.Session.MultiPreferencesResponse resp = sessionservice.GetPreferences(prefNames);
|
|
|
Teamcenter.Services.Strong.Core._2007_01.Session.ReturnedPreferences[] preferenceResp = resp.Preferences;
|
|
|
prefValues.Add(preferenceResp[0].Name, preferenceResp[0].Values);
|
|
|
//string temp = preferenceResp[0].Name.ToString();
|
|
|
//string[] value = (string[])prefValues[preferenceResp[0].Name.ToString()];
|
|
|
|
|
|
return prefValues;
|
|
|
}
|
|
|
|
|
|
|
|
|
public bool checkxml(string xmlpath)
|
|
|
{
|
|
|
if (File.Exists(xmlpath + "标题栏.xml"))
|
|
|
ed.WriteMessage("标题栏.xml准备就绪\n");
|
|
|
else
|
|
|
{
|
|
|
ed.WriteMessage("系统路径下不存在标题栏.xml文件\n");
|
|
|
return false;
|
|
|
}
|
|
|
if (File.Exists(xmlpath + "明细表.xml"))
|
|
|
ed.WriteMessage("明细表.xml准备就绪\n");
|
|
|
else
|
|
|
{
|
|
|
ed.WriteMessage("系统路径下不存在明细表.xml文件\n");
|
|
|
return false;
|
|
|
}
|
|
|
if (File.Exists(xmlpath + "Item类型.xml"))
|
|
|
ed.WriteMessage("Item类型.xml准备就绪\n");
|
|
|
else
|
|
|
{
|
|
|
ed.WriteMessage("系统路径下不存在Item类型.xml文件\n");
|
|
|
return false;
|
|
|
}
|
|
|
if (File.Exists(xmlpath + "数据集.xml"))
|
|
|
ed.WriteMessage("数据集.xml准备就绪\n");
|
|
|
else
|
|
|
{
|
|
|
ed.WriteMessage("系统路径下不存在数据集.xml文件\n");
|
|
|
return false;
|
|
|
}
|
|
|
if (File.Exists(xmlpath + "规则.xml"))
|
|
|
ed.WriteMessage("规则.xml准备就绪\n");
|
|
|
else
|
|
|
{
|
|
|
ed.WriteMessage("系统路径下不存在规则.xml文件\n");
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
//通过value值找key值
|
|
|
public object getKeyFromValue(Hashtable table,object value)
|
|
|
{
|
|
|
if (table.ContainsValue(value))
|
|
|
{
|
|
|
foreach (DictionaryEntry de in table)
|
|
|
{
|
|
|
if (de.Value.Equals(value))
|
|
|
{
|
|
|
return de.Key;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
//获得标题栏Item类型
|
|
|
public string getItemType(OriginBTL btlinfo, OriginTypeRule origintyperule)
|
|
|
{
|
|
|
if (origintyperule == null)
|
|
|
return "Item";
|
|
|
this.itemtype = origintyperule.Defaulttype.ToString();
|
|
|
|
|
|
this.getTypeByRule(btlinfo.Btlinfotable, origintyperule, "1", "");
|
|
|
|
|
|
return this.itemtype;
|
|
|
}
|
|
|
|
|
|
|
|
|
private string itemtype = "";
|
|
|
|
|
|
//获得明细栏Item类型
|
|
|
public string getItemType(OriginMXL mxlinfo, OriginTypeRule origintyperule)
|
|
|
{
|
|
|
if (origintyperule == null)
|
|
|
return "Item";
|
|
|
this.itemtype = origintyperule.Defaulttype.ToString();
|
|
|
|
|
|
this.getTypeByRule(mxlinfo.Mxlinfotable, origintyperule, "1","");
|
|
|
|
|
|
return this.itemtype;
|
|
|
}
|
|
|
|
|
|
|
|
|
//通过规则获得需要的Item类型
|
|
|
private void getTypeByRule(Hashtable infotable, OriginTypeRule origintyperule,
|
|
|
string pos,string usestringvalue)
|
|
|
{
|
|
|
ed.WriteMessage("当前source" + usestringvalue + "\n");
|
|
|
ed.WriteMessage("当前pos" + pos + "\n");
|
|
|
//获得source对应的数据
|
|
|
string sourcestring = origintyperule.Sourcetable[pos].ToString();
|
|
|
string sourcevalue = "";
|
|
|
if (sourcestring == "")
|
|
|
{
|
|
|
sourcevalue = usestringvalue;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ed.WriteMessage("source值:"+sourcestring+"\n");
|
|
|
sourcevalue = infotable[sourcestring].ToString();
|
|
|
}
|
|
|
//检查是否存在type,如果有,则直接返回
|
|
|
string typestring = origintyperule.Typetable[pos].ToString();
|
|
|
if (typestring != "")
|
|
|
{
|
|
|
this.itemtype = typestring;
|
|
|
return;
|
|
|
}
|
|
|
//处理判断条件
|
|
|
string startstring = origintyperule.Starttable[pos].ToString();
|
|
|
string endstring = origintyperule.Endtable[pos].ToString();
|
|
|
string containstring = origintyperule.Containtable[pos].ToString();
|
|
|
string equalstring = origintyperule.Equaltable[pos].ToString();
|
|
|
|
|
|
if (startstring != "")
|
|
|
{
|
|
|
if (sourcevalue.StartsWith(startstring))
|
|
|
{
|
|
|
string truestring = origintyperule.Truetable[pos].ToString();
|
|
|
if (truestring != "")
|
|
|
{
|
|
|
this.getTypeByRule(infotable, origintyperule, truestring, sourcevalue);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string falsestring = origintyperule.Falsetable[pos].ToString();
|
|
|
if (falsestring != "")
|
|
|
{
|
|
|
this.getTypeByRule(infotable, origintyperule, falsestring, sourcevalue);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else if (endstring != "")
|
|
|
{
|
|
|
if (sourcevalue.EndsWith(endstring))
|
|
|
{
|
|
|
string truestring = origintyperule.Truetable[pos].ToString();
|
|
|
if (truestring != "")
|
|
|
{
|
|
|
this.getTypeByRule(infotable, origintyperule, truestring, sourcevalue);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string falsestring = origintyperule.Falsetable[pos].ToString();
|
|
|
if (falsestring != "")
|
|
|
{
|
|
|
this.getTypeByRule(infotable, origintyperule, falsestring, sourcevalue);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else if (containstring != "")
|
|
|
{
|
|
|
if (sourcevalue.Contains(containstring))
|
|
|
{
|
|
|
string truestring = origintyperule.Truetable[pos].ToString();
|
|
|
if (truestring != "")
|
|
|
{
|
|
|
this.getTypeByRule(infotable, origintyperule, truestring, sourcevalue);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string falsestring = origintyperule.Falsetable[pos].ToString();
|
|
|
if (falsestring != "")
|
|
|
{
|
|
|
this.getTypeByRule(infotable, origintyperule, falsestring, sourcevalue);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else if (equalstring !="")
|
|
|
{
|
|
|
if (sourcevalue.Equals(equalstring))
|
|
|
{
|
|
|
string truestring = origintyperule.Truetable[pos].ToString();
|
|
|
if (truestring != "")
|
|
|
{
|
|
|
this.getTypeByRule(infotable, origintyperule, truestring, sourcevalue);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string falsestring = origintyperule.Falsetable[pos].ToString();
|
|
|
if (falsestring != "")
|
|
|
{
|
|
|
this.getTypeByRule(infotable, origintyperule, falsestring, sourcevalue);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//分割字符串,取出对应xml文件的的Item的ID
|
|
|
public List<string> getCorrespondItemID(string[] tempprevalues)
|
|
|
{
|
|
|
List<string> itemidlist = new List<string>();
|
|
|
Hashtable temptable = new Hashtable();
|
|
|
for (int i = 0; i < tempprevalues.Length; i++)
|
|
|
{
|
|
|
string tempvalueline = tempprevalues[i];
|
|
|
string[] tempvalue = tempvalueline.Split('=');
|
|
|
itemidlist.Add(tempvalue[1].ToString());
|
|
|
}
|
|
|
|
|
|
return itemidlist;
|
|
|
}
|
|
|
|
|
|
|
|
|
public bool downloadfile(Item DMTItem,string xmlpath)
|
|
|
{
|
|
|
bool result = false;
|
|
|
string DMTFilepath = "";
|
|
|
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
|
|
|
Editor ed1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
|
|
|
ModelObject[] itemrevisionlist = null;
|
|
|
ModelObject[] objects = { DMTItem };
|
|
|
String[] attributes = { "revision_list" };
|
|
|
dmService.RefreshObjects(objects);
|
|
|
dmService.GetProperties(objects, attributes);
|
|
|
itemrevisionlist = DMTItem.Revision_list;
|
|
|
ItemRevision itemrevision = itemrevisionlist[itemrevisionlist.Length - 1] as ItemRevision;
|
|
|
ExpandGRMRelationsPref myPref = new ExpandGRMRelationsPref();
|
|
|
RelationAndTypesFilter2 myFilter = new RelationAndTypesFilter2();
|
|
|
myFilter.RelationName = "IMAN_specification";
|
|
|
String[] typeVec = { "Text" };
|
|
|
myFilter.ObjectTypeNames = typeVec;
|
|
|
myPref.ExpItemRev = false;
|
|
|
RelationAndTypesFilter2[] myfilter = { myFilter };
|
|
|
myPref.Info = myfilter;
|
|
|
ModelObject[] objects1 = { itemrevision };
|
|
|
ExpandGRMRelationsResponse myResp = dmService.ExpandGRMRelationsForPrimary(objects1, myPref);
|
|
|
ExpandGRMRelationsOutput[] myoutput = myResp.Output;
|
|
|
for (int i = 0; i < myoutput.Length; i++)
|
|
|
{
|
|
|
ExpandGRMRelationsOutput one_out = myoutput[i];
|
|
|
for (int j = 0; j < one_out.OtherSideObjData.Length; j++)
|
|
|
{
|
|
|
ExpandGRMRelationsData otherSideData = one_out.OtherSideObjData[j];
|
|
|
for (int k = 0; k < otherSideData.OtherSideObjects.Length; k++)
|
|
|
{
|
|
|
Type typeinfo = otherSideData.OtherSideObjects[k].GetType();
|
|
|
string typename = typeinfo.Name;
|
|
|
if (typename == "Text")
|
|
|
{
|
|
|
DataSet dateset = otherSideData.OtherSideObjects[k] as DataSet;
|
|
|
ModelObject[] objects2 = { dateset };
|
|
|
String[] attributes2 = { "is_modifiable", "checked_out", "ref_list" };
|
|
|
dmService.RefreshObjects(objects2);
|
|
|
dmService.GetProperties(objects2, attributes2);
|
|
|
ModelObject[] dsfilevec = dateset.Ref_list;
|
|
|
ImanFile dsfile = dsfilevec[0] as ImanFile;
|
|
|
|
|
|
ModelObject[] objects3 = { dsfile };
|
|
|
String[] attributes3 = { "relative_directory_path", "original_file_name" };
|
|
|
dmService.RefreshObjects(objects3);
|
|
|
dmService.GetProperties(objects3, attributes3);
|
|
|
|
|
|
string newfilename = dsfile.Original_file_name;
|
|
|
ed1.WriteMessage("Original_file_name : " + newfilename + "\n");
|
|
|
//string tempdir = System.Environment.GetEnvironmentVariable("TEMP").ToString();
|
|
|
//ed1.WriteMessage("TEMP:" + tempdir.ToString() + "\n");
|
|
|
|
|
|
Teamcenter.Soa.Client.FileManagementUtility fmu = new Teamcenter.Soa.Client.FileManagementUtility(Teamcenter.ClientX.Session.getConnection());
|
|
|
Teamcenter.Soa.Client.GetFileResponse getFileResponse = fmu.GetFiles(dsfilevec);
|
|
|
FileInfo[] fileinfovec = getFileResponse.GetFiles();
|
|
|
|
|
|
FileInfo file = fileinfovec[0];
|
|
|
DMTFilepath = xmlpath + newfilename;
|
|
|
ed1.WriteMessage("拷贝路径:" + DMTFilepath + "\n");
|
|
|
System.IO.File.Copy(file.FullName, DMTFilepath, true);
|
|
|
System.IO.File.SetAttributes(DMTFilepath, FileAttributes.Normal);
|
|
|
if (DMTFilepath != "")
|
|
|
result = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|