获取块表对象,遍历 如果是LINE对象就取出。 DocumentLock doc=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) #region 开始事务 { BlockTable bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead); foreach (ObjectId id in btr) #region 遍历图元 { Autodesk.AutoCAD.DatabaseServices.Entity entity = (Autodesk.AutoCAD.DatabaseServices.Entity)trans.GetObject(id, OpenMode.ForRead); if (entity is Line) { Line line = (Line)entity; //this.listBox1.Items.Clear(); this.listBox1.Items.Add("找到线" + line.Id.ToString() + ":开始点X:" + line.StartPoint.X.ToString() + " Y:" + line.StartPoint.Y.ToString() + "结束点X:" + line.EndPoint.X.ToString() + " Y:" + line.EndPoint.Y.ToString()); //MessageBox.Show("找到线:开始点X:" +line.StartPoint.X.ToString()+" Y:"+line.StartPoint.Y.ToString()+"结束点X:"+line.EndPoint.X.ToString()+" Y:"+line.EndPoint.Y.ToString()); } else { if (entity is DBText) { DBText dbt = (DBText)entity; this.listBox1.Items.Add("找到文本:" + dbt.Id.ToString() + ":开始点X:" + dbt.Position.X.ToString() + " Y:" + dbt.Position.Y.ToString()); } MessageBox.Show("抱歉没有找到任何东西!!"); } } #endregion } #endregion |