按名称和描述创建图层
你好!我不明白为什么我不能为新图层设置描述。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();
}
}
}
**** Hidden Message ***** 谢谢你,完美的作品!
但是我真的不明白,为什么我必须首先创建Layertablerecord类型的层,然后将Layertablerecord的Description-property作为字符串。
是不是和Acad-API有点不一致?!使用Layername属性,它在我创建新层之前工作。 谢谢大家,我明白了!/D
页:
[1]