事务和ObjectIds
在 .NET API中,读取根Civil 文档的代码需要用到Autodesk.AutoCAD.DatabaseServices.TransactionManager 对象来开始/提交一个事务。用Using语句来管理一个事务(Transaction)是个好习惯,它可以在代码块的最后自动处理事务(Transaction);否则事务(Transaction)需要在一个Try-Finally block的Finally部分进行相对复杂的处理。这里有一个在Using代码块中使用事务(Transaction)的例子:
using (Transaction trans=TransactionManager.StartTransaction())
{
//operation here
trans.Commit();
}
注意:
请参照AutoCAD .NET Developer’s Guide中的 "Use Transactions With the Transaction Manager (.NET)"部分获取更多使用事务(Transaction)对象来打开和编辑图文件数据库对象的信息。
在.NET API中,大多数情况下从一个集合中获取到的其实是一个ObjectId对象,需要通过一个事务(Transaction)对象获取到其本来的类型(由TransactionManager.StartTransaction()返回)。下面是一个例子:
m_AligmentStyleId = m_doc.Styles.AlignmentStyles.Item(sStyleName)
oAlignmentStyle = m_trans.GetObject(m_AligmentStyleId, OpenMode.ForWrite) As AlignmentStyle
父主题: