GreenMan415
2009-11-19, 04:39 PM
I need to do a simple regen command at the end of my program, even though I have it set the program does not enact the regen. Any thoughts? It is probably something simple.
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Interop;
[assembly: CommandClass(typeof(RemodelDWG.Commands))]
namespace RemodelDWG
{
/// <summary>
/// Remodel DWG: Program that will clean up any translation file from ARRIS for Remodel use.
/// </summary>
public class Commands
{
public Commands()
{
//
// TODO: Add constructor logic here
//
}
// Define Command "Remodel"
[CommandMethod("Remodel")]
static public void RemodelDWG() // This method can have any name
{
//Set current application session
AcadApplication app;
app = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
// Get current DWG Database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDB = acDoc.Database;
//Start Transaction to play with DWG.
using (Transaction acTran = acDB.TransactionManager.StartTransaction())
{
//Open current drawing layer table listing and read.
LayerTable acLayerTbl;
acLayerTbl = acTran.GetObject(acDB.LayerTableId, OpenMode.ForRead)as LayerTable;
// Create an ObjectIdCollection to hold the object ids for each table record
ObjectIdCollection acObjCol = new ObjectIdCollection();
// Step through each layer and add iterator to the ObjectIdCollection
foreach (ObjectId acObjId in acLayerTbl)
{
acObjCol.Add(acObjId);
}
foreach (ObjectId acObjId in acObjCol)
{
//Get all layers in the database
LayerTableRecord acLayerTblRec;
acLayerTblRec = acTran.GetObject(acObjId, OpenMode.ForWrite) as LayerTableRecord;
//unlock all layers one by one
acLayerTblRec.IsLocked = false;
}
//Section to set remodel hatch layer color
string sLayerName = "011remeqxh";
if (acLayerTbl.Has(sLayerName) == true)
{
LayerTableRecord acLayerTblRec;
acLayerTblRec = acTran.GetObject(acLayerTbl[sLayerName], OpenMode.ForWrite) as LayerTableRecord;
acLayerTblRec.Color = Color.FromColorIndex(ColorMethod.ByLayer, 254);
}
app.ZoomExtents();
acDoc.Editor.Regen();
acTran.Commit(); // run all commands and save current state.
}
}
}
}
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Interop;
[assembly: CommandClass(typeof(RemodelDWG.Commands))]
namespace RemodelDWG
{
/// <summary>
/// Remodel DWG: Program that will clean up any translation file from ARRIS for Remodel use.
/// </summary>
public class Commands
{
public Commands()
{
//
// TODO: Add constructor logic here
//
}
// Define Command "Remodel"
[CommandMethod("Remodel")]
static public void RemodelDWG() // This method can have any name
{
//Set current application session
AcadApplication app;
app = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
// Get current DWG Database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDB = acDoc.Database;
//Start Transaction to play with DWG.
using (Transaction acTran = acDB.TransactionManager.StartTransaction())
{
//Open current drawing layer table listing and read.
LayerTable acLayerTbl;
acLayerTbl = acTran.GetObject(acDB.LayerTableId, OpenMode.ForRead)as LayerTable;
// Create an ObjectIdCollection to hold the object ids for each table record
ObjectIdCollection acObjCol = new ObjectIdCollection();
// Step through each layer and add iterator to the ObjectIdCollection
foreach (ObjectId acObjId in acLayerTbl)
{
acObjCol.Add(acObjId);
}
foreach (ObjectId acObjId in acObjCol)
{
//Get all layers in the database
LayerTableRecord acLayerTblRec;
acLayerTblRec = acTran.GetObject(acObjId, OpenMode.ForWrite) as LayerTableRecord;
//unlock all layers one by one
acLayerTblRec.IsLocked = false;
}
//Section to set remodel hatch layer color
string sLayerName = "011remeqxh";
if (acLayerTbl.Has(sLayerName) == true)
{
LayerTableRecord acLayerTblRec;
acLayerTblRec = acTran.GetObject(acLayerTbl[sLayerName], OpenMode.ForWrite) as LayerTableRecord;
acLayerTblRec.Color = Color.FromColorIndex(ColorMethod.ByLayer, 254);
}
app.ZoomExtents();
acDoc.Editor.Regen();
acTran.Commit(); // run all commands and save current state.
}
}
}
}