代码来源于本人近期项目中,主要功能是创建新图层,并设置图层属性,读者可以通过相关的一些更改来达到另一些功能,比如说修改图层一些属性的功能。(辽宁工程技术大学,辽宁多维科技,秦凯)
/// <summary>
param name
/// 创建图层(注意不可将冻结的图层设置为当前图层,否则会创建失败,且返回 eInvalidInput)
/// </summary>
/// <param name="layerName">创建的图层名称</param>
/// <param name="colorIndex">颜索引</param>
/// <param name="lineType">线型名称</param>
/// <param name="lineTypeFile">线型文件</param>
/// <param name="lineWeight">线宽</param>
/// <param name="bIsOff">开关图层</param>
/// <param name="bIsFreezed">冻结图层</param>
/// <param name="bIsLocked">锁定图层</param>
/// <param name="bIsCurrent">设置当前图层</param>
/// <returns></returns>
static public ObjectId CreateLayer(String layerName, short colorIndex, String lineType, String lineTypeFile, LineWeight lineWeight, bool bIsOff, bool bIsFreezed, bool bIsLocked, bool bIsCurrent)
{
colorIndex = (short)(colorIndex % 256);
ObjectId idRet = ObjectId.Null;
try
{
using (Transaction trans = (Transaction)db.TransactionManager.StartTransaction())
{
LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite);
if (lt.Has(layerName))
{
idRet = lt[layerName];
LayerTableRecord ltr = (LayerTableRecord)trans.GetObject(idRet, OpenMode.ForWrite);
ltr.IsOff = bIsOff;
ltr.IsFrozen = bIsFreezed;
ltr.IsLocked = bIsLocked;
ltr.Color = Color.FromColorIndex(ColorMethod.ByColor, colorIndex);
ltr.LineWeight = lineWeight;
ltr.LinetypeObjectId = LoadLineType(lineType, lineTypeFile);
if (bIsCurrent)
db.Clayer = idRet;
}
else
{
LayerTableRecord ltr = new LayerTableRecord();
ltr.Name = layerName;
ltr.IsOff = bIsOff;
ltr.IsFrozen = bIsFreezed;
ltr.IsLocked = bIsLocked;
ltr.Color = Color.FromColorIndex(ColorMethod.ByColor, colorIndex);
ltr.LineWeight = lineWeight;
ltr.LinetypeObjectId = LoadLineType(lineType, lineTypeFile);
idRet = lt.Add(ltr);
trans.AddNewlyCreatedDBObject(ltr, true);
if (bIsCurrent)
db.Clayer = idRet;
}
trans.Commit();
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
return idRet;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。