"The parameter is incorrect" when setting Macro Control Dec descriptive text

"The parameter is incorrect" when setting Macro Control Dec descriptive text

DRoam
Mentor Mentor
1,299 Views
15 Replies
Message 1 of 16

"The parameter is incorrect" when setting Macro Control Dec descriptive text

DRoam
Mentor
Mentor

I'm trying to set the descriptive text for a macro control definition, using the iLogic code below:

 

 

Dim oMacroDef As Inventor.MacroControlDefinition = Nothing
Try
	oMacroDef = ThisApplication.CommandManager.ControlDefinitions("macro:" & "testmodule" & "." & "testsub")
	MsgBox("Got existing definition")
Catch
	oMacroDef = ThisApplication.CommandManager.ControlDefinitions.AddMacroControlDefinition("testmodule" & "." & "testsub")
	MsgBox("Created new definition")
End Try

MsgBox("Current description: " & oMacroDef.DescriptionText)

oMacroDef.DescriptionText = "My Custom Description."

MsgBox("New description: " & oMacroDef.DescriptionText)

 

Creating or getting the macro definition works perfectly, as does reading the descriptive text. However, when I try to set the descriptive text, I get the  error: "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

 

According to the API manual, the DescriptionText property is a read/write property. So why can't I set it?

 

Running Inventor 2017.4.7.

0 Likes
1,300 Views
15 Replies
Replies (15)
Message 2 of 16

JamieVJohnson2
Collaborator
Collaborator

Is it possible that its complaining about the content of your text, such as commands don't like to use spaces.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 16

DRoam
Mentor
Mentor

I wouldn't think so, it's not complaining about the command name, it's complaining about the description text, which should definitely be able to contain spaces. Just for kicks I tried removing the spaces (and the period) and it still throws the error. So it must be something else.

0 Likes
Message 4 of 16

JamieVJohnson2
Collaborator
Collaborator

Inventor refuses to set it to "" as well.  This looks like a case of incomplete API, and 'any error will do'.  Is there a way to set the text WHILE creating the object?  Because it is acting as a read-only value (or a read/write value to a read only value), in those situations the developer may have intended it to be set once and only once.  Still experimenting on it.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 5 of 16

DRoam
Mentor
Mentor

@JamieVJohnson2 wrote:

Is there a way to set the text WHILE creating the object?  Because it is acting as a read-only value (or a read/write value to a read only value), in those situations the developer may have intended it to be set once and only once. 


Nope, the only way to create a MacroControlDefinition is using ControlDefinitions.AddMacroControlDefinition, which only accepts one argument: the name of the macro.

 

So right now it seems like your "incomplete API" explanation is most likely. @MjDeck, can you comment on if this is the case? To bring you up to speed, trying to set the MacroControlDefinition.DescriptionText property always results in a "The parameter is incorrect" error, even though it's supposed to be a read/write property. Is this a problem with the API, or am I doing something wrong?

0 Likes
Message 6 of 16

MjDeck
Autodesk
Autodesk

@DRoam, you're right: the API is incomplete. The setter for the MacroControlDefinition.DescriptionText is not implemented and will always throw an error.

We should either implement it, or update the documentation. I'll try to find out more.


Mike Deck
Software Developer
Autodesk, Inc.

Message 7 of 16

YuhanZhang
Autodesk
Autodesk

If you want users to view the description/tooltip for the macro button, you can set the ProgressiveTooltip instead of the MacroControlDefinition.Description. You can use below lines:

oMacroDef.ProgressiveToolTip.Title = "Command Name"
oMacroDef.ProgressiveToolTip.Description = "Brief description of the command."
oMacroDef.ProgressiveToolTip.ExpandedDescription = "Detailed description of the command."

 

to replace your code:

oMacroDef.DescriptionText = "My Custom Description."

 

Below is a sample button with the progressive tooltip:

progressivetooltip.png

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 8 of 16

DRoam
Mentor
Mentor

@YuhanZhang that's great! Thanks for that tip. That will work great for my ribbon buttons.

 

Unfortunately, the button I actually was trying to do this for is going into the File menu, and apparently file menu buttons don't show tooltips...?

 

Is there a reason for this? Is this something that could be implemented?

0 Likes
Message 9 of 16

DRoam
Mentor
Mentor

A couple other observations...

 

1. It appears the MacroControlDefinition.ToolTipText set method hasn't been properly implemented, as well. I get the same "The parameter is incorrect" error.

 

2. I think possibly the TargetControlInternalName argument for the CommandControls.AddMacro method may not be properly implemented, either. I'm pretty sure I'm using it correctly, but it always places my button after the first control in the CommandControls collection rather than the one I specified.

 

Here's the code I'm using, you can run it to see what I'm talking about. It should place the custom button after the "Export to DWG" button, but instead it places it after the "Image" button.

 

Dim oFileButtons As Inventor.CommandControls = ThisApplication.UserInterfaceManager.FileBrowserControls

Dim oExportButton As Inventor.CommandControl = oFileButtons.Item("Export")

'~~~~~Get or create Macro Control Definition~~~~~
Dim oMacroDef As Inventor.MacroControlDefinition = Nothing
Try
	oMacroDef = ThisApplication.CommandManager.ControlDefinitions("macro:" & "RibbonButtons" & "." & "DXF Auto–Export")
Catch
	Try
		oMacroDef = ThisApplication.CommandManager.ControlDefinitions.AddMacroControlDefinition("RibbonButtons" & "." & "DXF Auto–Export")
	Catch
		MessageBox.Show("Could not create control definition for macro """ & "DXF Auto–Export" & """ in module """ & "RibbonButtons" & """.")
		Exit Sub
	End Try
End Try

'~~~~~Set Macro properties~~~~~
'oMacroDef.DescriptionText = "Exports DXFs for the active Assembly (or a single active Part) to the Project folder."
oMacroDef.ProgressiveToolTip.Title = "DXF Auto-Export"
oMacroDef.ProgressiveToolTip.Description = "Exports DXFs for the active Assembly (or a single active Part) to the Project folder."

'~~~~~Check for button~~~~~
Dim oButton As Inventor.CommandControl = Nothing
For Each oCheckButton As Inventor.CommandControl In oExportButton.ChildControls
	If oCheckButton.ControlDefinition Is oMacroDef Then
		oButton  = oCheckButton
		Exit For
	End If
Next

'~~~~~Create button if missing~~~~~
If oButton Is Nothing Then
	Try
		oButton = oExportButton.ChildControls.AddMacro(oMacroDef,True,True,"AppExportDwgCmd",False)
	Catch
		MessageBox.Show("Could not create button for macro """ & "RibbonButtons" & "." & "DXF Auto–Export" & """ " & _
			"in menu """ & "Export" & """ in File Menu.")
	End Try
Else
	'Un-comment the following line for testing. Running this rule will then toggle the button on and off.
	oButton.Delete
End If

Is this an API error or a PEBKAC error? 😉

0 Likes
Message 10 of 16

YuhanZhang
Autodesk
Autodesk

I thought you want to add the macro to the ribbon panels, then you can use the progressive tooltip, if you place it to File Browser there are some limitations/issues to it.  At present you can either just place it on the ribbon panel or create a ButtonDefinition for File Browser.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 11 of 16

DRoam
Mentor
Mentor

@YuhanZhang, is it possible to associate a macro with a ButtonDefinition?

0 Likes
Message 12 of 16

YuhanZhang
Autodesk
Autodesk

We can add ButtonDefinition from a macro, but to make the button definition work in VBA from clicking a button that would introduce some issue to you, like the VBA may be held because you need to monitor the button click so you can't run any other VBA macros, and users may stop the command carelessly. I recommend to just create an addin to do the export DXF job instead of macro/iLogic rule if you want to place the button onto the File Browser menu. But I can show you how to create the button from VBA&iLogic code here, you can make your decision:

 

1. Copy the below VBA code to your "Modul1" module in ApplicationProject.

Sub CreateExportDXFCommand()
    Dim oFileButtons As Inventor.CommandControls
    Set oFileButtons = ThisApplication.UserInterfaceManager.FileBrowserControls
    
    Dim oExportButton As Inventor.CommandControl
    Set oExportButton = oFileButtons.Item("Export")
    
     
    Dim oExportDXFDef As Inventor.ButtonDefinition
     On Error Resume Next
     Set oExportDXFDef = ThisApplication.CommandManager.ControlDefinitions("CustomAutoExportDXFCmd")
     
     If Err Then
        Err.Clear
        On Error GoTo 0
        Set oExportDXFDef = ThisApplication.CommandManager.ControlDefinitions.AddButtonDefinition("Auto Export to DXF", "CustomAutoExportDXFCmd", kFileOperationsCmdType, "Custom commands", "Auto Export active part/assembly document to DXF", "Using this command to auto export your current document to DXF")
     End If
    
    oExportDXFDef.ProgressiveToolTip.Title = "DXF Auto-Export"
    oExportDXFDef.ProgressiveToolTip.Description = "Exports DXFs for the active Assembly (or a single active Part) to the Project folder."
    
    Dim oButton As Inventor.CommandControl
    Dim oCheckButton As CommandControl
    For Each oCheckButton In oExportButton.ChildControls
        If oCheckButton.ControlDefinition Is oExportDXFDef Then
            Set oButton = oCheckButton
            Exit For
        End If
    Next
    
    '~~~~~Create button if missing~~~~~
    If oButton Is Nothing Then
      
           Set oButton = oExportButton.ChildControls.AddButton(oExportDXFDef, True, True, "AppExportDwgCmd", False)
           
           Dim ocls As New Class1
           ocls.init
      
    Else
        'Un-comment the following line for testing. Running this rule will then toggle the button on and off.
        oButton.Delete
    End If

End Sub

 

2. Copy below VBA code to your "Class1" class module in ApplicationProject.

Private WithEvents oButtonDef As ButtonDefinition

Public Sub init()
   Set oButtonDef = ThisApplication.CommandManager.ControlDefinitions("CustomAutoExportDXFCmd")
     
    Do

        ThisApplication.UserInterfaceManager.DoEvents
    Loop Until bStop
    
    
End Sub
Private Sub oButtonDef_OnExecute(ByVal Context As NameValueMap)
     ' here add your code to export the active document to DXF
     MsgBox "I am triggered."
End Sub

 

3. Add below iLogic code to an iLogic rule, and you can run the rule.

Sub Main()
	Dim m_inventorApp As Inventor.Application
	m_inventorApp = ThisApplication
    
On Error Resume Next ' get the application VBA project Dim oVBAProj As InventorVBAProject Dim oAppVBAProj As InventorVBAProject For Each oVBAProj In m_inventorApp.VBAProjects If oVBAProj.ProjectType = VBAProjectTypeEnum.kApplicationVBAProject Then oAppVBAProj = oVBAProj Exit For End If Next ' get the VBA module Dim oVBAComp As InventorVBAComponent oVBAComp = oVBAProj.InventorVBAComponents("Module1") Dim oVBASub As InventorVBAMember oVBASub = oVBAComp.InventorVBAMembers("CreateExportDXFCommand") oVBASub.Execute() End Sub

 

4. Now from the File Browser menu, you can find the button like below, click it a message is popped up.

 

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 13 of 16

YuhanZhang
Autodesk
Autodesk

Attach the preview picture for the command.

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 14 of 16

DRoam
Mentor
Mentor

Thanks a lot, Yahun (or should I call you Rocky?) I appreciate you taking the time to show me how to do that.

 

I've been getting closer and closer to feeling like it's time to go the add-in route. It's a little intimidating to me, though. It seems like a daunting thing to take on. I've found multiple guides for how to create one, but they each seem a little different, so I'm not sure which one to follow.

 

Is it possible to create a very simple, small add-in that all it would do is place some buttons in the ribbon/file menu that simply fire VBA subs or external iLogic rules? That would be a good transition step for me until I can take the time to properly port my tools into the add-in.

 

Could you help get me started on how to do that, or point me to a guide you would recommend?

0 Likes
Message 15 of 16

JamieVJohnson2
Collaborator
Collaborator

@DRoam  Since you already know the Inventor Object tree pretty well, the AddIn, can be programmed in VB.Net language with the same object tree, so only a few different syntax updates (being that vba = version 6, and vb.net = version 7 and up).  iLogic compiler can use direct VB.Net code so you can quick test ideas in that if you like.  Also, you CAN use VB.Net to create and/or execute iLogic code in a blank file or file with existing code.

 

 Dim iLogicAddInGUID As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
        Dim addin As Inventor.ApplicationAddIn = Nothing
        Try
            addin = invApp.ApplicationAddIns.ItemById(iLogicAddInGUID)
        Catch ex As Exception
            MsgBox("Unable to load iLogic Add In", MsgBoxStyle.SystemModal)
        End Try
        If Not addin.Activated Then
            addin.Activate()
        End If

        Dim strRuleCalcs As String = String.Empty
        strRuleCalcs = "Sub Main()” & vbCrLf &
            “    RunCalcs()” & vbCrLf &
            “    GetCustomProperties()” & vbCrLf &
            “End Sub” 'and many other lines of code for the iLogic editor
invApp.SilentOperation = True
        Dim iLogAuto As Object 'Autodesk.iLogic.Interfaces.IiLogicAutomation
        iLogAuto = addin.Automation
        iLogAuto.CallingFromOutside = True
        iLogAuto.EnterDelayedRuleRunningMode()
        Dim newRule As Object = iLogAuto.AddRule(Model, "Calcs", "")
        newRule.text = strRuleCalcs
        iLogAuto.ExitDelayedRuleRunningMode()
        iLogAuto.RulesOnEventsEnabled = True
        AssignRuleToILogicEvent(Model, "Calcs", "BeforeDocSave0", 700)
        invApp.SilentOperation = False

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 16 of 16

YuhanZhang
Autodesk
Autodesk

You can install the Inventor SDK DeveloperTools.msi(e.g. C:\Users\Public\Documents\Autodesk\Inventor 2019\SDK\DeveloperTools.msi), the Developer Tools will install the Inventor Addin Wizards to Visual Studio, so you can now launch VS follow the steps in below help page to create your own addin:

 

http://help.autodesk.com/view/INVNTOR/2019/ENU/?guid=GUID-52422162-1784-4E8F-B495-CDB7BE9987AB

 

You can also refer to the samples in the Developer Tools(e.g C:\Users\Public\Documents\Autodesk\Inventor 2019\SDK\DeveloperTools\Samples\VB.NET\AddIns\SimpleAddIn) to know how to add buttons to ribbon, and you already know how to add buttons to File Browser menu.

 

Hope it helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes