Hello everybody .
I am new to VB.net and I just wondering if it is possible to use some codes that we use in VBA into VB.net , things like this .
Public Sub AddTheCircle() Dim p(0 To 2) As Double, r As Double p(0) = 10: p(1) = 50: p(2) = 0 r = 150 ThisDrawing.ModelSpace.AddCircle p, r End Sub
If not , so how to start with VB.net parallel to Autocad ?
Many thanks.
Tharwat
Hello TharwaT313,
Of Course you can use VBA code still. To a point.
VBA code will work "through the ActiveX® Automation library" still using the
Imports Autodesk.AutoCAD.Interop
Keep searching and I'm sure you'll find further tutorials of how to do this.
here's some sample code for creating a circle in VBA style and .Net
Imports Autodesk.AutoCAD.Interop Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Geometry Public Class Class1 <Autodesk.AutoCAD.Runtime.CommandMethod("VBACircle")> _ Public Sub AddVBACircle() Dim p(0 To 2) As Double, r As Double p(0) = 10 : p(1) = 50 : p(2) = 0 r = 150 Dim thisDrawing As Object = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument() thisDrawing.ModelSpace.AddCircle(p, r) End Sub <Autodesk.AutoCAD.Runtime.CommandMethod("NETCircle")> _ Public Shared Sub AddNetCircle() Dim p As New Point3d(10, 50, 0), r As Double = 150 Using db As Database = HostApplicationServices.WorkingDatabase() Using tr As Transaction = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction() Dim myDWG As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Using lock As DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument Dim cir As New Circle() cir.SetDatabaseDefaults() cir.Radius = r cir.Center = p Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable) Dim ms As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) Dim mtId As ObjectId mtId = ms.AppendEntity(cir) tr.AddNewlyCreatedDBObject(cir, True) tr.Commit() End Using End Using End Using End Sub End Class
Thank you guys ,
In VBA there is a spcae called Module that I could run the codes from it , so I looked for it in VB.net but I could not come
with a result .
Could you please tell me where to put the codes to start debugging codes for the action ?
Sorry for my poor informations about VB.net because I am looking for the first deck to start steping from it .
many thanks
Tharwat
The VBA to VB.NET migration videos at the bottom of this webpage might be helpful to you - www.autodesk.com/vba.
In VB.NET a Module is a Module. A class is a class. They are not the same thing. Classes can not be declared Shared, only members of classes can be declared Shared.