Message 1 of 9
Create a new layer (C#)
Not applicable
12-01-2008
03:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok...I thought I would make a new thread and see what you guys thought.....
I would like to add the ability to make the layer a plot layer or a no plot layer but am not sure whether that is a boolean for PlotStyle property or what?
I am taking all the parameters from a Access database so we can just assume the parameters below are correct.
Any other suggestions or thoughts?
{code}
public void createLayer(string layerName, int layerColor, string layerLineType, string layerDescription)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
//start transaction
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
//Get current layerTable
LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForWrite);
//Make new layTable record
LayerTableRecord ltr = new LayerTableRecord();
//Set Layer Properties
ltr.Name = layerName;
//LayerColor value is being sent in as a int32 to converting to int32 fo byACi colorMethod. I am using numbers such as 251 and 5 as colors.
Int16 layerColorShort = Convert.ToInt16(layerColor);
ltr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, layerColorShort);
ltr.Description = layerDescription;
// get linetypeId....do line types always have the same id...for example is Continuous always the same id?
LinetypeTable lt2 = (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForRead);
foreach (ObjectId lineid in lt2)
{
LinetypeTableRecord ltr2 = (LinetypeTableRecord)tr.GetObject(lineid, OpenMode.ForRead);
if (ltr2.Name == layerLineType)
{
ltr.LinetypeObjectId = ltr2.Id;
}
}
//add newly created layer back to layerTable
lt.Add(ltr);
tr.AddNewlyCreatedDBObject(ltr, true);
tr.Commit();
}
catch
{
tr.Abort();
}
}
{code}
I would like to add the ability to make the layer a plot layer or a no plot layer but am not sure whether that is a boolean for PlotStyle property or what?
I am taking all the parameters from a Access database so we can just assume the parameters below are correct.
Any other suggestions or thoughts?
{code}
public void createLayer(string layerName, int layerColor, string layerLineType, string layerDescription)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
//start transaction
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
//Get current layerTable
LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForWrite);
//Make new layTable record
LayerTableRecord ltr = new LayerTableRecord();
//Set Layer Properties
ltr.Name = layerName;
//LayerColor value is being sent in as a int32 to converting to int32 fo byACi colorMethod. I am using numbers such as 251 and 5 as colors.
Int16 layerColorShort = Convert.ToInt16(layerColor);
ltr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, layerColorShort);
ltr.Description = layerDescription;
// get linetypeId....do line types always have the same id...for example is Continuous always the same id?
LinetypeTable lt2 = (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForRead);
foreach (ObjectId lineid in lt2)
{
LinetypeTableRecord ltr2 = (LinetypeTableRecord)tr.GetObject(lineid, OpenMode.ForRead);
if (ltr2.Name == layerLineType)
{
ltr.LinetypeObjectId = ltr2.Id;
}
}
//add newly created layer back to layerTable
lt.Add(ltr);
tr.AddNewlyCreatedDBObject(ltr, true);
tr.Commit();
}
catch
{
tr.Abort();
}
}
{code}