PDA

View Full Version : Simple Regen?



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.
}

}

}
}

fixo
2009-11-19, 10:09 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.


This code is working good on my end
The 'regenmode' varialble is set to 1

~'J'~

GreenMan415
2009-11-20, 02:24 PM
Fixo,

I checked the regenmode and it is set to 1. However it does not regen for me. I have to still manually do a regen. Thoughts?

GreenMan415
2009-11-20, 06:13 PM
Disregard, I found a fix. I threw a app update after the regen and it works fine.

fixo
2009-11-20, 10:47 PM
Disregard, I found a fix. I threw a app update after the regen and it works fine.

Glad if so
Nice code btw I like it
Keep programming
All successes

~'J'~