Jump to content

Linking an opened AutoCAD Session to VB.net


Recommended Posts

Posted

In order to use AutoCAD commands with VB.net do you allways have to use code

to open an AutoCAD Session in the VB.net or can you access

an AutoCAD session that is opened before the VB.net program is started.

 

Most of the AutoCAD.net tutorials I have look at use VB.net code to open an AutoCAD session then

use VB.net code to activate AutoCAD commands in that session. I prefer to have

my VB.net access an AutoCAD session that is allready open but I don't know

if that is possable. If it is possable is there any code to demo that.

Than you,

Posted

It sounds like you're attempting to code a stand-alone .EXE rather than an AutoCAD plug-in (.DLL)... What are you trying to code (specifically)?

 

I typically code the latter, so that the desired functionality is available to AutoCAD, rather than controlling it from outside of the AutoCAD environment.

 

If you are attempting to access an already open session (via .EXE), then you should access the Application Object via the Process. Otherwise, if no Process exists, then create the Application Object.

 

If accessing the Application Object from a plug-in that has been NETLOAD-ed into your AutoCAD session, then simply access the Autodesk.AutoCAD.ApplicationServices.Application Class.

 

HTH

Posted

I would like to first open a AutoCAD session then write a VB.net program to access the commands on that

session that has been opened.

Posted
I would like to first open a AutoCAD session then write a VB.net program to access the commands on that session that has been opened.
You can do that with Autolisp and AutoCAD VBA

(Using Vbaman command) but not with AutoCAD.net?

Posted
I would like to first open a AutoCAD session then write a VB.net program to access the commands on that

session that has been opened.

 

... From what, an .EXE?

 

... In order to do what?

 

... What commands?

 

Please, be more specific.

Posted
Imports System.IO
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.Interop
Imports System.Runtime.InteropServices
Namespace ConsoleApplication1
Class Program
 Const progIDstr As String = "AutoCAD.Application.18.1"
 Private Shared Sub Main(args As String())
  Dim app As AcadApplication = Nothing
  Try
   Try
    app = Marshal.GetActiveObject(progIDstr)
    app.Visible = True
   Catch
    app = New AcadApplicationClass()
    app.Visible = True
   End Try
  Catch ex As Exception
   Console.WriteLine("Canot start AutoCAD: " & ex.Message)
   Return
  End Try

  Dim doc As AcadDocument = Nothing
  If app.Documents.Count > 1 Then
   doc = app.ActiveDocument
  Else
   doc = app.Documents.Add("acad.dwt")
  End If
  If doc Is Nothing Then
   Console.WriteLine("No drawing is open")
   Return
  End If
  Try
   doc.SendCommand("C 0,0,0 10 ")
  Catch ex As Exception
   Console.WriteLine("Importing failed: " & ex.Message)
   Console.ReadLine()
   Return
  End Try
 End Sub
End Class
End Namespace


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...