Connecting a ribbon button control to a SUB in vb.net addin.

Connecting a ribbon button control to a SUB in vb.net addin.

awatt
Advocate Advocate
1,199 Views
6 Replies
Message 1 of 7

Connecting a ribbon button control to a SUB in vb.net addin.

awatt
Advocate
Advocate

It seems basic, but I can't find a single example of how to connect a custom ButtonDefinition object to my VB.net SUB.  The OnExecute event should fire when the Execute method is called, but how do I know when the button is clicked?

 

I think it has something to do with the "ControlDefinitionEvents" object, but documentation on this object has disappeared from my API help file.

 

(Inventor 2015, VS 2010)

 

0 Likes
Accepted solutions (1)
1,200 Views
6 Replies
Replies (6)
Message 2 of 7

rjay75
Collaborator
Collaborator

Add an event handler to the button defintion's OnExecute event. 

Something like:

Snippet

AddHandler m_buttonDefinition.OnExecute, AddressOf Me.ButtonDefinition_OnExecute

This will call the Function Me.ButtonDefinition_OnExecute in the sample. (Could be named anything) whenever the button m_ButtonDefinition is clicked.

0 Likes
Message 3 of 7

awatt
Advocate
Advocate

Thanks.

I think that much is working. The TRY I put around it doesn't seem to complain.

 

I believe my problem lies in my use of the HANDLES definition in the code I want to execute.

Do I need to say it handles mybutton.OnExecute or ButtonDefinition.OnExecute?

 

The only way I could get it to compile without an error was like this:

 

Private WithEvents _BurnButton As ButtonDefinition

 

Public Sub WriteBurnFile() Handles _BurnButton.OnExecute

<code here>

 

That really doesn't seem right.

0 Likes
Message 4 of 7

rjay75
Collaborator
Collaborator

Modify your Sub to be.

 

Private Sub WriteBurnFile(ByVal context As Inventor.NameValueMap) Handles _BurnButton.OnExecute

 

Yes, it should be on your button object.

0 Likes
Message 5 of 7

awatt
Advocate
Advocate

Thanks again.  We're getting closer.

I'm still not seeing how my routine is seeing my ButtonDefinition object.  The declaration before the Sub only gives it an undefined generic buttondefinition object.  Or is the SUB declaration assigning a value to the declared variable?

 

0 Likes
Message 6 of 7

rjay75
Collaborator
Collaborator
Accepted solution

There are three main pieces of code that will get and handle a button.

 

First:

Private WithEvents _BurnButton As ButtonDefinition

This line defines a new Button variable named _BurnButton

 

Next:

Somewhere usually in the Activate Method of the addin class there should be a call to

_BurnButton = Application.CommandManager.ControlDefinitions.AddButtonDefinition(...)

This is the method that creates the button and assignes it to you variable.

 

Third:

Private Sub WriteBurnFile(ByVal context As Inventor.NameValueMap) Handles _BurnButton.OnExecute

This declares the Method to handle the _BurnButton.OnExecute event.

 

0 Likes
Message 7 of 7

awatt
Advocate
Advocate

Thanks large for the help.  I had a circus of errors working against me.

 

0 Likes