Active Member
Posts: 6
Registered: ‎08-12-2005
Message 1 of 2 (95 Views)

Accessing existing VBA macros through .NET

95 Views, 1 Replies
08-15-2005 09:22 AM
I'm trying to do a few things through a windows application using VB.Net:

1) open autocad and a specific drawing
2) run an existing VBA function w/ input parameters from .NET form
3) return outputs from VBA macro to .NET application

Is this possible? I'm a newbie to VB.NET but proficient in VBA. I've successfully opened the drawing I need using unmanaged code with my .NET form:

Imports System.Data.OleDb
Imports System.Math
Imports System.Runtime
Imports System.Runtime.InteropServices
Imports System.Runtime.InteropServices.Marshal
Imports System.Windows.Forms
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub MySub()
Connect2ACAD() 'procedure that checks for running autocad and opens new if not open.
Dim oApp As AcadApplication
Dim oDoc As AcadDocument
oApp = GetActiveObject("AutoCAD.Application.16")
oApp.Visible = True
oDoc = oApp.Documents.Open(filenam)
End Sub
End Class

The inputs and outputs of the function I have in VBA are all double datatype where the output is the area of a region created.
I know there's a RunMacro command, but this can't be used with input parameters or outputs. Any help whatsoever would be greatly appreciated - including better methods to start from scratch. Thanks,

Posts: 0
Message 2 of 2 (95 Views)

Re: Accessing existing VBA macros through .NET

08-23-2005 01:46 PM in reply to: SuperFly
The only way I figured out how to get around it is the same way that I get LISP to talk with VBA or VB .net...Have the VB.net program write a txt file with the data needed for the VBA function...Then VBA reads in the file selecting what it needs...Then VBA writes out a file that tells VB.net what it needs...If you use "RunMacro" I think .net waits for it to finish...I could be wrong though...I know that if you run it from the command line via "SendCommand" .net waits...I know this is a conveluded way to do it, but I have no idea how else to make it work...Hope this helped...
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.