[CommandMethod("assignlinetype")]
public static void assignlinetype()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
LayerTable acLyrTbl;
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
OpenMode.ForRead) as LayerTable;
LinetypTable acLineTbl;
acLineTbl = acTrans.GetObject(acCurDb.LinetypeTableId,
OpenMode.ForRead) as LinetypeTable;
string[] acLinetypes
= new string[3]; acLinetypes[0] = "hidden10"
acLinetypes[1] = "center10"
acLinetypes[2] = "dot10"
foreach (string linetype in acLinetypes)
if (acLineTypTbl.Has(sLineTypName) == false)
{
acCurDb.LoadLineTypeFile(sLineTypName, "acad.lin");
}
// how do I error handle this if true???
string[] sLayerNames
= new string[3]; sLayerNames[0] = "ACIRed";
sLayerNames[1] = "TrueBlue";
sLayerNames[2] = "ColorBookYellow";
Color
[] acColors
= new Color
[3]; acColors[0] = Color.FromColorIndex(ColorMethod.ByAci, 1);
acColors[1] = Color.FromColorIndex(ColorMethod.ByAci, 1);
acColors[2] = Color.FromColorIndex(ColorMethod.ByAci, 1);
// can I have an array here that references linetypes to the layers?
int nCnt = 0;
foreach (string sLayerName in sLayerNames)
{
if (acLyrTbl.Has(sLayerName) == false)
{
using (LayerTableRecord acLyrTblRec
= new LayerTableRecord
()) {
acLyrTblRec.Name = sLayerName;
if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen();
acLyrTbl.Add(acLyrTblRec);
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
acLyrTblRec.Color = acColors[nCnt];
// should there be a linetype reference here ?
}
}
else
{
LayerTableRecord acLyrTblRec = acTrans.GetObject(acLyrTbl[sLayerName],
OpenMode.ForWrite) as LayerTableRecord;
acLyrTblRec.Color = acColors[nCnt];
// should there be a linetype reference here do I load the linetype table record for write now ?
}
nCnt = nCnt + 1;
}
acTrans.Commit();
}
}