t_alberty
2009-10-12, 02:15 AM
I'm new to AutoCAD (taking an intro community college course), and new to .Net (although at one point I was a competent VB6 programmer). I'm exploring how to modify .DWG's with .Net code. I've reviewed two articles (DE111-2 & DC115-2) and was able to get the example of adding "HelloWorld" text to a drawing working. Now I would like to add a circle to the drawing, but I'm not having any luck. Here is a code snippet based on the "HelloWorld" example:
Dim DB As Database
Dim BT As BlockTable
Dim MS As BlockTableRecord
'Start a transaction to edit the DWG Database
Using trans As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()
' Open Modelspace BlockTableRecord ready to add entity
DB = Application.DocumentManager.MdiActiveDocument.Database
BT = trans.GetObject(DB.BlockTableId, OpenMode.ForRead)
MS = trans.GetObject(BT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
'Create a new circle
Dim oCir As Circle = New Circle
MS.AppendEntity(oCir)
trans.AddNewlyCreatedDBObject(oCir, True)
trans.Commit()
End Using
Visual Studio does not like the MS.AppendEntry or trans.AddNewly... I get a Value of type 'Circle.Circle' cannot be be converted to ... Database.Entity.
I surely don't understand the Object Model yet as I would expect to be able to set properties (e.g. center point and radius) of the circle that I created like this:
oCir.Orign(0,0)
oCir.Radius(1)
Does anyone have any code that they can share that would help me 1) draw a circle and 2) begin to understand the object model?
Thanks,
Tom
Dim DB As Database
Dim BT As BlockTable
Dim MS As BlockTableRecord
'Start a transaction to edit the DWG Database
Using trans As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()
' Open Modelspace BlockTableRecord ready to add entity
DB = Application.DocumentManager.MdiActiveDocument.Database
BT = trans.GetObject(DB.BlockTableId, OpenMode.ForRead)
MS = trans.GetObject(BT(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
'Create a new circle
Dim oCir As Circle = New Circle
MS.AppendEntity(oCir)
trans.AddNewlyCreatedDBObject(oCir, True)
trans.Commit()
End Using
Visual Studio does not like the MS.AppendEntry or trans.AddNewly... I get a Value of type 'Circle.Circle' cannot be be converted to ... Database.Entity.
I surely don't understand the Object Model yet as I would expect to be able to set properties (e.g. center point and radius) of the circle that I created like this:
oCir.Orign(0,0)
oCir.Radius(1)
Does anyone have any code that they can share that would help me 1) draw a circle and 2) begin to understand the object model?
Thanks,
Tom