1--實體的選擇集
1 PromptEntityOptions entPline = new PromptEntityOptions("選擇一條斷面線:"); 2 PromptEntityResult entPlineRes = ed.GetEntity(entPline); 3 4 if (entPlineRes.Status == PromptStatus.OK) 5 { 6 Polyline entpolyline = (Polyline)trans.GetObject(entPlineRes.ObjectId, OpenMode.ForRead); 7 //ed.WriteMessage(entpolyline.EndPoint.ToString() + entpolyline.StartPoint.ToString()); 8 polylineStartPoint = entpolyline.StartPoint; 9 polylineEndPoint = entpolyline.EndPoint; 10 }
2--點的選擇
//選擇斷面零點 PromptPointOptions pointOp = new PromptPointOptions("請選擇斷面零點:\n"); PromptPointResult pointRes = ed.GetPoint(pointOp); if (pointRes.Status == PromptStatus.OK) { // ed.WriteMessage("選擇的零點為:" + pointRes.Value.X.ToString() + pointRes.Value.Y.ToString() + pointRes.Value.Z.ToString()); ed.WriteMessage("選擇的零點為:" + pointRes.Value.ToString()); //斷面零點信息 gcdZERO.GcdX = pointRes.Value.X; gcdZERO.GcdY = pointRes.Value.Y; gcdZERO.GcdH = pointRes.Value.Z; gcdZERO.GcdSCDH = dmCS.DmH + "斷面零點"; gcdDic.Add(gcdZERO);//將高程點也加入到gcdDic中 }
3- 根據過濾器來選擇點
1 PromptSelectionOptions selectionOpZDH = new PromptSelectionOptions(); 2 selectionOpZDH.MessageForAdding = "請選擇展點號和高程點:"; 3 4 //根據過濾器來選 5 TypedValue[] filListZDH = new TypedValue[]{ 6 new TypedValue((int)DxfCode.Operator, "<OR"), 7 new TypedValue((int)DxfCode.Operator, "<AND"), 8 new TypedValue((int)DxfCode.Start, "Insert"), 9 new TypedValue((int)DxfCode.LayerName, "GCD"), 10 new TypedValue((int)DxfCode.Operator, "AND>"), 11 new TypedValue((int)DxfCode.Operator, "<AND"), 12 new TypedValue((int)DxfCode.Start, "Text"), 13 new TypedValue((int)DxfCode.LayerName, "ZDH"), 14 new TypedValue((int)DxfCode.Operator, "AND>"), 15 new TypedValue((int)DxfCode.Operator, "OR>")}; 16 17 SelectionFilter filterZDH = new SelectionFilter(filListZDH); 18 19 PromptSelectionResult ssResZDH = ed.GetSelection(selectionOpZDH, filterZDH); 20 21 22 if (ssResZDH.Status == PromptStatus.OK) 23 { 24 SelectionSet ssZDH = ssResZDH.Value; 25 int nCount = ssZDH.Count; 26 ObjectId[] oID = ssZDH.GetObjectIds();//通過ID對實體進行操作 27 28 Entity ent; 29 30 //獲得塊表記錄-圖紙空間,打印布局 31 //BlockTableRecord btr=(BlockTableRecord )trans.GetObject(bt[BlockTableRecord.PaperSpace],OpenMode.ForWrite); 32 33 //ed.WriteMessage("nCount:" + nCount); 34 35 // foreach (ObjectId id in oID) 36 for (int i = 0; i < nCount; i++) 37 { 38 ent = (Entity)trans.GetObject(oID[i], OpenMode.ForRead); 39 40 41 /*switch (ent.GetType().ToString()) 42 { 43 //展點號 44 case "DBText": 45 DBText dbtxt = (DBText)ent; 46 gcdZDH.GcdX = dbtxt.Position.X; 47 gcdZDH.GcdY = dbtxt.Position.Y; 48 gcdZDH.GcdH = dbtxt.Position.Z; 49 gcdZDH.GcdSCDH = dbtxt.TextString; 50 zdhDic.Add(i, gcdZDH); 51 strZDH += "展點號:" + dbtxt.TextString + "其坐標為:" + dbtxt.Position.ToString() + "\r\n"; 52 break; 53 //高程點 54 case "BlockReference": 55 BlockReference bent = (BlockReference)ent; 56 gcd.GcdX = bent.Position.X; 57 gcd.GcdY = bent.Position.Y; 58 gcd.GcdH = bent.Position.Z; 59 gcd.GcdSCDH = i.ToString(); 60 gcdDic.Add(i, gcd); 61 strZDH += "高程點Postion:" + bent.Position.ToString() + "\r\n"; 62 break; 63 default: 64 break; 65 66 } 67 */ 68 69 /* 70 if (ent is MText) 71 { 72 MText mtx = ent as MText; 73 ed.WriteMessage("展點號的坐標為:" + mtx.Location.ToString()); 74 } 75 else if (ent.GetType() == typeof(MText)) 76 { 77 MText mtxt = (MText)ent; 78 ed.WriteMessage("展點號的坐標為:" + mtxt.Location.ToString()); 79 } 80 */ 81 82 //展點號 83 if (ent.GetType() == typeof(DBText)) 84 { 85 GCD gcdZDH = new GCD(); 86 DBText dbtxt = (DBText)ent; 87 //ed.WriteMessage("展點號:" + dbtxt.TextString + "其坐標為:" + dbtxt.Position.ToString()); 88 gcdZDH.GcdX = dbtxt.Position.X; 89 gcdZDH.GcdY = dbtxt.Position.Y; 90 gcdZDH.GcdH = dbtxt.Position.Z; 91 gcdZDH.GcdSCDH = "ZDH___" + dbtxt.TextString; 92 93 // strZDH += gcdZDH.GcdSCDH.ToString() + "展點號:"+i + dbtxt.TextString + "其坐標為:" + dbtxt.Position.ToString() + "\r\n"; 94 //zdhDic.Add(i, gcdZDH); 95 zdhDic.Add(gcdZDH); 96 97 98 } 99 100 101 /*//展點號中心點 102 else if (ent.GetType() == typeof(DBPoint)) 103 { 104 DBPoint dbp = (DBPoint)ent; 105 ed.WriteMessage("展點號中心點的坐標:" + dbp.Position.ToString()); 106 strZDH +="展點號中心點的坐標:" +dbp.Position.X + " " + dbp.Position.Y + " " + dbp.Position.Z; 107 strZDH += "\r\n"; 108 } 109 */ 110 111 112 //高程點是個塊 113 else if (ent.GetType() == typeof(BlockReference)) 114 { 115 GCD gcd = new GCD(); 116 BlockReference bent = (BlockReference)ent; 117 118 // ed.WriteMessage("高程點Postion:" + bent.Position.ToString()); 119 120 //ed.WriteMessage("高程點的坐標為:" + ent.GeometricExtents.MaxPoint.ToString() + ent.GeometricExtents.MinPoint.ToString()); 121 //strZDH += ent.GeometricExtents.MaxPoint.ToString() + "\r\n"+ent.GeometricExtents.MinPoint .ToString(); 122 123 124 125 gcd.GcdX = bent.Position.X; 126 gcd.GcdY = bent.Position.Y; 127 gcd.GcdH = bent.Position.Z; 128 // gcd.GcdSCDH = i.ToString(); 129 gcd.GcdSCDH = "---"; 130 // strZDH += gcd.GcdSCDH.ToString() + "高程點Postion:"+i + bent.Position.ToString() + "\r\n"; 131 // gcdDic.Add(i, gcd); 132 //gcdDic.Add(i, gcd);//將高程點和展點號放在一個字典中 133 gcdDic.Add(gcd); 134 } 135 136 }
