using System; using System.Collections.Generic; using System.Collections; using System.Text; using System.IO; using System.Data; //using System.Windows.Forms; using ZwSoft.ZwCAD.DatabaseServices; using ZwSoft.ZwCAD.Runtime; using ZwSoft.ZwCAD.Geometry; using ZwSoft.ZwCAD.ApplicationServices; using ZwSoft.ZwCAD.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 { public int Compare(OriginMXL one, OriginMXL two) { return (Convert.ToInt32(one.Mxldatatable["序号"].ToString())).CompareTo((Convert.ToInt32(two.Mxldatatable["序号"].ToString()))); } } class OriginTool { private Editor ed = ZwSoft.ZwCAD.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();//aRef.Tag.ToString().ToString(); } } } } } } System.Windows.Forms.MessageBox.Show("属性同步结束!", "提示"); } tran.Commit(); } } public void SetTitleInfo_open(string btlname, Hashtable tempvaluetable) { ed.WriteMessage("1111\n"); Document appodcTemp = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; ZwSoft.ZwCAD.EditorInput.Editor cadEdit = appodcTemp.Editor; using (appodcTemp.LockDocument()) { Database db = appodcTemp.Database; using (Transaction tran = db.TransactionManager.StartTransaction()) { ed.WriteMessage("222\n"); ed.WriteMessage("btlname:" + btlname + "\n"); BlockTable blt = tran.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable; ed.WriteMessage("btlname1:" + btlname + "\n"); if (blt.Has(btlname)) { ed.WriteMessage("333\n"); BlockTableRecord bltr = tran.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; foreach (ObjectId item in bltr) { ed.WriteMessage("444\n"); Entity ent = tran.GetObject(item, OpenMode.ForWrite) as Entity; if (ent.GetType().Name == "BlockReference") { ed.WriteMessage("555\n"); BlockReference bref = (BlockReference)ent; ed.WriteMessage("块名称1:" + bref.Name + "\n"); 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();//aRef.Tag.ToString().ToString(); } } } } } } System.Windows.Forms.MessageBox.Show("属性同步结束!", "提示"); } tran.Commit(); } } } public void SetTitleInfo_v1(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();//aRef.Tag.ToString().ToString(); } } } } } } //System.Windows.Forms.MessageBox.Show("属性同步结束!", "提示"); } 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 GetMXLInfo(string filepath, string mxlname) { //OriginTool origintool = new OriginTool(); List mxllist = new List(); 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 Boolean insertBomMXL(List bomMsgBeanList,Boolean eraseBOM) { Boolean isOk = false; String blockname = "XY_MXB"; String btlBlockName = "XY_MXB1"; // Database db = HostApplicationServices.WorkingDatabase; Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor ed = acDoc.Editor; List pointList = new List(); //删除所有的明细栏 if (eraseBOM == true) { using (Transaction tran = acCurDb.TransactionManager.StartTransaction()) { ed.WriteMessage("删除明细栏 mxl \n"); TypedValue[] typedValue = new TypedValue[1]; typedValue.SetValue(new TypedValue((int)DxfCode.BlockName, blockname), 0); SelectionFilter filter = new SelectionFilter(typedValue); PromptSelectionResult result = ed.SelectAll(filter); if (result.Status == PromptStatus.OK) { SelectionSet acSSet = result.Value; foreach (ObjectId id in acSSet.GetObjectIds()) { Entity hatchobj = tran.GetObject(id, OpenMode.ForWrite) as Entity; hatchobj.Erase();//删除 } } typedValue.SetValue(new TypedValue((int)DxfCode.BlockName, btlBlockName), 0); filter = new SelectionFilter(typedValue); result = ed.SelectAll(filter); if (result.Status == PromptStatus.OK) { SelectionSet acSSet = result.Value; foreach (ObjectId id in acSSet.GetObjectIds()) { Entity hatchobj = tran.GetObject(id, OpenMode.ForWrite) as Entity; hatchobj.Erase();//删除 } } tran.Commit(); } } //获取存放明细表的块的位置 using (Transaction tran = acCurDb.TransactionManager.StartTransaction()) { BlockTable block = tran.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; ed.WriteMessage("获取明细栏 mxn \n"); //查找存放明细栏的图框 if (block.Has(btlBlockName)) { BlockTableRecord bltr = tran.GetObject(acCurDb.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 == btlBlockName) { Point3d point = bref.Position; pointList.Add(point); ed.WriteMessage("X="+point.X+" | Y="+point.Y+" | Z="+point.Z +"\n"); } } } } tran.Commit(); } //插入明细表 //锁定文件 using (acDoc.LockDocument()) { int lineCount = 0; for (int i = 0; ; i++) { // ed.WriteMessage("================================================\n"); // ed.WriteMessage("bomMsgBeanList.Count=====" + bomMsgBeanList.Count + "\n"); // ed.WriteMessage("pointList.Count=====" + pointList.Count + "\n"); // ed.WriteMessage("lineCount1=====" + lineCount + "\n"); if (lineCount >= bomMsgBeanList.Count) { break; } Point3d pointOrigin = new Point3d(0,0,0); if (i >= pointList.Count) { //pointList[i]; PromptPointResult pPtRes = null; PromptPointOptions pPtOpts = new PromptPointOptions(""); pPtOpts.Message = "选取插入的点:"; pPtRes = ed.GetPoint(pPtOpts); pointOrigin = pPtRes.Value; ed.WriteMessage(" x=" + pointOrigin.X + " y=" + pointOrigin.Y + " z=" + pointOrigin.Z); using (Transaction tran = acCurDb.TransactionManager.StartTransaction()) { BlockTable block = tran.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; if (block.Has(btlBlockName)) { Point3d InsertPt = pointOrigin; BlockTableRecord tableRec = tran.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite, false) as BlockTableRecord; BlockTableRecord modelSpace = tran.GetObject(block[btlBlockName], OpenMode.ForRead, false) as BlockTableRecord; BlockReference blockRef = new BlockReference(InsertPt, modelSpace.ObjectId); tableRec.AppendEntity(blockRef); tran.AddNewlyCreatedDBObject(blockRef, true); insertAttri(blockRef, tran, acCurDb, null); ed.Regen(); tran.Commit(); } } } else { pointOrigin = pointList[i]; //20240409如果选了否,需要选取插入点 if (eraseBOM == false) { PromptPointResult pPtRes = null; PromptPointOptions pPtOpts = new PromptPointOptions(""); pPtOpts.Message = "选取插入的点2:"; pPtRes = ed.GetPoint(pPtOpts); pointOrigin = pPtRes.Value; pointOrigin = new Point3d(pointOrigin.X, pointOrigin.Y-12, pointOrigin.Z); ed.WriteMessage(" x=" + pointOrigin.X + " y=" + pointOrigin.Y + " z=" + pointOrigin.Z); } } //记录最大的明细栏的个数 int maxCount = 0; // ed.WriteMessage("lineCount3=====" + lineCount + "\n"); for (int j = (lineCount==0?0:(lineCount + 1)); j < bomMsgBeanList.Count; j++) { lineCount = j+1; // ed.WriteMessage("lineCount2=====" + lineCount + "\n"); using (Transaction tran = acCurDb.TransactionManager.StartTransaction()) { BlockTable block = tran.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; if (block.Has(blockname)) { maxCount++; //Point3d InsertPt = new Point3d((pointOrigin.X + 0.0331 ), (pointOrigin.Y + 14 -0.0224 + (maxCount-1) * 7), pointOrigin.Z); Point3d InsertPt = new Point3d((pointOrigin.X + 0.0331 ), (pointOrigin.Y + 12 -0.0224 + (maxCount-1) * 7), pointOrigin.Z); BlockTableRecord tableRec = tran.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite,false) as BlockTableRecord; BlockTableRecord modelSpace = tran.GetObject(block[blockname], OpenMode.ForRead,false) as BlockTableRecord; BlockReference blockRef = new BlockReference(InsertPt, modelSpace.ObjectId); tableRec.AppendEntity(blockRef); tran.AddNewlyCreatedDBObject(blockRef, true); insertAttri(blockRef,tran,acCurDb,bomMsgBeanList[j]); ed.Regen(); tran.Commit(); } } if (maxCount == 929) {//20240319明细表读取到CAD直接一张表显示,不要分表分段; break; } } } } return isOk; } /// /// 设置块的属性 /// /// /// /// /// /* public void insertAttri(BlockReference br, Transaction tran,Database db,BomMsgBean bean) { //TextStyleTableRecord textStyle=getTextStyle("明细栏短字体"); BlockTableRecord btrec = tran.GetObject(br.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord; if (btrec.HasAttributeDefinitions) { // ed.WriteMessage("ppppp\n"); AttributeCollection atcoll = br.AttributeCollection; foreach(ObjectId id in btrec){ DBObject obj = id.GetObject(OpenMode.ForRead) ; if(obj is Entity){ Entity ent = obj as Entity; if (ent is AttributeDefinition) { AttributeDefinition attdef = ent as AttributeDefinition; if (attdef!=null) { Boolean isChange = false; double w = 100; AttributeReference attref = new AttributeReference(); attref.SetDatabaseDefaults(); attref.SetAttributeFromBlock(attdef, br.BlockTransform); attref.Position = attdef.Position.TransformBy(br.BlockTransform); attref.Tag = attdef.Tag; if (bean != null) { if (attref.Tag.Equals("序号")) { attref.TextString = bean.Index; } else if (attref.Tag.Equals("代号")) { String str= bean.CodeNo; attref.TextString = str; if (str.Length<17) { // w = str.Length * 20; // isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("名称")) { String str = bean.Name; attref.TextString = str; if (str.Length < 9) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("数量")) { String str = bean.Quantity; attref.TextString = str; if (str.Length < 5) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("材料")) { String str = bean.Material; attref.TextString = str; if (str.Length < 9) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("单重")) { String str = bean.Zhongliang; attref.TextString = str; if (str.Length < 5) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("总重")) { String str = bean.Zongzhong; attref.TextString = str; if (str.Length < 5) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("备注")) { String str = bean.Note; attref.TextString = str; if (str.Length < 6) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } *//*else { attref.TextString = attdef.TextString; } *//* } else { attref.TextString = attdef.TextString; } attref.AdjustAlignment(db);//20240515 if (isChange) { //double aw = Math.Abs(attref.GeometricExtents.MaxPoint.X - attref.GeometricExtents.MinPoint.X); //double factor = w / aw; //ed.WriteMessage("w:" + w + "\n"); //ed.WriteMessage("aw:" + aw + "\n"); //ed.WriteMessage("factor:" + factor + "\n"); attref.WidthFactor = 1; } atcoll.AppendAttribute(attref); tran.AddNewlyCreatedDBObject(attref, true); //ObjectId textStyleId = attref.TextStyle; //TextStyleTableRecord textStyle = (TextStyleTableRecord)textStyleId.GetObject(OpenMode.ForWrite); //textStyle.XScale = 1; //textStyle.UpgradeOpen(); //textStyle.DowngradeOpen(); } } } } } }*/ public void insertAttri(BlockReference br, Transaction tran, Database db, BomMsgBean bean) { //TextStyleTableRecord textStyle=getTextStyle("明细栏短字体"); BlockTableRecord btrec = tran.GetObject(br.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord; if (btrec.HasAttributeDefinitions) { // ed.WriteMessage("ppppp\n"); AttributeCollection atcoll = br.AttributeCollection; foreach (ObjectId id in btrec) { DBObject obj = id.GetObject(OpenMode.ForRead); if (obj is Entity) { Entity ent = obj as Entity; if (ent is AttributeDefinition) { AttributeDefinition attdef = ent as AttributeDefinition; if (attdef != null) { Boolean isChange = false; double w = 100; AttributeReference attref = new AttributeReference(); attref.SetDatabaseDefaults(); attref.SetAttributeFromBlock(attdef, br.BlockTransform); attref.Position = attdef.Position.TransformBy(br.BlockTransform); attref.Tag = attdef.Tag; if (bean != null) { if (attref.Tag.Equals("序号")) { attref.TextString = bean.Index; } else if (attref.Tag.Equals("代号")) { String str = bean.CodeNo; attref.TextString = str; if (str.Length < 17) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("名称")) { String str = bean.Name; attref.TextString = str; if (str.Length < 9) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("数量")) { String str = bean.Quantity; attref.TextString = str; if (str.Length < 5) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("材料")) { String str = bean.Material; attref.TextString = str; if (str.Length < 9) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("单重")) { String str = bean.Zhongliang; attref.TextString = str; if (str.Length < 5) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("总重")) { String str = bean.Zongzhong; attref.TextString = str; if (str.Length < 5) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } else if (attref.Tag.Equals("备注")) { String str = bean.Note; attref.TextString = str; if (str.Length < 6) { w = str.Length * 20; isChange = true; attref.HorizontalMode = TextHorizontalMode.TextLeft; } } /*else { attref.TextString = attdef.TextString; } */ } else { attref.TextString = attdef.TextString; } attref.AdjustAlignment(db);//20240515 if (isChange) { //double aw = Math.Abs(attref.GeometricExtents.MaxPoint.X - attref.GeometricExtents.MinPoint.X); //double factor = w / aw; //ed.WriteMessage("w:" + w + "\n"); //ed.WriteMessage("aw:" + aw + "\n"); //ed.WriteMessage("factor:" + factor + "\n"); attref.WidthFactor = 1; } atcoll.AppendAttribute(attref); tran.AddNewlyCreatedDBObject(attref, true); //ObjectId textStyleId = attref.TextStyle; //TextStyleTableRecord textStyle = (TextStyleTableRecord)textStyleId.GetObject(OpenMode.ForWrite); //textStyle.XScale = 1; //textStyle.UpgradeOpen(); //textStyle.DowngradeOpen(); } } } } } } /// /// 设置块的属性 /// /// /// /// /// /*public void insertAttri2(BlockReference br, Transaction tran, Database db, BomMsgBean bean) { BlockTableRecord btrec = tran.GetObject(br.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord; if (btrec.HasAttributeDefinitions) { AttributeCollection atcoll = br.AttributeCollection; foreach (ObjectId id in btrec) { DBObject obj = id.GetObject(OpenMode.ForRead); if (obj is Entity ent && ent is AttributeDefinition attdef) { // 创建属性引用 AttributeReference attref = new AttributeReference(); attref.SetDatabaseDefaults(); attref.SetAttributeFromBlock(attdef, br.BlockTransform); attref.Position = attdef.Position.TransformBy(br.BlockTransform); attref.Tag = attdef.Tag; // 设置文本内容 if (bean != null) { switch (attdef.Tag.ToUpper()) { case "序号": attref.TextString = bean.Index; break; case "代号": attref.TextString = bean.CodeNo; break; case "名称": attref.TextString = bean.Name; break; case "数量": attref.TextString = bean.Quantity; break; case "材料": attref.TextString = bean.Material; break; case "单重": attref.TextString = bean.Zhongliang; break; case "总重": attref.TextString = bean.Zongzhong; break; case "备注": attref.TextString = bean.Note; break; default: attref.TextString = attdef.TextString; break; } // 强制设置宽度比例为1,防止缩放 attref.WidthFactor = 1; // 可选:设置固定文字高度(单位由当前样式决定) // attref.Height = 5.0; // 比如设置为5个图形单位 // 设置对齐方式(左对齐) attref.HorizontalMode = TextHorizontalMode.TextLeft; // 注释掉这行以避免自动调整对齐导致缩放 // attref.AdjustAlignment(db); // 添加属性引用到集合中 atcoll.AppendAttribute(attref); tran.AddNewlyCreatedDBObject(attref, true); } else { attref.TextString = attdef.TextString; attref.WidthFactor = 1; attref.HorizontalMode = TextHorizontalMode.TextLeft; // attref.AdjustAlignment(db); atcoll.AppendAttribute(attref); tran.AddNewlyCreatedDBObject(attref, true); } } } } }*/ //获得当前图纸中已有字体样式 public TextStyleTableRecord getTextStyle(string styleName) { ed.WriteMessage("获得当前图纸中已有字体样式\n"); Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { TextStyleTable tat = (TextStyleTable)db.TextStyleTableId.GetObject(OpenMode.ForRead); foreach (ObjectId item in tat) { TextStyleTableRecord textStyle = (TextStyleTableRecord)item.GetObject(OpenMode.ForRead); string name= textStyle.Name; ed.WriteMessage("图纸中的字体:" + name + "\n"); if (styleName.Equals(name)) { ed.WriteMessage("找到图纸中的字体:" + name + "\n"); return textStyle; } } } return null; } /// /// /// /// /// /// public void setBlockRefAttribute(BlockTableRecord modelSpace, Transaction tran,BomMsgBean bean) { ed.WriteMessage("aaaaaa\n"); foreach (ObjectId id in modelSpace) { Entity ent = tran.GetObject(id, OpenMode.ForRead, false) as Entity; if(ent is AttributeDefinition){ ed.WriteMessage("bbbbb\n"); //AttributeReference attriRef = new AttributeReference(); AttributeDefinition attriDef = ent as AttributeDefinition; ed.WriteMessage("Name = "+attriDef.TextStyleName + "\n"); } } } //获取指定块参照名称中对应的属性值 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 sortbomlist(List sortbomlist) { sortbomlist.Sort(new SortMXL1()); return sortbomlist; } /// /// 搜索ItemRevision /// /// /// /// public SavedQueryResults getSearchItemRev(String itemId ,String itemRev) { 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("OriginSearchItemRevID")) { 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 'OriginSearchItemRevID' query.\n"); return null; } try { ed.WriteMessage(" 'OriginSearchItemRevID' Item ID =" + itemId + " Item Rev = "+ itemRev+ ".\n"); // 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","Revision ID" ,"active_sqe"}; //savedQueryInput[0].Entries = new String[] { "零组件 ID" }; savedQueryInput[0].Values = new String[3]; savedQueryInput[0].Values[0] = itemId; savedQueryInput[0].Values[1] = itemRev; savedQueryInput[0].Values[2] = "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 ItemRevs:" + found.NumOfObjects + "\n"); return found; } catch (ServiceException e) { ed.WriteMessage("ExecuteSavedQuery service request failed.\n"); ed.WriteMessage(e.Message); return null; } } //根据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 { ed.WriteMessage(" 'OriginSearchItemID' Item ID ="+item_id+".\n"); // 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; } } //根据item_id,name,type,owner搜索 public SavedQueryResults getSearchItem(string item_id, string name) { 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" }; //savedQueryInput[0].Entries = new String[] { "名称", "零组件 ID" }; savedQueryInput[0].Values = new String[2]; savedQueryInput[0].Values[0] = name; savedQueryInput[0].Values[1] = 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; } } //查询所有用户 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 getCorrespondItemID(string[] tempprevalues) { List itemidlist = new List(); 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 = ZwSoft.ZwCAD.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; } } }