Author Topic: Autodesk.AutoCAD.Interop  (Read 19885 times)

0 Members and 1 Guest are viewing this topic.

Kurtz David

  • Guest
Autodesk.AutoCAD.Interop
« on: October 30, 2013, 03:40:48 AM »
Hello,
I'm trying to Import the Autodesk.AutoCAD.Interop without Successe.
Attached is a Print screen (of my references).

thanks in advance,
David.

Bert

  • Guest
Re: Autodesk.AutoCAD.Interop
« Reply #1 on: October 30, 2013, 04:09:40 AM »
 Did you select these two items from the COM tab of the Add References dialog:

AutoCAD (version) Type Library
AutoCAD/ObjectDBX Common 17.0 Type Library

Kurtz David

  • Guest
Re: Autodesk.AutoCAD.Interop
« Reply #2 on: October 30, 2013, 04:16:34 AM »
Hello,
I have added the "AutoCAD (version) Type Library" from the COM tab and the problem has been fixed.
will the dll will work when the AutoCAD version will be changed?

Thanks,
David.

Bert

  • Guest
Re: Autodesk.AutoCAD.Interop
« Reply #3 on: October 30, 2013, 04:38:26 AM »
Not used to work with COM Interoperability with .NET, but i think it is version-dependent.

BlackBox

  • King Gator
  • Posts: 3770
Re: Autodesk.AutoCAD.Interop
« Reply #4 on: October 30, 2013, 08:58:01 AM »
COM is version, and environment-dependent (i.e., R18x86, R18x64, R19x86, R19x64, etc.)... Unless you use late-binding, which does not require the COM assembly references (by nature of the object Type), and can be compiled to 'Any CPU' (which supports both x86, and x64 environments).

In any event, to add the necessary COM assembly references, simply right click on your project's "References" node, and select "Add Reference...", then use the Browse tab to navigate to your target version's ObjectARX SDK and add Autodesk.AutoCAD.Interop.Common.dll & Autodesk.AutoCAD.Interop.dll from either the ..\inc-win32\, or ..\inc-x64\ folder respectively.

HTH

"How we think determines what we do, and what we do determines what we get."

Bert

  • Guest
Re: Autodesk.AutoCAD.Interop
« Reply #5 on: October 30, 2013, 09:25:59 AM »
Thanks BlackBox for clearing that up, I wasn't sure about the details myself

BlackBox

  • King Gator
  • Posts: 3770
Re: Autodesk.AutoCAD.Interop
« Reply #6 on: October 30, 2013, 09:32:38 AM »
Thanks BlackBox for clearing that up, I wasn't sure about the details myself

You're welcome; I'm happy to help.



Also, as an example of Late Binding, here's a DevBlog article you may, or may not find useful.

Cheers
"How we think determines what we do, and what we do determines what we get."

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Autodesk.AutoCAD.Interop
« Reply #7 on: October 30, 2013, 01:38:06 PM »
Quote
Also, as an example of Late Binding, here's a DevBlog article you may, or may not find useful.

Also, if your using .NET 4.0 you can use dynamic casting in lieu of late binding.
Code: [Select]
object acadObject = Application.AcadApplication;
    object preferences =
            acadObject.GetType().InvokeMember("Preferences",
            BindingFlags.GetProperty,
            null, acadObject, null);

You can use this instead
Code: [Select]
dynamic acadObject = Application.AcadApplication;
var preferences = acadObject.Preferences;
Revit 2019, AMEP 2019 64bit Win 10

BlackBox

  • King Gator
  • Posts: 3770
Re: Autodesk.AutoCAD.Interop
« Reply #8 on: October 30, 2013, 01:47:52 PM »
Quote
Also, as an example of Late Binding, here's a DevBlog article you may, or may not find useful.

Also, if your using .NET 4.0 you can use dynamic casting in lieu of late binding.
Code: [Select]
object acadObject = Application.AcadApplication;
    object preferences =
            acadObject.GetType().InvokeMember("Preferences",
            BindingFlags.GetProperty,
            null, acadObject, null);

You can use this instead
Code: [Select]
dynamic acadObject = Application.AcadApplication;
var preferences = acadObject.Preferences;

I completely forgot about Tony making a similar suggestion a while back - Most of my development has been in .NET 3.5 due to what version(s) we use at work, but now that I've started publishing apps at Exchange, and for posting code in forums now generally, I really should utilize this methodology.

Many thanks for the reminder!

Cheers
"How we think determines what we do, and what we do determines what we get."

Kurtz David

  • Guest
Re: Autodesk.AutoCAD.Interop
« Reply #9 on: November 05, 2013, 09:17:12 AM »
Hello All (All you smart guys),
If I choose to add the interop dlls from the objectARX SDK I have downloaded from Autodesk.
(Then) will it be possible to add few dlls so the application will work with few versions of AutoCAD?
(I am working with AutoCAD 2010 and when I have added the interop dll from the objectARX I have to remove the reference to the AutoCAD COM interop)

Thanks in advance,
David.

BlackBox

  • King Gator
  • Posts: 3770
Re: Autodesk.AutoCAD.Interop
« Reply #10 on: November 05, 2013, 12:45:38 PM »
Hello All (All you smart guys)...

You must be talking to 'them'... I'm just a production guy.  :lol:

If I choose to add the interop dlls from the objectARX SDK I have downloaded from Autodesk.
(Then) will it be possible to add few dlls so the application will work with few versions of AutoCAD?
(I am working with AutoCAD 2010 and when I have added the interop dll from the objectARX I have to remove the reference to the AutoCAD COM interop)

Not sure I follow....

If you're to use COM, without Late Binding (or dynamic), your project must include the above mentioned Interop assemblies, and they should both be set 'Copy Local == False'. This lets you implement what you need from the SDK, and at runtime, your assembly will automagically be using the Interop assemblies that are installed with the product itself (and not those from SDK).

If you've previously referenced the Interop assemblies from the product's install folder, yes, you'd remove them as you need (are allowed) only one instance (or just attach the new SDK versions, which I believe replaces?).

Hope that makes (more?) sense.

Cheers
"How we think determines what we do, and what we do determines what we get."

Kurtz David

  • Guest
Re: Autodesk.AutoCAD.Interop
« Reply #11 on: November 05, 2013, 07:18:19 PM »
Hello,
In short, my question is, is it possible to create an application using the interop that will work on both AutoCAD 2010 and 2012?
(If YES then How?)

Thanks in advance,
David

BlackBox

  • King Gator
  • Posts: 3770
Re: Autodesk.AutoCAD.Interop
« Reply #12 on: November 05, 2013, 09:52:45 PM »
Hello,
In short, my question is, is it possible to create an application using the interop that will work on both AutoCAD 2010 and 2012?
(If YES then How?)

Thanks in advance,
David

Create a project, add Interop assembly references from the 2012 SDK (Copy Local == False), compile project to .NET 3.5 framework, both for x86, and x64 (Again, since you're not using Late Binding, or .NET 4.0's dynamic Type)... NETLOAD, Registry load, or load via Autoloader .bundle. Lemon squeezy.
"How we think determines what we do, and what we do determines what we get."

Kurtz David

  • Guest
Re: Autodesk.AutoCAD.Interop
« Reply #13 on: November 06, 2013, 01:49:47 AM »
In case somebody will need a similar application in the future I'm uploading the result.
(and as a gratitude to all the help I got here)

I'm the "Jack of all trades" in my site, among all the my responsibilities I'm the CAD administrator as well.

We are about to upgrade all of our site's AutoCAD and we need to install for every installation our "in-house" applications.

To install an application we need to:
1.   Add the path to the AutoCAD's search pathes.
2.   Add the Application to the AutoCAD Automatic load suitcase.
3.   Add the Cui as a partial CUI
4.   Show to toolbars.

The attached application does all of the above for me with one simple click.
(I have to do one last modification to the application which will be to load all the lists from an XML or simple txt file)

Thanks again to you all.
David.


Code: [Select]
Imports Autodesk.AutoCAD.Runtime
'Imports Autodesk.AutoCAD.EditorInput
'Imports Autodesk.AutoCAD.Geometry
'Imports Autodesk.AutoCAD.Interop
'Imports Autodesk.AutoCAD.Colors
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.ApplicationServices

Imports System.IO
Imports Microsoft.Win32

Public Class IDEAddAplications
    <CommandMethod("AddIDEApplications", CommandFlags.UsePickSet)>
    Public Sub AddIDEApplications()
        Dim UseConsole As Boolean = False
        Dim RunMode As Integer

        RunMode = 10

        ''Application Part 1 - Add Pathes to Search Pathes
        If RunMode = 1 Or RunMode = 10 Then
            Dim Pathes As New List(Of String)
            Pathes.Add("C:\AutoCAD VBA Codes\Bentley Advanced")
            Pathes.Add("C:\AutoCAD VBA Codes\BOMOUT Style 2 + CatPart - NO JYAI")
            Pathes.Add("C:\AutoCAD VBA Codes\BOMOUT Style 3 - NO JYAI")
            Pathes.Add("C:\AutoCAD VBA Codes\CatPart With Blocks 64")
            Pathes.Add("C:\AutoCAD VBA Codes\Excel Imports")
            Pathes.Add("C:\AutoCAD VBA Codes\PostIsometrics")
            Pathes.Add("C:\AutoCAD NET\CatPart")
            Pathes.Add("C:\AutoCAD NET\MM2Imperial")
            Pathes.Add("C:\AutoCAD NET\Supports")

            Dim pref As AcadPreferences = Autodesk.AutoCAD.ApplicationServices.Application.Preferences
            Dim sp As String = pref.Files.SupportPath
            'Dim TempString() As String = sp.Split(";")
            For Each TempString As String In Pathes
                If Not sp.Contains(TempString) Then
                    pref.Files.SupportPath = sp & ";" & TempString
                    sp = pref.Files.SupportPath
                End If
            Next
        End If

        ''Application Part 2 - Add Applications to Autoload
        If RunMode = 2 Or RunMode = 10 Then
            Dim AutoCADVersionReg As RegistryKey
            ''Dim IDEApplicaationReg As RegistryKey
            Dim AutoCADStartupReg As RegistryKey

            Dim KeyPath As New List(Of String)
            ''ACADM 2010
            ''KeyPath.Add("SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8005:409\Applications")
            KeyPath.Add("SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8005:409")
            '' ''AutoCAD P&ID 2010
            ''KeyPath.Add("SOFTWARE\Autodesk\AutoCAD\R18.0\ACAD-8016:409\Applications")
            '' ''AutoCAD P&ID 2011
            ''KeyPath.Add("SOFTWARE\Autodesk\AutoCAD\R18.1\ACAD-9016:409\Applications")
            '' ''AutoCAD P&ID 2012 - English
            ''KeyPath.Add("SOFTWARE\Autodesk\AutoCAD\R18.2\ACAD-A016:409\Applications")
            ''ACADM 2012
            ''KeyPath.Add("SOFTWARE\Autodesk\AutoCAD\R18.2\ACAD-A005:409\Applications")
            KeyPath.Add("SOFTWARE\Autodesk\AutoCAD\R18.2\ACAD-A005:409")
            ''ACAD 2012
            KeyPath.Add("SOFTWARE\Autodesk\AutoCAD\R18.2\ACAD-A001:409")

            Dim IDEApplications(7, 1) As String
            IDEApplications(0, 0) = "IDE CatPart"
            IDEApplications(0, 1) = "C:\AutoCAD NET\CatPart\CatPartNET.lsp"
            IDEApplications(1, 0) = "IDE Supports"
            IDEApplications(1, 1) = "C:\AutoCAD NET\Supports\Supports.lsp"
            IDEApplications(2, 0) = "IDE MM2Imperial"
            IDEApplications(2, 1) = "C:\AutoCAD NET\MM2Imperial\MM2Imperial.lsp"
            IDEApplications(3, 0) = "IDE BOMOUT Style 3"
            IDEApplications(3, 1) = "C:\AutoCAD VBA Codes\BOMOUT Style 3 - NO JYAI\ExportStyle3.dvb"
            IDEApplications(4, 0) = "BOMOUT Style 2 + CatPart - NO JYAI"
            IDEApplications(4, 1) = "C:\AutoCAD VBA Codes\BOMOUT Style 2 + CatPart - NO JYAI\BOMOUT Style 2 + CatPart.dvb"
            IDEApplications(5, 0) = "CatPart With Blocks 64"
            IDEApplications(5, 1) = "C:\AutoCAD VBA Codes\CatPart With Blocks 64\CatPartWithBlocks64.dvb"
            IDEApplications(6, 0) = "PostIsometrics"
            IDEApplications(6, 1) = "C:\AutoCAD VBA Codes\PostIsometrics\PostIsometrics.dvb"
            IDEApplications(7, 0) = "Bentley Advanced"
            IDEApplications(7, 1) = "C:\AutoCAD VBA Codes\Bentley Advanced\Bentley_Advanced.LSP"

            For Each CurrentKeyPath As String In KeyPath
                AutoCADVersionReg = Registry.CurrentUser.OpenSubKey(CurrentKeyPath & "\Profiles", True)
                If Not AutoCADVersionReg Is Nothing Then
                    Dim Profiles() As String
                    Dim Startup() As String
                    Profiles = AutoCADVersionReg.GetSubKeyNames()
                    For Each Profile As String In Profiles
                        AutoCADStartupReg = Registry.CurrentUser.OpenSubKey(CurrentKeyPath & "\Profiles\" & Profile & "\Dialogs\Appload\Startup", True)
                        If Not AutoCADStartupReg Is Nothing Then
                            Startup = AutoCADStartupReg.GetValueNames
                            For I As Integer = 0 To UBound(IDEApplications, 1)
                                Dim StartupBoolean As Boolean = False
                                For J As Integer = 0 To UBound(Startup)
                                    Dim StartupValue As String = AutoCADStartupReg.GetValue(Startup(J))
                                    If StartupValue = IDEApplications(I, 1) Then StartupBoolean = True
                                Next
                                If StartupBoolean = False Then
                                    Dim NumStartup As Integer = AutoCADStartupReg.GetValue("NumStartup")
                                    AutoCADStartupReg.SetValue(NumStartup + 1 & "Startup", IDEApplications(I, 1))
                                    AutoCADStartupReg.SetValue("NumStartup", (NumStartup + 1).ToString)
                                End If
                            Next
                        End If
                    Next

                    ''*************************************************************************
                    ''A Methos of AutoLoading Applications to All Users & All AutoCAD Profiles
                    ''But It Looks as if It Works Only With *.ddl and NOT With *.dvb
                    ''*************************************************************************

                    ''For I As Integer = 0 To UBound(IDEApplications, 1)
                    ''    ''CurrentApplication As String In IDEApplications

                    ''    IDEApplicaationReg = Registry.LocalMachine.OpenSubKey(CurrentKeyPath & "\" & IDEApplications(I, 0), True)
                    ''    If IDEApplicaationReg Is Nothing Then
                    ''        IDEApplicaationReg = Registry.LocalMachine.CreateSubKey(CurrentKeyPath & "\" & IDEApplications(I, 0))
                    ''        IDEApplicaationReg.SetValue("DESCRIPTION", IDEApplications(I, 0))
                    ''        IDEApplicaationReg.SetValue("LOADCTRLS", 2)
                    ''        IDEApplicaationReg.SetValue("MANAGED", 1)
                    ''        IDEApplicaationReg.SetValue("LOADER", IDEApplications(I, 1))
                    ''        IDEApplicaationReg.Close()
                    ''        AutoCADVersionReg.Close()
                    ''    End If
                    ''Next

                    ''For Debugging Mode
                    ''Exit Sub
                    ''For Debugging Mode

                End If
            Next

        End If

        ''Application Part 3 - Loading the CUI Files
        If RunMode = 3 Or RunMode = 10 Then
            Dim IDEApplicationsCUI(6, 1) As String
            IDEApplicationsCUI(0, 0) = "IDE_CATPART"
            IDEApplicationsCUI(0, 1) = "C:\AutoCAD NET\CatPart\CatPartNET.cuix"
            IDEApplicationsCUI(1, 0) = "IDE_SUPPORTS"
            IDEApplicationsCUI(1, 1) = "C:\AutoCAD NET\Supports\Supports.cuix"
            IDEApplicationsCUI(2, 0) = "IDE_MM2IMPERIAL"
            IDEApplicationsCUI(2, 1) = "C:\AutoCAD NET\MM2Imperial\MM2Imperial.cuix"
            IDEApplicationsCUI(3, 0) = "IDE_BOMOUT_3"
            IDEApplicationsCUI(3, 1) = "C:\AutoCAD VBA Codes\BOMOUT Style 3 - NO JYAI\ExportStyle3.cuix"
            IDEApplicationsCUI(4, 0) = "IDE_BOMOUT_2"
            IDEApplicationsCUI(4, 1) = "C:\AutoCAD VBA Codes\BOMOUT Style 2 + CatPart - NO JYAI\BOMOUT Style 2 + CatPart.cuix"
            IDEApplicationsCUI(5, 0) = "IDE_CATPART_64"
            IDEApplicationsCUI(5, 1) = "C:\AutoCAD VBA Codes\CatPart With Blocks 64\CatPart 64.cuix"
            IDEApplicationsCUI(6, 0) = "BENTLEY_ADVANCED"
            IDEApplicationsCUI(6, 1) = "C:\AutoCAD VBA Codes\Bentley Advanced\Bentley_Advanced.cuix"

            'Const cuiname As String = "mycuiname"
            'Const cuifile As String = "c:\mycuifile.cui"

            Dim OMenuGroup As AcadMenuGroup
            For I As Integer = 0 To UBound(IDEApplicationsCUI, 1)
                Try
                    'Attempt to access our menugroup
                    OMenuGroup = Application.MenuGroups.Item(IDEApplicationsCUI(I, 0))
                Catch ex As System.Exception
                    'Failure simply means we need to load the CUI first
                    Application.MenuGroups.Load(IDEApplicationsCUI(I, 1))
                    OMenuGroup = Application.MenuGroups.Item(IDEApplicationsCUI(I, 0))
                End Try

                'Cycle through the toobars, setting them to visible
                For J As Integer = 0 To OMenuGroup.Toolbars.Count - 1
                    OMenuGroup.Toolbars.Item(J).Visible = True
                Next

                ''For Debugging Mode
                ''If I = 1 Then Exit Sub
                ''For Debugging Mode

            Next

            ''Beep()

        End If

    End Sub
End Class

BlackBox

  • King Gator
  • Posts: 3770
Re: Autodesk.AutoCAD.Interop
« Reply #14 on: November 06, 2013, 03:30:02 PM »
...

We are about to upgrade all of our site's AutoCAD and we need to install for every installation our "in-house" applications.

...

To install an application we need to:
1.   Add the path to the AutoCAD's search pathes.
2.   Add the Application to the AutoCAD Automatic load suitcase.
3.   Add the Cui as a partial CUI
4.   Show to toolbars.

The attached application does all of the above for me with one simple click.
(I have to do one last modification to the application which will be to load all the lists from an XML or simple txt file)

... Or... You could just use an Autoloader .bundle to deploy your app(s), which will do all of the above mentioned steps for you. Lemon squeezy.
"How we think determines what we do, and what we do determines what we get."