Disable button when not AMxAssemblyEnvironment?

Disable button when not AMxAssemblyEnvironment?

CadUser46
Collaborator Collaborator
770 Views
4 Replies
Message 1 of 5

Disable button when not AMxAssemblyEnvironment?

CadUser46
Collaborator
Collaborator

How to disable the button when in the sketch environment (or any other)?

 

I was looking through the rack face sample and thought I had it but alas, no. In the attachment you can see my button is still enabled when an assembly sketch is active. I intend to replace the Create Component button.  FYI i'm a novice when it comes to .NET and addins so spell it out for me.

 

Alternatively is there a better sample I can look at?

 

I have already added the handler to the activate event.  My button definition is a public variable in another module, could this be the problem?

 

        Public Sub m_UIEvents_OnEnvironmentChange(ByVal environment As Environment, ByVal environmentState As EnvironmentStateEnum, ByVal beforeOrAfter As EventTimingEnum, ByVal context As NameValueMap, ByRef handlingCode As HandlingCodeEnum)

            Try
                Dim envInternalName As String = environment.InternalName

                If Not envInternalName = "AMxAssemblyEnvironment" Then

                    'Enable the "Rack Face" button when the part environment is activated or resumed
                    If environmentState = EnvironmentStateEnum.kActivateEnvironmentState Or environmentState = EnvironmentStateEnum.kResumeEnvironmentState Then
                        BtnDefCreateInPlace.Enabled = True
                        'm_rackFaceCmd.ButtonDefinition.Enabled = True
                    End If

                    'Disable the "Rack Face" button when the part environment is terminated or suspended
                    If environmentState = EnvironmentStateEnum.kTerminateEnvironmentState Or environmentState = EnvironmentStateEnum.kSuspendEnvironmentState Then
                        BtnDefCreateInPlace.Enabled = False
                        'm_rackFaceCmd.ButtonDefinition.Enabled = False
                    End If
                End If

                handlingCode = HandlingCodeEnum.kEventNotHandled

            Catch
            End Try

        End Sub

 

 

 

 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Accepted solutions (1)
771 Views
4 Replies
Replies (4)
Message 2 of 5

sajith_subramanian
Autodesk Support
Autodesk Support

 

Hello,

 

Would you be able to share the code (if non confidential) where you are creating the button definition BtnDefCreateInPlace? Since ideally, if you call the BtnDefCreateInPlace.Enabled = True / False you should be able to enable and disable the button in that environment.

 

Regards,


Sajith Subramanian
Autodesk Developer Network
0 Likes
Message 3 of 5

CadUser46
Collaborator
Collaborator

Sure.  I have this in a separate module.

 

Imports Inventor

Namespace CreateInPlace

    Module mUserInterface

        Private Const strAddInGuid As String = "fdbd0202-f505-4a4b-9a64-f9e14c93d7ab"
        Public BtnDefCreateInPlace As ButtonDefinition

        Public Sub LoadButtons()

            'Only the definitions need to be listed here.  The buttons are loaded in the CreateUserInterface sub so that the addin can handle a ribbon reset.
            Dim mCtrlDefs As ControlDefinitions = Addin.InventorApp.CommandManager.ControlDefinitions

            'Initialise icons for button definitions.
            Dim ipdCreate16Icon As IPictureDisp = mPictureDispConverter.ToIPictureDisp(My.Resources.Create16)
            Dim ipdCreate32Icon As IPictureDisp = mPictureDispConverter.ToIPictureDisp(My.Resources.Create32)

            'Create all the button definitions.  A button is like an emtpy control that has to be filled with a definition.
            BtnDefCreateInPlace = mCtrlDefs.AddButtonDefinition("Create", "idBtnCreate", CommandTypesEnum.kQueryOnlyCmdType, strAddInGuid, _
                                                                "Description", "Create Component", ipdCreate16Icon, ipdCreate32Icon, ButtonDisplayEnum.kDisplayTextInLearningMode)

            'Add event handlers.  This tells the button what to do when it's pressed.
            AddHandler BtnDefCreateInPlace.OnExecute, AddressOf mUserInterface.BtnDefCreateInPlace_OnExecute

        End Sub

        Public Sub CreateUserInterface()

            'Get a reference to the UserInterfaceManager object. 
            Dim UIManager As Inventor.UserInterfaceManager = Addin.InventorApp.UserInterfaceManager

            'Get the assembly ribbon.
            Dim assyRibbon As Inventor.Ribbon = UIManager.Ribbons.Item("Assembly")

            'Get the assembly tab.
            Dim assyTab As Inventor.RibbonTab = assyRibbon.RibbonTabs.Item("id_TabAssemble")

            'Get the component panel and hide the default Create command.
            Dim compPanel As Inventor.RibbonPanel = assyTab.RibbonPanels.Item("id_PanelA_AssembleComponent")
            compPanel.CommandControls.Item("AssemblyCreateComponentCmd").Visible = True
            compPanel.CommandControls.AddButton(BtnDefCreateInPlace, True)

        End Sub

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 4 of 5

sajith_subramanian
Autodesk Support
Autodesk Support

Hi,

 

The condition in the loop is set as

 

 If Not envInternalName = "AMxAssemblyEnvironment" Then

 

This will actually enable the create button when not in AMxAssemblyEnvironment , that is in the sketch environment.

 

To disable the button in any environment other than AMxAssemblyEnvironment   you can change the if condition to

 

If envInternalName = "AMxAssemblyEnvironment" Then  'remove Not

 

Another way to achieve this would be to disable the BtnDefCreateInPlace when in sketch mode.

 

If Environment.InternalName = "AMxAssemblySketchEnvironment" Then ' check if sketch environment

 

' set the button as disabled....

 

 

 

 

Please let me know if this solves the problem.

 

Regards,

Sajith

 


Sajith Subramanian
Autodesk Developer Network
0 Likes
Message 5 of 5

CadUser46
Collaborator
Collaborator
Accepted solution

@sajith_subramanian

 

I eventually found my mistake.  In the activate sub where I was adding the handler I had a . instead of an _

 

ie me.m_UIEvents.OnEnvironmentChange instead of me.m_UIEvents_OnEnvironmentChange 

 

I realised during debugging it wasn't calling the sub at all.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes