使用NetAPI进行CAD打印(三)-搜索图框
本帖最后由 sailorcwx 于 2011-2-24 16:02 编辑/// <summary>
/// 搜索图框
/// V1.0 by WeltionChen@2011.02.24
/// </summary>
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;
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);
}
}
}
沙发坐下,呵呵
打印的系列,加点简要的说明更好,:)
使用NetAPI进行CAD打印(四)-自动识别标准图幅及比例
本帖最后由 sailorcwx 于 2011-3-10 23:22 编辑public void GetFrameSizeScale()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Point3d pt1 = ed.GetPoint("\n第一个点").Value;
Point3d pt2 = ed.GetPoint("\n对角点").Value;
object[] returnResult;
if (GetFrameSizeScale(new Point2d(pt1.X, pt1.Y), new Point2d(pt2.X, pt2.Y), out returnResult))
{
ed.WriteMessage("\n比例:{0},横向尺寸:{1},竖向尺寸:{2}", returnResult, returnResult, returnResult);
}
else
{
ed.WriteMessage("\n你所选的不是标准图框");
}
}
bool GetFrameSizeScale(Point2d pt1, Point2d pt2,out object[] returnResult)
{
returnResult = new object;
List<int> pageWidths = new List<int> { 841, 594, 419, 293, 210 };
double frameXSize = Math.Abs(pt1.X-pt2.X);
double frameYSize=Math.Abs(pt1.Y-pt2.Y);
double frameWidth = Math.Min(frameXSize, frameYSize);
for (int i = 0; i < pageWidths.Count; i++)
{
int pageWidth = pageWidths;
if ((int)frameWidth % pageWidth == 0)
{
double scale = pageWidth / frameWidth;
returnResult = scale;
returnResult = frameXSize * scale;
returnResult = frameYSize * scale;
return true;
}
}
return false;
}
系列的专题合并了,呵呵
这样方便查找:) 学习的好程序,楼主能添加一些注释就更便于学习了... 怎么没有(一)? 期待添加新内容!!!
期待你的大作 本帖最后由 guodonglin 于 2011-6-27 21:34 编辑
如何读取布局的plotsettings对象?希望提供程序。gzjwulin@163.com .谢谢。 为什么我在.net应用程序里使用kean专题的那些程序,我点击按钮的时候提示找不到模块呢?
按钮事件就进不去,这是为什么呢、?用命令是没有问题的,lz能帮解答下么?谢谢