PDA

View Full Version : Help drawing a circle using VB.Net



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

Coolmo
2009-10-12, 01:35 PM
I usually don't like redirecting questions to a link but check out the AutoCAD .NET Developer's Guide for this. You won't be disappointed.

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html

Hopefully this link gets you there. This thing is pretty amazing for getting you started on all kinds of .NET programming for AutoCAD and goes over most of the basics including inserting all kinds of entities, setting up and switching layers, creating selection sets, etc. Not to mention it describes the basic structure of AutoCAD and all of its "objects" which helps out tremendously when you start to really dive into this stuff. Enjoy.

Coolmo
2009-10-12, 02:07 PM
BTW, I posted a .NET reply here because I assumed that this would be moved to the .NET forum soon...

t_alberty
2009-10-12, 09:59 PM
Thanks! I haven't had time to dig deep, but my initial impression is this will really help me.

I appreciate your quick response!

Tom