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