我使用Visual Studio 2010在AutoCAD 2010中編寫了一些DOT NET例程,但現在我們正在升級到AutoCAD 2017/Visual Studio 2015.如何使用Visual Studio 2015在AutoCAD 2017中生成Flyouts,工具欄和按鈕
我已經成功地將所有代碼導入到新環境中,並且一切正常,除了彈出窗口,工具欄和工具欄按鈕。這些甚至在程序啓動並且我的DLL被網絡加載後在AutoCAD 2017中完全不顯示。然而,所有的命令在AutoCAD中仍然可用,但只能通過命令行。
我試圖完成的是每次啓動AutoCAD時,彈出窗口會自動顯示在左上角。
下面是在程序初始化運行myCommands.vb文件,這應該顯示我在AutoCAD 2017年展開工具欄,但不會:
Option Explicit On
Imports Microsoft.Win32
Imports System.Reflection
Imports System.Data.OleDb
Imports System.Runtime.CompilerServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports acApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Customization
Imports acOp = Autodesk.AutoCAD.Interop
Imports acOpCom = Autodesk.AutoCAD.Interop.Common
<Assembly: CommandClass(GetType(CatScript17.CatScriptCommands))>
Namespace CatScript17
' Manages all CatScript commands for this software. Also contains all the autocad flyout/toolbar commands.
Public Class CatScriptCommands
Implements IExtensionApplication
Public Shared strAppName As String = "CatScript17"
Public Shared cs As CustomizationSection
Public Shared restoreDefaultMacro As Boolean = False
Public Sub Initialize() Implements IExtensionApplication.Initialize
' Autoload the catscript17 flyouts and toolbars into AutoCAD 2017 upon each startup
CatScriptToolbar.addToolbar()
End Sub
Public Sub Terminate() Implements IExtensionApplication.Terminate
Throw New NotImplementedException()
End Sub
' Displaying the Air Conveyor Corner form
<CommandMethod("accorner", CommandFlags.UsePickSet)>
Public Shared Sub acCorner()
End Sub
' Displaying the Air Conveyor Side Elevation form
<CommandMethod("acelevation", CommandFlags.UsePickSet)>
Public Shared Sub acElevation()
End Sub
' Displaying the Air Conveyor Straight form
<CommandMethod("acstraight", CommandFlags.UsePickSet)>
Public Shared Sub acStraight()
End Sub
' Displaying the Case Straight Combo form
<CommandMethod("cccombo", CommandFlags.UsePickSet)>
Public Shared Sub ccCombo()
End Sub
' Displaying the Case Corner Conveyor form
<CommandMethod("cccorner", CommandFlags.UsePickSet)>
Public Shared Sub ccCorner()
End Sub
' Displaying the Case Conveyor Side Elevation form
<CommandMethod("ccelevation", CommandFlags.UsePickSet)>
Public Shared Sub ccElevation()
End Sub
' Displaying the Case Straight Conveyor form
<CommandMethod("ccstraight", CommandFlags.UsePickSet)>
Public Shared Sub ccStraight()
End Sub
' Displaying the Case Turner Conveyor form
<CommandMethod("ccturner", CommandFlags.UsePickSet)>
Public Shared Sub ccTurner()
End Sub
' Displaying the Case Zero Pressure Conveyor form
<CommandMethod("cczeropressure", CommandFlags.UsePickSet)>
Public Shared Sub ccZeroPressure()
End Sub
' Displaying the table top Bi-Di form
<CommandMethod("ttbidi", CommandFlags.UsePickSet)>
Public Shared Sub ttBiDi()
End Sub
' Displaying the table top Combiner form
<CommandMethod("ttcombiner", CommandFlags.UsePickSet)>
Public Shared Sub ttCombiner()
End Sub
' Displaying the table top Corner form
<CommandMethod("ttcorner", CommandFlags.UsePickSet)>
Public Shared Sub ttCorner()
End Sub
' Displaying the table top Decel form
<CommandMethod("ttdecel", CommandFlags.UsePickSet)>
Public Shared Sub ttDecel()
End Sub
' Displaying the table top Divert form
<CommandMethod("ttdivert", CommandFlags.UsePickSet)>
Public Shared Sub ttDivert()
End Sub
' Displaying the table top Dynamic form
<CommandMethod("ttdynamic", CommandFlags.UsePickSet)>
Public Shared Sub ttDynamic()
End Sub
' Displaying the Table Top Side Elevation form
<CommandMethod("ttelevation", CommandFlags.UsePickSet)>
Public Shared Sub ttElevation()
End Sub
' Displaying the Mass Merge Conveyor form
<CommandMethod("ttmerge", CommandFlags.UsePickSet)>
Public Shared Sub ttMerge()
End Sub
' Displaying the Mass Parallel Conveyor form
<CommandMethod("ttparallel", CommandFlags.UsePickSet)>
Public Shared Sub ttParallel()
End Sub
' Displaying the Mass Straight Conveyor form
<CommandMethod("ttstraight", CommandFlags.UsePickSet)>
Public Shared Sub ttStraight()
End Sub
End Class
Public Class CatScriptToolbar
'-----------
' Properties
'-----------
Private Shared groups As acOp.AcadMenuGroups
Private Shared group As acOp.AcadMenuGroup
Private Shared toolbars As acOp.IAcadToolbars
Private Shared toolbar As acOp.AcadToolbar
Private Shared flyout As acOp.AcadToolbarItem
'--------
' Methods
'--------
' Component for adding toolbars and flyouts
Public Shared Sub addToolbar()
Try
Dim app As acOp.AcadApplication = _
DirectCast(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, _
acOp.AcadApplication)
' Define the toolbars group
groups = app.MenuGroups
group = groups.Item(0)
toolbars = group.Toolbars
' Generate the flyout toolbar
toolbar = toolbars.Add("CatScript Tools")
' Generate the flyouts
flyoutForTableTop(0)
flyoutForCaseConveyor(1)
flyoutForAirConveyor(2)
' Dock the newly created toolbar on the left
toolbar.Dock(acOpCom.AcToolbarDockStatus.acToolbarDockLeft)
Catch ex As System.Exception
End Try
End Sub
' Component for generating the flyout for air conveyor, as well as buttons for each routine
Private Shared Sub flyoutForAirConveyor(ByVal toolbarIndex As Long)
' Create an air conveyor toolbar
Dim str As String = "Air"
Dim tool As acOp.AcadToolbar = toolbars.Add(str & " Conveyor")
Dim titles(), commands(), descs() As String
titles = {"Straight", "Corner", "Elevation"}
commands = {"straight", "corner", "elevation"}
descs = {"Generates the straight sections for air conveyor applications. " & _
"Allows for section dimensioning",
"Generates the curved sections and corners for air conveyor applications " & _
"(in angles of 30, 45, 60, and 90 degrees). User also has the option of generating " & _
"infinite curves (with legs or hangers) for the air conveyor corner",
"Generates the side and plan views of elevation changes for air conveyors. " & _
"This is accomplished using infeed and discharge NRE, incline/decline angle or " & _
"specified/picked distance, and infeed/discharge section lengths. This routine " & _
"allows for section dimensioning (if generating ONLY plan view)"}
Dim button As acOp.AcadToolbarItem
For i As Long = 0 To titles.Length - 1
' Add the button to temporary toolbar
button = tool.AddToolbarButton(i, str & " " & titles(i), _
descs(i), ChrW(27) & ChrW(27) & "_ac" & commands(i) & vbLf, False)
' Set the images for the button. cat.root is C:\catscript\
button.SetBitmaps(cat.root & "AC " & titles(i) & ".bmp", _
cat.root & "AC " & titles(i) & ".bmp")
Next
'Create the Group flyout
flyout = toolbar.AddToolbarButton(toolbarIndex, _
"Air Conveyor", "Groups the Air Conveyors", _
ChrW(27) & ChrW(27) & "_acstraight" & vbLf, True)
flyout.SetBitmaps(cat.root & "AC Straight.bmp", cat.root & "AC Straight.bmp")
' Attach the group toolbar to the flyout just created
flyout.AttachToolbarToFlyout(group.Name.ToString(), str & " Conveyor")
tool.Visible = False
End Sub
' Component for generating the flyout for case conveyor, as well as buttons for each routine
Private Shared Sub flyoutForCaseConveyor(ByVal toolbarIndex As Long)
' Create a case conveyor toolbar
Dim tool As acOp.AcadToolbar = toolbars.Add("Case Conveyor")
Dim titles(), commands(), descs() As String
titles = {"Straight", "Corner", "Turner", "Zero Pressure", "Elevation", "Combo"}
commands = {"straight", "corner", "turner", "zeropressure", "elevation", "combo"}
descs = {"Generates the straight sections for case conveyor applications. " & _
"Sections generated are Straight Idler, Pass Through, Drive, and Stand Alone, " & _
"using varying infeed and discharge styles. This routine allows " & _
"for section dimensioning",
"Generates the curved sections and corners in case conveyor applications",
"Generates the Straight Stand-Alone, and Multiple Chain sections of case " & _
"conveyor for product orientation change. This routine allows for section dimensioning",
"Generates straight sections of Zero-Pressure Accumulation in case " & _
"conveyor applications. This routine allows for section dimensioning",
"Generates the side and plan views of elevation changes for case conveyors. " & _
"This is accomplished using infeed and discharge TOC, incline/decline angle or " & _
"specified/picked distance, and infeed/discharge section lengths. This routine " & _
"allows for section dimensioning (if generating ONLY plan view)", _
"Combines two or three case straight sections into one case straight section"}
' Add the button to temporary toolbar
Dim button As acOp.AcadToolbarItem
For i As Long = 0 To titles.Length - 1
button = tool.AddToolbarButton(i, "Case " & titles(i), _
descs(i), ChrW(27) & ChrW(27) & "_cc" & commands(i) & vbLf, False)
' Set the images for the button
button.SetBitmaps(cat.root & "CC " & titles(i) & ".bmp", _
cat.root & "CC " & titles(i) & ".bmp")
Next
'Create the Group flyout
flyout = toolbar.AddToolbarButton(toolbarIndex, _
"Case Conveyor", "Groups the Case conveyors", _
ChrW(27) & ChrW(27) & "_ccstraight" & vbLf, True)
flyout.SetBitmaps(cat.root & "CC Straight.bmp", cat.root & "CC Straight.bmp")
' Attach the group toolbar to the flyout just created
flyout.AttachToolbarToFlyout(group.Name.ToString(), "Case Conveyor")
tool.Visible = False
End Sub
' Component for generating the flyout for table top, as well as buttons for each routine
Private Shared Sub flyoutForTableTop(ByVal toolbarIndex As Long)
' Create a table top toolbar
Dim tool As acOp.AcadToolbar = toolbars.Add("Table Top")
Dim titles(), commands(), descs() As String
titles = {"Straight", "Corner", "Dynamic Transfer", "Parallel Transfer", _
"Merge", "Divert", "Combiner", "Decel"}
commands = {"straight", "corner", "dynamic", "parallel", _
"merge", "divert", "combiner", "decel"}
descs = {"Generates the straight sections for table top applications. " & _
"Sections generated are Straight Idler, Pass Through, Drive, and " & _
"Stand Alone. User has the option of specifying rail configuration, " & _
"using varying infeed and discharge styles. This routine allows " & _
"for section dimensioning",
"Generates the curved sections and corners in table top applications.",
"Generates the dynamic transfer sections in table top applications. " & _
"User has the option of specifying rail configuration. " & _
"This routine allows for section dimensioning",
"Generates the parallel transfers in table top applications. User has the " & _
"option of specifying rail configuration. This routine allows for section dimensioning",
"Generates merge tables in table top applications. User has the option of " & _
"specifying rail configuration. This routine allows for section dimensioning",
"Generates divert tables in table top applications. User has the option of " & _
"specifying rail configuration. This routine allows for section dimensioning",
"Generates combiner tables in table top applications. " & _
"This routine allows for section dimensioning",
"Generates deceleration tables in table top applications. " & _
"This routine allows for section dimensioning"}
' Generate the buttons
Dim button As acOp.AcadToolbarItem
For i As Long = 0 To titles.Length - 1
' Add the button to temporary toolbar
button = tool.AddToolbarButton(i, "Table Top " & titles(i), _
descs(i), ChrW(27) & ChrW(27) & "_tt" & commands(i) & vbLf, False)
' Set the images for the button
button.SetBitmaps(cat.root & "TT " & titles(i) & ".bmp", _
cat.root & "TT " & titles(i) & ".bmp")
Next
'Create the Group flyout
flyout = toolbar.AddToolbarButton(toolbarIndex, _
"Table Top Conveyor", "Groups the Table Top conveyors", _
ChrW(27) & ChrW(27) & "_ttstraight" & vbLf, True)
flyout.SetBitmaps(cat.root & "TT Straight.bmp", cat.root & "TT Straight.bmp")
' Attach the group toolbar to the flyout just created
flyout.AttachToolbarToFlyout(group.Name.ToString(), "Table Top")
tool.Visible = False
End Sub
End Class
End Namespace
該項目從ObjectARX中引用了最新的AutoCAD API的DLL
關於如何獲取此代碼以顯示這3個彈出窗口及其工具欄的任何想法? AutoCAD是否改變了在AutoCAD 2017 VS2015中生成展開和工具欄的方式? 如果是這樣,關於如何在程序啓動時自動加載我的彈出窗口和AutoCAD 2017中的工具欄?
感謝。