Launch command under condition

Launch command under condition

TONELLAL
Collaborator Collaborator
542 Views
4 Replies
Message 1 of 5

Launch command under condition

TONELLAL
Collaborator
Collaborator

Hi,

I need to launch an Inventor command under condition. The algorithm should be :

If CustomProperty = "" then 

     ask for CustomProperty value

     launch InvCommand

Else

     launch invCommand

End if

 

What is the best method :

-create my own command, and replace the existing icon in the ribbon

-or is it possible to modify the controldefinition of the existing icon ?

0 Likes
543 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

The first question and second question don't seem to go together.  The example you gave in your first question seems like it would be the fastest and simplest route.  I assume there you're talking about executing a control definition by using either iLogic or VBA code.  If so, I assume you would want whatever ribbon icon you click on to immediately check that custom iproperty before executing whatever main command is behind it, correct?  I would definately make your own macro for that.

As for your second question, I would definitely advise you to leave default tools alone and just hide them if you don't want to use them as they are.  Then replace its position in the ribbon with your macro button.

 

Here is some VBA code to get a copy of the icons it is using.  You can just use these as you would any other macro images, or you can modify them a bit first (recommended).

(Replace "UpdateStylesCmd" with the name of the command you want to get the icon graphics for.)

Sub Get_CMD_Icon()
    'Dim oCDs As ControlDefinitions
    'Set oCDs = ThisApplication.CommandManager.ControlDefinitions
    'Dim oCD As ControlDefinition
    'For Each oCD In oCDs
    '    ListBox1.AddItem oCD.DisplayName
    'Next oCD
    Dim oDef As ButtonDefinition
    Set oDef = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateStylesCmd")
    Dim oLargeIcon As IPictureDisp
    Set oLargeIcon = oDef.LargeIcon
    Dim oStandardIcon As IPictureDisp
    Set oStandardIcon = oDef.StandardIcon
    StdFunctions.SavePicture oLargeIcon, "C:\Temp\UpdateStylesCmd_LargeIcon.bmp"
    StdFunctions.SavePicture oStandardIcon, "C:\Temp\UpdateStylesCmd_StandardIcon.bmp"
End Sub

 If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

TONELLAL
Collaborator
Collaborator

I just want to replace one original inventor command by mine. I have the VBA code, it functions, now I wondered if the best way to place it on the ribbon was to add my own button, then hide the original one, or if it was possible to only modify the command associated with the original button.

I think the first solution is better, as you said, so I let default command alone.

 

The other idea to just modify default button was I already tried to use default icon, near like you propose. The only difference is I don't save the icon as BMP but directly use the iPictureDisp object:

    Dim oDef As ButtonDefinition
    Set oDef = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateStylesCmd")
    Dim oLargeIcon As IPictureDisp
    Set oLargeIcon = oDef.LargeIcon
    Dim oStandardIcon As IPictureDisp
    Set oStandardIcon = oDef.StandardIcon

    dim oNewDef as ButtonDefinition

    Set NewDef = ThisApplication.CommandManager.ControlDefinitions.AddButtonDefinition(btDisplayName, btInternalName, btClassification, btClientId, btDescriptionText, btToolTipTxt, oStandardIcon, oLargeIcon, btButtonDisplay)

 

This functions, but icons seems not to be the same as default button (cf joined file). Colors, definition, and even the shape are different ! If I use your method, saving as BMP, I have the same result... Any idea about this difference ? And, how can I obtain the right icon (even if I modify ot after 😉 ) ?

 

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Yes.  The process of directly Getting the IPictureDisp object from one definition to Setting it to your own, would seem to be the most efficient and direct way to do it, if you're not planning on making any changes to it.

 

Yes. I've seen those same kinds of differences in icon appearances before too.  Looks like a Theme modification, but I'm honestly not sure how to control it.  I'm not %100 sure about the extent of how Autodesk deals with all the different Theme options.  They may just have a different variation of each icon to go with each theme, or they may just show different colors differently within the UI while using different themes.

So, it might be a pain, but I would suggest a test.  You could try changing to a different theme, then capture those icons again, then see if they (the image files themselves) look any different in an image viewer app.  If they look different in an image viewer app, this would confirm that Autodesk has multiple icon image variations stored somewhere within the install directories, and may be an easier situation to deal with.  However, if they don't appear any different in the image viewer, yet they do appear different within the UI, this would indicate the theme is changing how the icon appears independently of the image file, and would make this process more difficult to control.

 

I got the name of the command for 'Insert Frame Members' ("AFG_CMD_InsertProfile"), because that's what your posted icons looked like, and placed that into my code to save the icons out (and cleaned up the unused stuff from before).  Attached are the icons I received.  I'm using Inventor 2021.1 and have the 'Light' UI Theme with the 'Dark' in-canvas color scheme.

Sub Get_CMD_Icon()
    Dim oDef As ButtonDefinition
    Set oDef = ThisApplication.CommandManager.ControlDefinitions.Item("AFG_CMD_InsertProfile")
    Dim oLargeIcon As IPictureDisp
    Set oLargeIcon = oDef.LargeIcon
    Dim oStandardIcon As IPictureDisp
    Set oStandardIcon = oDef.StandardIcon
    StdFunctions.SavePicture oLargeIcon, "C:\Temp\AFG_CMD_InsertProfile_LargeIcon.bmp"
    StdFunctions.SavePicture oStandardIcon, "C:\Temp\AFG_CMD_InsertProfile_StandardIcon.bmp"
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

TONELLAL
Collaborator
Collaborator

I saved the same icon for AF_CMD_InsertProfile in versions 2018, 2020, 2021, in dark ou light theme, and also a sceenshot of the displayed icons to compare. In 2028 and 2020, it was not really a theme like in 2021.

As you can see, all icons are different depending of the theme. So, I think the icon stored in the controldefinition doesn't matter, icons are managed somewhere else... Perhaps in a dll file ? If Autodesk can give more details...

0 Likes