TheSwamp
Code Red => .NET => Topic started by: Kurtz David 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.
-
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
-
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.
-
Not used to work with COM Interoperability with .NET, but i think it is version-dependent.
-
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
-
Thanks BlackBox for clearing that up, I wasn't sure about the details myself
-
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 (http://adndevblog.typepad.com/autocad/2012/05/modifying-autocad-support-path-through-net.html) a DevBlog article you may, or may not find useful.
Cheers
-
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.
object acadObject = Application.AcadApplication;
object preferences =
acadObject.GetType().InvokeMember("Preferences",
BindingFlags.GetProperty,
null, acadObject, null);
You can use this instead
dynamic acadObject = Application.AcadApplication;
var preferences = acadObject.Preferences;
-
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.
object acadObject = Application.AcadApplication;
object preferences =
acadObject.GetType().InvokeMember("Preferences",
BindingFlags.GetProperty,
null, acadObject, null);
You can use this instead
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
-
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.
-
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
-
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
-
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.
-
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.
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
-
...
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 (http://tinyurl.com/lyb5gtt) .bundle to deploy your app(s), which will do all of the above mentioned steps for you. Lemon squeezy.
-
... Or... You could just use an Autoloader (http://tinyurl.com/lyb5gtt) .bundle to deploy your app(s), which will do all of the above mentioned steps for you. Lemon squeezy.
An autoloader bundle will not work in AutoCAD 2010 will it?
-
Greetings, Owen! Long time, no chat - I hope all is well with you, Sir. :-)
... Or... You could just use an Autoloader (http://tinyurl.com/lyb5gtt) .bundle to deploy your app(s), which will do all of the above mentioned steps for you. Lemon squeezy.
An autoloader bundle will not work in AutoCAD 2010 will it?
While Autoloader was first implemented in 2012, generally speaking, the contents of a given .bundle are able to be ARX/CUI/NET-loaded into 2010 respectively (presuming compatible compiled framework executable files, etc.)... As I understand it, the OP is currently using both 2010, and 2012, and according to the OP:
We are about to upgrade all of our site's AutoCAD and we need to install for every installation our "in-house" applications.
... Which is what prompted my suggestion of Autoloader.
They're already producing 2010 and 2012 compatible executable files, and have everything they'd need (save PackageContents.xml essentially). Since it (Autoloader) currently supports one of their two production versions, and the contents of a would-be .bundle could be loaded through typical Profile means (i.e., Registry loader, CUIx loaded as partial to main, etc.) as per usual, methinks it may save 'deployment' efforts by only having to setup their 2010 installs. Then, once they've upgraded, they'll already have a working "In-House" application .bundle after install of new version.
Cheers