Since Autodesk is telling us that we need to go through
transactions to open objects, the TransactionManager's
methods that operate on the top transaction become
more important, because there can be many cases where
objects need to be opened for read, to examine them and
then closed immediately. Encapsulating something like
that into a library function would otherwise require it to
start and end a transaction just to open one object.
With the transaction manager, a library function that opens
an object can use the top transaction (if there is one) to do
it without having to incurr the overhead of starting/ending a
transaction
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com
wrote in message news:4880032@discussion.autodesk.com...
thanks albert.
Since there is no difference between TransactionManager and Transaction. in the following two methods ,Could you point out which
one is better.
//method 1
public static void MainApp ( )
{
Database db = HostApplicationServices.WorkingDatabase;
TransactionManager tm = db.TransactionManager;
Transaction trans = tm.StartTransaction();
try
{
LayerTableRecord ltr = new LayerTableRecord();
ltr.Name = "S_Cols_Pat1";
ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 251);
AddLayer(ltr, trans);
trans.Commit();
}
finally { trans.Dispose(); }
}
public static ObjectId AddLayer( LayerTableRecord ltr , Transaction trans)
{
ObjectId retId = ObjectId.Null;
LayerTable lt = trans.GetObject(Db.LayerTableId, OpenMode.ForWrite, false) as LayerTable;
if (!lt.Has(ltr.Name))
{
retId = lt.Add(ltr);
trans.AddNewlyCreatedDBObject(ltr, true);
}
else
{
retId = lt[ltr.Name];
}
return retId;
}
//method 2
public static void MainApp()
{
Database db = HostApplicationServices.WorkingDatabase;
TransactionManager tm = db.TransactionManager;
Transaction trans = tm.StartTransaction();
try
{
LayerTableRecord ltr = new LayerTableRecord();
ltr.Name = "S_Cols_Pat1";
ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 251);
AddLayer(ltr);
trans.Commit();
}
finally { trans.Dispose(); }
}
public static ObjectId AddLayer( LayerTableRecord ltr )
{
Database db = HostApplicationServices.WorkingDatabase;
TransactionManager tm = db.TransactionManager;
ObjectId retId = ObjectId.Null;
LayerTable lt = tm.GetObject(Db.LayerTableId, OpenMode.ForWrite, false) as LayerTable;
if (!lt.Has(ltr.Name))
{
retId = lt.Add(ltr);
tm.AddNewlyCreatedDBObject(ltr, true);
}
else
{
retId = lt[ltr.Name];
}
return retId;
}