| 出到命令行,我们需要使用Application.DocumentManager.MdiActiveDocument.Editor对象的服务。要使用它,请加入下面的代码:
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
在函数的内部:
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
最后,在循环的后面确定找到了多少个块索引:
ed.WriteMessage("Employees Found: " + nEmployeeCount.ToString());
第四章结束
下面的代码片断演示了怎样获取Employee对象的所有内容,包括ACME_DIVISION字典中的部门经理的名字。这部分要在后面的章节中使用,但因为它和本章有关,因此我们把它放在本章作介绍。如果有时间的话,请阅读一下其中的代码来看看它是怎么使用的。它可以被直接放到你的类中并可以运行。命令的名字是PRINTOUTEMPLOYEE。ListEmployee()函数接收一个ObjectId参数,它通过一个ref类型的字符串数组返回值(包含相应的雇员数据)。调用它的PrintoutEmployee()函数只是用来在命令行中输出这些数据。
我们需要一个遍历并显示所有雇员数据的命令。
public static void ListEmployee(ObjectId employeeId, ref string[] saEmployeeList)
{
int nEmployeeDataCount = 0;
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction(); //开始事务处理。
try
{
Entity ent = (Entity)trans.GetObject(employeeId, OpenMode.ForRead, false); //打开当前对象!
if (ent.GetType() == typeof(BlockReference))
{
//不是所有的块索引都有雇员数据,所以我们要处理错误
  上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |