• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Mentor
    Posts: 370
    Registered: ‎09-23-2004

    Re: Accessing AcadDocument and AcadApplication via .NET assembly

    02-05-2013 04:30 PM in reply to: Balaji_Ram

    Hello,

    I've looked into that code, but I couldn't get it to convert to VB.net.  Do you have a VB version? 

     

    Thanks,

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,167
    Registered: ‎04-09-2008

    Re: Accessing AcadDocument and AcadApplication via .NET assembly

    02-05-2013 10:27 PM in reply to: mgorecki

    mgorecki wrote:

    Hello,

    I've looked into that code, but I couldn't get it to convert to VB.net.  Do you have a VB version? 

     

    Thanks,


    What about using online C# <-> VB.NET converter?


    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.
    Mentor
    Posts: 370
    Registered: ‎09-23-2004

    Re: Accessing AcadDocument and AcadApplication via .NET assembly

    02-06-2013 07:17 AM in reply to: Alexander.Rivilis

    I've tried 2 different c# to VB converters and they both give me the same message, but for differing lines:

    "An error occured converting your code, probably due to a syntax error:-- line 12 col 3: EOF expected"

    I removed the extra spaces and changed the 17.1 to 18.0, but I still get the same error.

    using System;
    using System.Runtime.InteropServices;
    using Autodesk.AutoCAD.Interop;
    
    //This C# code can be added to an “on-click” event handler for a button (for example) or another function
    //that makes sense in the context of your application.
    
      // "AutoCAD.Application.17" uses 2007 or 2008,
      //  whichever was most recently run
      // "AutoCAD.Application.17.1" uses 2008, specifically
    
      const string progID = "AutoCAD.Application.18.0";
      AcadApplication acApp = null;
    
      try
      {
        acApp = (AcadApplication)Marshal.GetActiveObject(progID);
      }
      catch
      {
        try
        {
          Type acType = Type.GetTypeFromProgID(progID);
          acApp = (AcadApplication)Activator.CreateInstance(acType, true);
        }
        catch
        {
          MessageBox.Show("Cannot create object of type \"" + progID + "\"");
        }
      }
      if (acApp != null)
      {
        // By the time this is reached AutoCAD is fully
        // functional and can be interacted with through code
    
        acApp.Visible = true;
        acApp.ActiveDocument.SendCommand("_MYCOMMAND ");
      }

     

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,167
    Registered: ‎04-09-2008

    Re: Accessing AcadDocument and AcadApplication via .NET assembly

    02-06-2013 07:47 AM in reply to: mgorecki
    Imports System
    Imports System.Runtime.InteropServices
    Imports Autodesk.AutoCAD.Interop
    
    Namespace Test
        Public Class Test
            Public Shared Sub StartAutoCAD()
                ' "AutoCAD.Application.17" uses 2007, 2008, 2009
                '  whichever was most recently run
                ' "AutoCAD.Application.17.1" uses 2008, specifically
                ' "AutoCAD.Application.18" uses 2010, 2011, 2012
                ' "AutoCAD.Application.18.1" uses 2011, specifically
                ' "AutoCAD.Application.19" uses 2013,...
    
                Const progID As String = "AutoCAD.Application.19"
                Dim acApp As AcadApplication = Nothing
    
                Try
                    acApp = DirectCast(Marshal.GetActiveObject(progID), AcadApplication)
                Catch
                    Try
                        Dim acType As Type = Type.GetTypeFromProgID(progID)
                        acApp = DirectCast(Activator.CreateInstance(acType, True), AcadApplication)
                    Catch
                        MessageBox.Show("Cannot create object of type """ & progID & """")
                    End Try
                End Try
    
                If acApp IsNot Nothing Then
                    ' By the time this is reached AutoCAD is fully
                    ' functional and can be interacted with through code
                    acApp.Visible = True
                    acApp.ActiveDocument.SendCommand("_MYCOMMAND ")
                End If
            End Sub
        End Class
    End Namespace

    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.
    Mentor
    Posts: 370
    Registered: ‎09-23-2004

    Re: Accessing AcadDocument and AcadApplication via .NET assembly

    02-07-2013 07:31 AM in reply to: Alexander.Rivilis

    Hi Alexander,

    This gets long, but I'm hoping you can help me out with this.

    The scenario:

    We have a web app that launches one program (just like the one below).  I add code to let the web app know AutoCad is running.

    The web app then sends an array to another function in the same program.  The array sent has a handful of keys and variables.  My function reads the keys and variables to determine a second program to launch in Autocad (there are three potential programs to launch, the variables will let the code know which one to launch).

    Once it knows, how does it go about doing the "netload", entering the path and .dll name of the program to launch, and then sending the command to launch the program (keeping in mind the program to launch will need to receive data, like passing the values of the variables)?

     

    Thank you so much for helping me this far.

    Mark

    Please use plain text.
    Mentor
    Posts: 370
    Registered: ‎09-23-2004

    Re: Accessing AcadDocument and AcadApplication via .NET assembly

    02-07-2013 10:32 AM in reply to: Alexander.Rivilis

    Hello Alexander,

    I think I found something that could work:

    acApp.ActiveDocument.SendCommand("(command " & Chr(34) & "NETLOAD" & Chr(34) & " " & _

     Chr(34) & "C:\myFiles\myProgram.dll" & Chr(34) & ") ")

     

    If that would work, and I have a sub called "POD" that's expecting an array, can I use acApp.ActiveDocument.SendCommand("(command "POD(arrayName)")")

     

     

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,167
    Registered: ‎04-09-2008

    Re: Accessing AcadDocument and AcadApplication via .NET assembly

    02-07-2013 10:36 AM in reply to: mgorecki

    I think I began to understand what you want. But you can not pass array to command any way.


    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.