Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

change picture of buttondefinition

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
472 Views, 11 Replies

change picture of buttondefinition

Anonymous
Not applicable
I want to change the picture of a buttondefinition.
How can I do that?

Geert

Code:
'Make Button
Dim objControlDefs As ControlDefinitions
Set objControlDefs = objInventorApp.CommandManager.ControlDefinitions
Dim objUpdateModelCmdPicture As IPictureDisp
Set objUpdateModelCmdPicture = LoadResPicture(126, vbResIcon)
Set mobjUpdateModelCmd = objControlDefs.AddButtonDefinition("Update Model", "UpdateModelCmd", kQueryOnlyCmdType, strClientID, , , objUpdateModelCmdPicture, objUpdateModelCmdPicture)

'Change picture of button
Dim objUpdateModelCmdPicture As IPictureDisp
Set objUpdateModelCmdPicture = LoadResPicture(127, vbResIcon)
Dim objCommandBars As CommandBars
Set objCommandBars = objUserInterfaceMgr.CommandBars
'select commandbar where button resides
Dim objDataLINKCmdBar As CommandBar
Set objDataLINKCmdBar = objCommandBars.Add("DataLINK", "DataLINKCmdBar", kRegularCommandBar, strClientID)
'?????? How to change the picture of commandbutton
objDataLINKCmdBar.Controls.Item ("UpdateModelCmd")
0 Likes

change picture of buttondefinition

I want to change the picture of a buttondefinition.
How can I do that?

Geert

Code:
'Make Button
Dim objControlDefs As ControlDefinitions
Set objControlDefs = objInventorApp.CommandManager.ControlDefinitions
Dim objUpdateModelCmdPicture As IPictureDisp
Set objUpdateModelCmdPicture = LoadResPicture(126, vbResIcon)
Set mobjUpdateModelCmd = objControlDefs.AddButtonDefinition("Update Model", "UpdateModelCmd", kQueryOnlyCmdType, strClientID, , , objUpdateModelCmdPicture, objUpdateModelCmdPicture)

'Change picture of button
Dim objUpdateModelCmdPicture As IPictureDisp
Set objUpdateModelCmdPicture = LoadResPicture(127, vbResIcon)
Dim objCommandBars As CommandBars
Set objCommandBars = objUserInterfaceMgr.CommandBars
'select commandbar where button resides
Dim objDataLINKCmdBar As CommandBar
Set objDataLINKCmdBar = objCommandBars.Add("DataLINK", "DataLINKCmdBar", kRegularCommandBar, strClientID)
'?????? How to change the picture of commandbutton
objDataLINKCmdBar.Controls.Item ("UpdateModelCmd")
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
It is not possible to change the image of a button once it has been created.
Sorry.

Sanjay-
0 Likes

It is not possible to change the image of a button once it has been created.
Sorry.

Sanjay-
Message 3 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
OK, then I must do this by enable.
Not so nice but it works.

Thanks,

Geert
0 Likes

OK, then I must do this by enable.
Not so nice but it works.

Thanks,

Geert
Message 4 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
"I must do this by enable."
Can you explain that part?
We need to put one icon in green color when is running and it must change to red when is not connected.
0 Likes

"I must do this by enable."
Can you explain that part?
We need to put one icon in green color when is running and it must change to red when is not connected.
Message 5 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
It would be easiest if you created 2 ButtonDefinitions (1 green and 1 red)
and placed the appropriate button as needed.

Sanjay-
0 Likes

It would be easiest if you created 2 ButtonDefinitions (1 green and 1 red)
and placed the appropriate button as needed.

Sanjay-
Message 6 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Thanks Sanjay, Ok, I try to do it as you say
0 Likes

Thanks Sanjay, Ok, I try to do it as you say
Message 7 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
There are 2 options.
1) define 2 buttons such as Sanjay said
2) define one button and enable it or not.

In our case the green button says model is OK, the red button says model needs care and clicking on it run a program. The green button is (for us) then useless because it don't have to do anything, so now we have one button (red) which is enabled when the model needs care and is not enabled when the model is OK.
This is the same behavior as Inventor does. (see Update button)

Geert.

Used Code:
Private Sub mobjApplicationEvents_OnNewView(ByVal ViewObject As Inventor.View, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, HandlingCode As Inventor.HandlingCodeEnum)

Dim objControlDefs As Inventor.ControlDefinitions
Set objControlDefs = objInventorApp.CommandManager.ControlDefinitions
objControlDefs.Item("UpdateModelCmd").Enabled = True

End sub
0 Likes

There are 2 options.
1) define 2 buttons such as Sanjay said
2) define one button and enable it or not.

In our case the green button says model is OK, the red button says model needs care and clicking on it run a program. The green button is (for us) then useless because it don't have to do anything, so now we have one button (red) which is enabled when the model needs care and is not enabled when the model is OK.
This is the same behavior as Inventor does. (see Update button)

Geert.

Used Code:
Private Sub mobjApplicationEvents_OnNewView(ByVal ViewObject As Inventor.View, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, HandlingCode As Inventor.HandlingCodeEnum)

Dim objControlDefs As Inventor.ControlDefinitions
Set objControlDefs = objInventorApp.CommandManager.ControlDefinitions
objControlDefs.Item("UpdateModelCmd").Enabled = True

End sub
Message 8 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Ok many thanks to both
Pretty explications Geert.
Our case is similar as you described, but is different in one point, when the macro is running de button must be in (green) disabled mode and (red) enable in case the macro is not running or fails.
Sorry my english is not good and I'm not a VBA experienced programmer.
It´s possible that one macro knows if another macro is running?
0 Likes

Ok many thanks to both
Pretty explications Geert.
Our case is similar as you described, but is different in one point, when the macro is running de button must be in (green) disabled mode and (red) enable in case the macro is not running or fails.
Sorry my english is not good and I'm not a VBA experienced programmer.
It´s possible that one macro knows if another macro is running?
Message 9 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
I don't know exactly what you mean.
When starts your macro up? Automatically in a event such as mine? If so you can make your macro as a function which gives a boolean back as result. Something like this:

Private Function CheckMacroRuns (....) as boolean
if Macroruns then
CheckMacroRuns = True
else
CheckMacroRuns = False
end Function

'Controlling buttons
if CheckMacroRuns = true then
objControlDefs.Item("GreenCmd").Enabled = True
objControlDefs.Item("RedCmd").Enabled = False
Else
objControlDefs.Item("GreenCmd").Enabled = False
objControlDefs.Item("RedCmd").Enabled = True
end if
0 Likes

I don't know exactly what you mean.
When starts your macro up? Automatically in a event such as mine? If so you can make your macro as a function which gives a boolean back as result. Something like this:

Private Function CheckMacroRuns (....) as boolean
if Macroruns then
CheckMacroRuns = True
else
CheckMacroRuns = False
end Function

'Controlling buttons
if CheckMacroRuns = true then
objControlDefs.Item("GreenCmd").Enabled = True
objControlDefs.Item("RedCmd").Enabled = False
Else
objControlDefs.Item("GreenCmd").Enabled = False
objControlDefs.Item("RedCmd").Enabled = True
end if
Message 10 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Thanks again it's very clear what you said.
And yes, my macro starts automatically.
Then it cloud be something like this:

'In Module

Option Explicit
Public oEvent As clsEvent

Private Function AutoStart() as boolean
Set oEvent = New clsEvent
oEvent.Initialize
if AutoStart then
AutoStart=true
else
AutoStart=false
end if
End Function

'and in class modules

Option Explicit
Private WithEvents oModelingEvents As ModelingEvents
Private WithEvents oApplicationEvents As ApplicationEvents
Private WithEvents UserInputEvents As UserInputEvents

Private Sub Initialize()
Set oModelingEvents = ThisApplication.ModelingEvents
Set oApplicationEvents = ThisApplication.ApplicationEvents
Set UserInputEvents = _
ThisApplication.CommandManager.UserInputEvents
End Sub
0 Likes

Thanks again it's very clear what you said.
And yes, my macro starts automatically.
Then it cloud be something like this:

'In Module

Option Explicit
Public oEvent As clsEvent

Private Function AutoStart() as boolean
Set oEvent = New clsEvent
oEvent.Initialize
if AutoStart then
AutoStart=true
else
AutoStart=false
end if
End Function

'and in class modules

Option Explicit
Private WithEvents oModelingEvents As ModelingEvents
Private WithEvents oApplicationEvents As ApplicationEvents
Private WithEvents UserInputEvents As UserInputEvents

Private Sub Initialize()
Set oModelingEvents = ThisApplication.ModelingEvents
Set oApplicationEvents = ThisApplication.ApplicationEvents
Set UserInputEvents = _
ThisApplication.CommandManager.UserInputEvents
End Sub
Message 11 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Will this be possible in the future?
Ronny

Re: change picture of buttondefinition
It is not possible to change the image of a button once it has been created.
Sorry.

Sanjay-
0 Likes

Will this be possible in the future?
Ronny

Re: change picture of buttondefinition
It is not possible to change the image of a button once it has been created.
Sorry.

Sanjay-
Message 12 of 12
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
No plans for this yet.

Sanjay-
0 Likes

No plans for this yet.

Sanjay-

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report