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