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: 

Open Parameter Dialog box with code

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
grim2020
1168 Views, 8 Replies

Open Parameter Dialog box with code

Hi,

I'm using VBA in Inventor 2010.  I want to create a macro that adds 3 fields to a part for LRNGTH, WIDTH and THICKNESS, as well as comments and setting the export to be export out.  My program is below and works well.  However i would like to end the macro with the parameter dialog box open.  What code do i need to do this?

 

Sub AddBomFields()
   
    'adds LENGTH, WIDTH and THICKNESS user parameters to part
   
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
  
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition

    Dim oUserParam As UserParameter
    Set oUserParam = oCompDef.Parameters.UserParameters.AddByValue("LENGTH", 0, kInchLengthUnits)
    Set oUserParam = oCompDef.Parameters.UserParameters.AddByValue("WIDTH", 0, kInchLengthUnits)
    Set oUserParam = oCompDef.Parameters.UserParameters.AddByValue("THICKNESS", 0, kInchLengthUnits)
   
    ' Get the Parameters object. Assumes a part or assembly document is active.
    Dim oParameters As Parameters
    Set oParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters

    ' Get the parameter named "LENGTH".
    Dim oLengthParam As Parameter
    Set oLengthParam = oParameters.Item("LENGTH")
    oLengthParam.Comment = "BOM LENGTH"
    oLengthParam.ExposedAsProperty = True
   
    ' Get the parameter named "WIDTH".
    Dim oWidthParam As Parameter
    Set oWidthParam = oParameters.Item("WIDTH")
    oWidthParam.Comment = "BOM WIDTH"
    oWidthParam.ExposedAsProperty = True
       
    ' Get the parameter named "THICKNESS".
    Dim oThicknessParam As Parameter
    Set oThicknessParam = oParameters.Item("THICKNESS")
    oThicknessParam.Comment = "BOM THICKNESS"
    oThicknessParam.ExposedAsProperty = True
   
    ThisApplication.ActiveDocument.Update
   
    Dim Msg, Style, Title, Help, Ctxt, Response
    Msg = "Length, Width and Thickness parameters added."    ' Define message.
    Style = vbOKOnly    ' Define buttons.
    Title = "Parameter Addition Complete"    ' Define title.
   
    ' Display message.
    Response = MsgBox(Msg, Style, Title)
       
    End Sub

8 REPLIES 8
Message 2 of 9
barbara.han
in reply to: grim2020

To fire a command, you need to find the internal name of that command, then call the Execute method on the corresponding ControlDefinition object.

 

Here is the code to fire Parameters dialog:   

 

ThisApplication.CommandManager.ControlDefinitions.Item("AppParametersCmd").Execute

 

You can use the following code to get all internal names of all commands:

Sub test()

    Dim oControlDef As ControlDefinition

    Open "c:\1.txt" For Output As #1

    Dim s As String

   

    For Each oControlDef In ThisApplication.CommandManager.ControlDefinitions

        s = oControlDef.InternalName & ":" & oControlDef.DescriptionText

        Write #1, s

    Next

    Close #1

End Sub

 

Barbara Han

Developer Technical Services

Autodesk

Barbara Han
Developer Technical Services
Autodesk Developer Network
Message 3 of 9
grim2020
in reply to: barbara.han

Excellent.  Thank you.

Message 4 of 9
grim2020
in reply to: barbara.han

Is there a way to condense my code to allow the export and comments to be added at the same time as the parameter is created?

Message 5 of 9
barbara.han
in reply to: grim2020

I finally got time to look into this thread again. You can simplify your code so that there is no need to read the parameter later in order to change its properties. Here is the simplified version:

Sub AddBomFields()

    'adds LENGTH, WIDTH and THICKNESS user parameters to part
   
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
   
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition
   
    Dim oUserParam As UserParameter
    Set oUserParam = oCompDef.Parameters.UserParameters.AddByExpression("LENGTH", 0, kInchLengthUnits)
    oUserParam.Comment = "BOM LENGTH"
    oUserParam.ExposedAsProperty = True
   
    Set oUserParam = oCompDef.Parameters.UserParameters.AddByValue("WIDTH", 0, kInchLengthUnits)
    oUserParam.Comment = "BOM WIDTH"
    oUserParam.ExposedAsProperty = True
   
    Set oUserParam = oCompDef.Parameters.UserParameters.AddByValue("THICKNESS", 0, kInchLengthUnits)
    oUserParam.Comment = "BOM THICKNESS"
    oUserParam.ExposedAsProperty = True
   
    ThisApplication.CommandManager.ControlDefinitions.Item("AppParametersCmd").Execute
  
End Sub

Barbara Han
Developer Technical Services
Autodesk Developer Network
Message 6 of 9
grim2020
in reply to: barbara.han

Thank you Barbara,  I understand VB well enough, it's just getting the Inventor sysntax down.

Message 7 of 9
barbara.han
in reply to: grim2020

Yes, it would be even simpler if AddByVaule or an other API has more parameters to set all those properties in a line of code, but unluckily no that API. How it should not be difficult to use currect way to do the same. 

Barbara Han
Developer Technical Services
Autodesk Developer Network
Message 8 of 9
grim2020
in reply to: barbara.han

Barbara,

 

I have the following code to add a length field.  How do I set the unit string to off so the "in" does not display?

 

Sub AddBomFieldsL()

    'adds LENGTH, WIDTH and THICKNESS user parameters to part
  
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
  
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition
  
    Dim oUserParam As UserParameter
    Set oUserParam = oCompDef.Parameters.UserParameters.AddByExpression("LENGTH", 0, kInchLengthUnits)
    oUserParam.Comment = "BOM LENGTH"
    oUserParam.ExposedAsProperty = True
  
    ThisApplication.CommandManager.ControlDefinitions.Item("AppParametersCmd").Execute
 
End Sub

Message 9 of 9
grim2020
in reply to: grim2020

Answered my own question:

 

    oUserParam.CustomPropertyFormat.ShowUnitsString = False
    oUserParam.CustomPropertyFormat.Precision = kTwoDecimalPlacesPrecision

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

Post to forums  

Autodesk Design & Make Report