- 积分
- 11099
- 明经币
- 个
- 注册时间
- 2005-2-20
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2011-2-24 15:58:53
|
显示全部楼层
使用NetAPI进行CAD打印(三)-搜索图框
本帖最后由 sailorcwx 于 2011-2-24 16:02 编辑
- /// <summary>
- /// 搜索图框
- /// V1.0 by WeltionChen@2011.02.24
- /// </summary>
- [CommandMethod("tt6")]
- public void GetDrawingFrames()
- {
- using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
- {
- //缩放到全屏操作
- Database db = HostApplicationServices.WorkingDatabase;
- Point3d minPoint = db.Extmin;
- Point3d maxPoint = db.Extmax;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- ViewTableRecord currentVP = ed.GetCurrentView() as ViewTableRecord;
- ViewTableRecord zoomVP = new ViewTableRecord();
- zoomVP.CopyFrom(currentVP);
- zoomVP.Width = maxPoint.X - minPoint.X;
- zoomVP.Height = maxPoint.Y - minPoint.Y;
- zoomVP.CenterPoint = new Point2d((minPoint.X + maxPoint.X) / 2, (minPoint.Y + maxPoint.Y) / 2);
- ed.SetCurrentView(zoomVP);
- List<Point3d[]> drawingFramePoints=new List<Point3d[]>{};
- bool isSearchByFrameLine = true; //测试用
- if (isSearchByFrameLine)
- {
- SelectionFilter frameFilter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "LWPOLYLINE"), new TypedValue(90, 4), new TypedValue(70, 1) });
- PromptSelectionResult selectedFrameResult = ed.SelectAll(frameFilter);
- if (selectedFrameResult.Status == PromptStatus.OK)
- {
- List<ObjectId> selectedObjectIds = new List<ObjectId>(selectedFrameResult.Value.GetObjectIds());
- List<ObjectId> resultObjectIds = new List<ObjectId>(selectedFrameResult.Value.GetObjectIds());
- RemoveInnerPLine(tr, ref selectedObjectIds, ref resultObjectIds);
- foreach (ObjectId frameId in resultObjectIds)
- {
- Autodesk.AutoCAD.DatabaseServices.Polyline framePline = tr.GetObject(frameId, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Polyline;
- framePline.Highlight();
- }
- ed.WriteMessage("共搜索到{0}个图框\n", resultObjectIds.Count);
- }
- }
- }
- }
- void RemoveInnerPLine(Transaction tr, ref List<ObjectId> selectedObjectIds,ref List<ObjectId> resultObjectIds)
- {
- ObjectId outerPlineId = selectedObjectIds[0];
- selectedObjectIds.RemoveAt(0);
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- Autodesk.AutoCAD.DatabaseServices.Polyline outerPline = tr.GetObject(outerPlineId, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Polyline;
- SelectionFilter frameFilter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "LWPOLYLINE"), new TypedValue(90, 4), new TypedValue(70, 1) });
- PromptSelectionResult getInnerPlineResult = ed.SelectWindow(outerPline.GetPoint3dAt(0), outerPline.GetPoint3dAt(2), frameFilter);
- if (getInnerPlineResult.Status == PromptStatus.OK)
- {
- List<ObjectId> innerPlineObjectIds = new List<ObjectId>(getInnerPlineResult.Value.GetObjectIds());
- innerPlineObjectIds.Remove(outerPlineId);
- foreach (ObjectId innerPlineObjectId in innerPlineObjectIds)
- {
- selectedObjectIds.Remove(innerPlineObjectId);
- resultObjectIds.Remove(innerPlineObjectId);
- }
- if (selectedObjectIds.Count > 0)
- {
- RemoveInnerPLine(tr, ref selectedObjectIds, ref resultObjectIds);
- }
- }
- }
|
评分
-
查看全部评分
|