[请教]如何通过图形句柄选择并缩放到图形呀
<p>用vba很简单</p><p>Public Sub FindHandle()<br/> Dim ent As AcadEntity<br/> Dim returnObj As AcadObject<br/> Dim returnStr As String<br/> Dim MinP As Variant, MaxP As Variant<br/> On Error GoTo lblerr<br/> returnStr = ThisDrawing.Utility.GetString(False, "输入实体句柄:")<br/> Set returnObj = ThisDrawing.HandleToObject(returnStr)<br/> Set ent = returnObj<br/> ent.Highlight True<br/> ent.GetBoundingBox MinP, MaxP<br/> 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/> Transaction trans = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction();</p><p> try<br/> {<br/> long l = long.Parse(textBox_Element_Handle.Text, System.Globalization.NumberStyles.HexNumber);<br/> <br/> PromptSelectionResult prSelectionRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SelectAll();<br/> if (prSelectionRes.Status != PromptStatus.OK) <br/> throw new System.Exception("未找到图形元素!");<br/> <br/> ObjectId[] ois = prSelectionRes.Value.GetObjectIds();<br/> foreach (ObjectId objId in ois)<br/> {<br/> Entity en = (Entity)trans.GetObject(objId, OpenMode.ForRead);<br/> if(en.Handle.Value == l)<br/> {<br/> /*平移缩放到该元素*/</p><p> /*知道的帮忙啊*/<br/><br/> <br/> en.Highlight(new FullSubentityPath(new ObjectId[]{en.ObjectId}, new SubentityId(SubentityType.Null,0)),true);<br/> return;<br/> }<br/> }</p><p> MessageBox.Show(@"未找到该句柄对应的图形元素!");<br/> }</p><p> catch (System.Exception Ex)<br/> {<br/> MessageBox.Show(Ex.Message, @"错误");<br/> }</p><p> finally<br/> {<br/> trans.Dispose();<br/> }</p><p></p><p>请问有谁可以帮助我呢,或者有更简单的办法:)</p> 受教了!!!
页:
[1]