[CommandMethod("createLayer")] public ObjectId CreateLayer() //-----------------------------------1------------------------------- { ObjectId layerId=new ObjectId(); //它返回函数的值 Database db = HostApplicationServices.WorkingDatabase; Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Transaction trans = db.TransactionManager.StartTransaction(); //首先取得层表…… LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite); //检查EmployeeLayer层是否存在…… if (lt.Has("EmployeeLayer")) { layerId = lt["EmployeeLayer"]; } else { //如果EmployeeLayer层不存在,就创建它 LayerTableRecord ltr = new LayerTableRecord(); ltr.Name = "EmployeeLayer"; //设置层的名字 ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 2); layerId = lt.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); } trans.Commit(); trans.Dispose(); return layerId; //-----------------------------------2------------------------------- } 调试时报错,但将程序返回类型改为void:-----1--------处改为public void CreateLayer() ,-------2------处去掉,则可正常建立层,这是为什么? 另外,要将建立的层设为当前层,我该怎么做? |