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