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 }