.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to make codes form VBA works in VB.net

7 REPLIES 7
Reply
Message 1 of 8
_Tharwat
760 Views, 7 Replies

How to make codes form VBA works in VB.net

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

7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: _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. 

 

 

 

 

Message 3 of 8
arcticad
in reply to: Anonymous

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

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 4 of 8
_Tharwat
in reply to: arcticad

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

Message 5 of 8
Anonymous
in reply to: _Tharwat

In VB.NET a module is a shared class ---- a static class in C#.

 

 

Message 6 of 8
_Tharwat
in reply to: Anonymous

How to reach that Jeff .

 

Thanks

Message 7 of 8
StephenPreston
in reply to: _Tharwat

The VBA to VB.NET migration videos at the bottom of this webpage might be helpful to you - www.autodesk.com/vba.

 

 

Cheers,

Stephen Preston
Autodesk Developer Network
Message 8 of 8
chiefbraincloud
in reply to: Anonymous

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.

Dave O.                                                                  Sig-Logos32.png

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost