Code Red => .NET => Topic started by: mindofcat on February 24, 2017, 07:30:10 PM
Title: Generate Flyouts, Toolbars, and Buttons in AutoCAD 2017 using Visual Studio 2015
Post by: mindofcat on February 24, 2017, 07:30:10 PM
Hi All,
I wrote some DOT NET routines a while back in AutoCAD 2010 using Visual Studio 2010, but now we are upgrading to AutoCAD 2017 / Visual Studio 2015.
I have successfully imported all of my code into the new environment, and everything works fine, except for the flyouts, toolbars, and toolbar buttons. These do not even show up at all in AutoCAD 2017 after the program is started up and my DLL is netloaded. All the commands, however, still become available in AutoCAD, but only via command line.
What I'm attempting to accomplish is to have the flyouts appear automatically on the top-left everytime AutoCAD is started up.
Below is the myCommands.vb file which runs upon program initialization, and which should show me my flyouts in AutoCAD 2017, but doesn't:
<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
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
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
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
This project references the latest AutoCAD API DLLs from ObjectARX 2017.
Any ideas on how I can get this code to display those 3 flyouts and their toolbars? Did AutoCAD change the way flyouts and toolbars are generated in AutoCAD 2017 VS2015? If so, any pointers as to how I can autoload my flyouts and toolbars in AutoCAD 2017 upon program startup?
Thanks.
Title: Re: Generate Flyouts, Toolbars, and Buttons in AutoCAD 2017 using Visual Studio 2015
Post by: kdub_nz on February 25, 2017, 12:38:22 AM
That's a tough question.
You'll probably get more people using VB at the other place you've posted this.
If it was C# I'd ask you for the complete solution file and everything that goes with it. ( ie, something compilable and with ALL resources )
I seem to recall that you've asked this sort of question before ... about toolbars located in a specific location ..
Title: Re: Generate Flyouts, Toolbars, and Buttons in AutoCAD 2017 using Visual Studio 2015
Post by: MexicanCustard on February 27, 2017, 07:40:19 AM
Toolbar flyouts are special elements that do not have a MacroID. Instead, they require a reference to a toolbar. This reference determines the items to be displayed in the flyout. You can create new toolbars for the referenced toolbar.
Namespace CatScript17 Public Class CatScriptCommands Implements IExtensionApplication Public Shared cs As CustomizationSection
Public Sub Initialize() Implements IExtensionApplication.Initialize Dim newTb As Toolbar = New Toolbar("New Toolbar", cs.MenuGroup) newTb.ElementID = "EID_NewToolbar" newTb.ToolbarOrient = ToolbarOrient.floating newTb.ToolbarVisible = ToolbarVisible.show
Dim newButton As ToolbarButton = New ToolbarButton(newTb, -1) newButton.MacroID = "ID_Pline" Dim newControl As ToolbarControl = New ToolbarControl(ControlType.NamedViewControl, newTb, -1) Dim newFlyout As ToolbarFlyout = New ToolbarFlyout(newTb, -1) newFlyout.ToolbarReference = "DIMENSION" End Sub End Class End Namespace
But when I build the solution and load it into AutoCAD 2017, still, no toolbar or flyout. Was there something I'm missing here?
Thanks.
Title: Re: Generate Flyouts, Toolbars, and Buttons in AutoCAD 2017 using Visual Studio 2015
Post by: dgorsman on February 27, 2017, 02:50:22 PM
Definitely no solution here. Just a mention-slash-vent that I detest code-generated UI content. If there are only minor variations, then that can be done with flyouts/dropdowns/etc. Not to mention observed issues with workspace management. If there is well defined need to be dynamically different every single session, OK, maybe. But if this is going to be the same every time, writing code to generate it every session just seems... excessive. Like, "never using XREFs or blocks" excessive. :thinking:
PS: note the code tags used by MexicanCustard.
Title: Re: Generate Flyouts, Toolbars, and Buttons in AutoCAD 2017 using Visual Studio 2015
Post by: mindofcat on March 13, 2017, 11:33:34 AM
This problem has been resolved. The toolbars do not change within each AutoCAD session, and therefore, a partial cui menu file was created instead. Now the toolbars and flyouts load successfully in AutoCAD 2017 via a one-time cuiload command.
Lesson learned: Do not attempt to accomplish it via complicated programming code when you can get it done simply manually.