- 积分
- 257
- 明经币
- 个
- 注册时间
- 2004-3-30
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2004-4-16 22:40:00
|
显示全部楼层
- Imports Autodesk.AutoCAD.ApplicationServices
- Imports Autodesk.AutoCAD.DatabaseServices
- Imports Autodesk.AutoCAD.Runtime
- Imports Autodesk.AutoCAD.Interop
- Imports Autodesk.AutoCAD.Geometry
- Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager
- Public Class TLCad
- <CommandMethod("test")> Public Shared Sub MytestCmd()
- Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
- Dim tm As DBTransMan = db.TransactionManager
- Dim myT As Transaction = tm.StartTransaction()
- Try
- Dim line As New Line(New Point3d(0, 0, 0), New Point3d(1, 1, 0))
- Dim bt As BlockTable = CType(tm.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable)
- Dim btr As BlockTableRecord = CType(tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False), BlockTableRecord)
- btr.AppendEntity(line)
- tm.AddNewlyCreatedDBObject(line, True)
- Dim tbl As RegAppTable = CType(myT.GetObject(db.RegAppTableId, OpenMode.ForWrite, False), RegAppTable)
- Dim app As New RegAppTableRecord
- app.Name = "test1"
- tbl.Add(app)
- tm.AddNewlyCreatedDBObject(app, True)
- line.XData = New ResultBuffer( _
- New TypedValue(CInt(DxfCode.ExtendedDataRegAppName), "test1"), _
- New TypedValue(CInt(DxfCode.ExtendedDataAsciiString), "tlcad test"))
- myT.Commit()
- Finally
- myT.Dispose()
- End Try
- End Sub
- End Class
看了上面的例子,有OBJECTARX的感觉!createLine()
{
AcGePoint3d startPt(4.0, 2.0, 0.0);
AcGePoint3d endPt(10.0, 7.0, 0.0);
AcDbLine *pLine = new AcDbLine(startPt, endPt); AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
pBlockTable->close(); AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId, pLine); pBlockTableRecord->close();
pLine->close(); return lineId;
}
|
|