Button iLogic external

Button iLogic external

JMGunnar
Collaborator Collaborator
2,337 Views
7 Replies
Message 1 of 8

Button iLogic external

JMGunnar
Collaborator
Collaborator

I want too add button too external rule without add-ins 

 

I can not found ControlDefinition 

for iLogic External rule   like  MacroControlDefinition 

 

Best Regards Johan

 

 

 

 

Dim oMacroDef As MacroControlDefinition 
	For Each oItem In oButtonsList
	
		
	oMacroDef = oControlDefs.AddMacroControlDefinition(oItem)	
		oPanel.CommandControls.AddMacro(oMacroDef, False)	
	Next

 

 

oCommandType = InputRadioBox("Select One", _
"Built in commands", "Macro commands", False, "ilogic")

' Get the ribbon associated with the document
Dim oRibbon As Inventor.Ribbon

Dim oDoc As Document
oDoc = ThisApplication.ActiveEditDocument
If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
    oRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Assembly")
    oType = "Assembly"
ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
    oRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Part")
    oType = "Part"
ElseIf oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
    oRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Drawing")
    oType = "Drawing"
Else
    oType = "Unknown"
	Exit Sub
End If

oName = "TEST_"

'delete existing tab, in case it exist from previous test
Try
oRibbon.RibbonTabs.Item(oName & oType).Delete
Catch
End Try

Dim oTab As Inventor.RibbonTab
oTab = oRibbon.RibbonTabs.Add(oName & oType, oName & oType, "ClientId123")
oTab.Active = True

Dim oPanel As RibbonPanel
sPanelName = oName & " Tools"

oPanel = oTab.RibbonPanels.Add(sPanelName, sPanelName & "_" & oType, sPanelName & "_" & oType)

Dim oControlDefs As ControlDefinitions
oControlDefs = ThisApplication.CommandManager.ControlDefinitions

Dim oButtonsList As New ArrayList
If oCommandType = False
	
	If oType = "Drawing" Then	
		oButtonsList.Add("Test.Test_01")
		oButtonsList.Add("Test.Test_02")		
	Else If oType = "Assembly" Then
		oButtonsList.Add("Test.Test_03")
		oButtonsList.Add("Test.Test_04")	
	Else If oType = "Part" Then
		oButtonsList.Add("Test.Test_05")
		oButtonsList.Add("Test.Test_06")
	End If
	
	Dim oMacroDef As MacroControlDefinition 
	For Each oItem In oButtonsList
	
		
	oMacroDef = oControlDefs.AddMacroControlDefinition(oItem)	
		oPanel.CommandControls.AddMacro(oMacroDef, False)	
	Next

Else
	
	If oType = "Drawing" Then	
		oButtonsList.Add("DrawingBalloonCmd")
		oButtonsList.Add("DrawingBalloonAllCmd")		
	Else If oType = "Assembly" Then
		oButtonsList.Add("AppZoomSelectCmd")
		oButtonsList.Add("AppZoomAllCmd")		
	Else If oType = "Part" Then
		oButtonsList.Add("PartExtrudeCmd")	
		oButtonsList.Add("PartRevolveCmd")		
	End If

	Dim oButtonDef As ButtonDefinition
	For Each oItem In oButtonsList
		oButtonDef = oControlDefs.Item(oItem)		
		oPanel.CommandControls.AddButton(oButtonDef, False)	
	Next

End If

 

 

0 Likes
Accepted solutions (1)
2,338 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor
What version of Inventor are you using?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 8

JMGunnar
Collaborator
Collaborator

Inventor 2024

 

@bradeneuropeArthur  

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

There is no 'special' type of ControlDefinition that is just for iLogic rules...at least not yet, or not exposed to us.  They will just be a regular ControlDefinition, and will primarily be uses as a ButtonDefinition.  But they are bundled into a CommandCategory.  That same CommandCategory also has all other 'add-in' related ControlDefinitions and toolbars bundled into it though, which kind of sucks, in my opinion.  It would make things slightly easier to be able to just get them all in one pre-defined group.  However, if you loop through all ControlDefinitions, you will find that all of them for iLogic rules will have their name starting with "iLogic.Rule:".  After that portion of its name, will be any sub folder that the rule file is in, if at a lower level than the main external rules folder, then the name of the external rule file, with its file extension.

 

When we add them by code iLogic rule, I believe that they will only stay there during that session of Inventor, then will be gone again after restarting Inventor.  That is why folks use add-ins for customizing the user interface, because add-ins are designed to start when Inventor starts, then put all user interface stuff in place automatically each time.  If we add the iLogic rule buttons manually, using the customization dialog, then they will stay there permanently.  Attached is an iLogic rule I created a while back to 'inspect' an existing iLogic rule button that has been placed into the ribbon manually, initially just to see how everything was set by Autodesk behind the scenes.  As you can see, even that code is fairly long and complex.  One of the other codes I used to use before, for adding rules to the ribbon as buttons, was even longer and more complex.  But I wrote those rules before updating from Inventor 2022 directly to Inventor 2024, back when the manual process was not yet built-in, so the rule for adding a button it is no longer used for 2024 version.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

Frederick_Law
Mentor
Mentor

You can add iLogic rules to ribbon:

ILogic-Button-01.jpg

 

You can make custom icon for each rule also.  I did one for "Flat Out".

 

Another way is add rules to "Global Forms":

ILogic-Button-02.jpg

 

The settings are inside "Design Data": C:\Vault Workspace\Design Data\iLogic\UI\iLogicBrowserUiFormSpecification.xml

I put them in Vault and shared to other users.

Message 6 of 8

Frederick_Law
Mentor
Mentor

@WCrihfield wrote:

There is no 'special' type of ControlDefinition that is just for iLogic rules...


No, but the command does start with iLogic.

ILogic-Button-03.jpg

 

VBA Macro to list all Commands:


 

 

Sub PrintCommandNames()

    Dim oControlDefs As ControlDefinitions
    Set oControlDefs = ThisApplication.CommandManager.ControlDefinitions

    Dim oControlDef As ControlDefinition
    
'replace ????? with user folder name    
Open "C:\Users\?????\Documents\CommandNames.txt" For Output As #1

    Print #1, Tab(10); "Command Name"; Tab(75); "Description"; vbNewLine
    
    For Each oControlDef In oControlDefs

        Print #1, oControlDef.InternalName; Tab(55); oControlDef.DescriptionText
        
    Next
    Close #1
End Sub​

 

 

 

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor
Accepted solution

Just posting a correction to something I said in Message 4.  I said "I believe that they will only stay there during that session of Inventor, then will be gone again after restarting Inventor."  Well, that was true according to my testing back while using Inventor 2022 and how the old version rules I was using at the time worked for that task.  However, apparently that is not the case when using some updated code with updated settings for use in 2024.  I copied one of my old rules, modified it a bit, ran it to add a rule to the ribbon, and it seemed to work better now.  Plus, the rule button is still there after closing Inventor, then restarting it.  But I did observe something odd.  Only the small button icon was visible where I placed it, even though when I added it by code, I specified True for the 'ShowText' parameter of the AddButton method.  And when I open the Customize dialog to review the buttons in that panel, the checkbox is checked in the Text column for that rule button.  To fix this oddity, I had to uncheck the box, then checked it again.  But at least the button stayed there, and still worked as designed, when clicked.  In this recent testing, I did not attempt to create any new RibbonTab or RibbonPanel, just added the button to an existing panel.  In my old tests, the new RibbonTabs and new RibbonPanels that were created by my rule were gone after restarting Inventor.  I have not tested that part again in 2024 yet though.  It would be nice if they simply included the ability to add tabs and panels to the Customize dialog.  I even created an 'Idea' post about it in the Inventor Ideas forum back in early 2020.

Edit:  I attached the updated rule I used in my recent testing, just for reference.  It contains some methods that are not currently being used, but they could be further developed and included, if needed.  I was using all of them in my old codes, when I was adding tabs & panels also.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8

JMGunnar
Collaborator
Collaborator

Thank's again @WCrihfield 

 

Yes this is still not rember new Ribbon or Panel 

In my old tests, the new RibbonTabs and new RibbonPanels that were created by my rule were gone after restarting Inventor.  I have not tested that part again in 2024 yet though

 

But this works 

 

To create a custom icon use:
png format

16x16px or 32x32px

Must be put in the same folder as the Rule is stored

 

File name:
<Form or rule name> . <Light or dark> . <Small or large> .png

 

Example: “Push Parameters.light.large.png”

 

Thank's again @WCrihfield 

0 Likes