你好!
我不明白为什么我不能为新图层设置描述。Name和Decription都是作为字符串的属性,但我只得到正确的图层名称而不是图层描述?!
- public static void CreateLayer(string layName, string layDescr)
- {
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- try
- {
- // Get the layer table from the drawing
- LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
- if (lt.Has(layName))
- ed.WriteMessage("\nLayername: {0} already exists.", layName);
- else
- {
- // Create our new layer table record...
- LayerTableRecord ltr = new LayerTableRecord();
- // ... and set its properties
- ltr.Name = layName;
- ltr.Description = layDescr;
- // Add the new layer to the layer table
- lt.UpgradeOpen();
- ObjectId ltId = lt.Add(ltr);
- tr.AddNewlyCreatedDBObject(ltr, true);
- // Set the layer to be current for this drawing
- db.Clayer = ltId;
- // Report what we've done
- ed.WriteMessage("\nCreated layer named {0}", layName);
- }
- }
- catch
- {
- // An exception has been thrown, indicating the
- // name is invalid
- ed.WriteMessage("\nInvalid layer name.");
- }
- // Commit the transaction
- tr.Commit();
- }
- }
- }
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |