kingdomsol 发表于 2007-3-19 12:02:00

[请教]如何通过图形句柄选择并缩放到图形呀

<p>用vba很简单</p><p>Public Sub FindHandle()<br/>&nbsp;&nbsp;&nbsp; Dim ent As AcadEntity<br/>&nbsp;&nbsp;&nbsp; Dim returnObj As AcadObject<br/>&nbsp;&nbsp;&nbsp; Dim returnStr As String<br/>&nbsp;&nbsp;&nbsp; Dim MinP As Variant, MaxP As Variant<br/>&nbsp;&nbsp;&nbsp; On Error GoTo lblerr<br/>&nbsp;&nbsp;&nbsp; returnStr = ThisDrawing.Utility.GetString(False, "输入实体句柄:")<br/>&nbsp;&nbsp;&nbsp; Set returnObj = ThisDrawing.HandleToObject(returnStr)<br/>&nbsp;&nbsp;&nbsp; Set ent = returnObj<br/>&nbsp;&nbsp;&nbsp; ent.Highlight True<br/>&nbsp;&nbsp;&nbsp; ent.GetBoundingBox MinP, MaxP<br/>&nbsp;&nbsp;&nbsp; ZoomWindow MinP, MaxP<br/>lblerr:<br/>End Sub</p><p></p><p></p><p>但是现在需要用c#,我找不到合适的函数,现在只做到了选择元素(自己觉得效率很低),但是不知道怎么平移缩放到该元素:</p><p>Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;<br/>&nbsp;&nbsp;&nbsp;Transaction trans = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction();</p><p>&nbsp;&nbsp;&nbsp;try<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;long l = long.Parse(textBox_Element_Handle.Text, System.Globalization.NumberStyles.HexNumber);<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;PromptSelectionResult prSelectionRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SelectAll();<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (prSelectionRes.Status != PromptStatus.OK) <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new System.Exception("未找到图形元素!");<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;ObjectId[] ois = prSelectionRes.Value.GetObjectIds();<br/>&nbsp;&nbsp;&nbsp;&nbsp;foreach (ObjectId objId in ois)<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Entity en = (Entity)trans.GetObject(objId, OpenMode.ForRead);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(en.Handle.Value == l)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*平移缩放到该元素*/</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*知道的帮忙啊*/<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;en.Highlight(new FullSubentityPath(new ObjectId[]{en.ObjectId}, new SubentityId(SubentityType.Null,0)),true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}</p><p>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(@"未找到该句柄对应的图形元素!");<br/>&nbsp;&nbsp;&nbsp;}</p><p>&nbsp;&nbsp;&nbsp;catch (System.Exception Ex)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(Ex.Message, @"错误");<br/>&nbsp;&nbsp;&nbsp;}</p><p>&nbsp;&nbsp;&nbsp;finally<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;trans.Dispose();<br/>&nbsp;&nbsp;&nbsp;}</p><p></p><p>请问有谁可以帮助我呢,或者有更简单的办法:)</p>

yxr_MJTD 发表于 2009-3-23 10:49:00

受教了!!!
页: [1]
查看完整版本: [请教]如何通过图形句柄选择并缩放到图形呀