Creating a Visual Basic Action

You can create visual basic actions also known as macros with arguments.

See Also
In the Knowledge Base
What are the limitations related to macros with arguments?
  1. From the Compass, click 3D Modeling Apps and select Engineering Rules Capture.
  2. Click Visual Basic Action .
  3. Enter arguments in the box located between the parentheses and click OK to add the macro to the document.

    The arguments must always be separated by a comma.

    A VB Scripts subnode is added to the tree below the Relations node. A VB Script object is added below this subnode.
  4. In the Visual Basic Action Editor, enter your script.
  5. Right-click VB Script.1 and select VB Script.1 object > Run.
    The Select Inputs for Script Arguments window appears.
  6. Select the arguments in the geometry or in the tree and click OK to run the script.

Notes:
  • You may also create a Visual Basic Action by clicking the relation defined in the tree and clicking Visual Basic Action .
  • Macros with arguments are features that can be stored in 3D Shapes and in knowledge engineering specifications and that can be called from a rule (VBScriptRun) or a reaction. In this case, arguments are passed from the rule.
  • The VB script features with arguments are provided with a context menu enabling you to launch the script.

Example

In this example, you are going to create two String type parameters to a 3D Shape.

  1. From the Compass, click 3D Modeling Apps and select Engineering Rules Capture.
  2. Click Visual Basic Action .
  3. In the Visual Basic Action Editor, copy/paste the script below:

    Dim knowlObjs as KnowledgeObjects
    Set knowlObjs =  selectedObject.GetItem("KnowledgeObjects")
    Dim oParams As ParmsSet
    Set oParams = knowlObjs.GetKnowledgeRootSet(TRUE, 0)
    Dim strParam1 As StrParam
    Set strParam1 = oParams.Factory.CreateString("FirstName", "")
    Dim strParam2 As StrParam
    Set strParam2 = oParams.Factory.CreateString("LastName", "")
    End Sub

  4. Enter the selectedObject argument in the box located between the parentheses and click OK to add the macro to the document.

    A VB Scripts subnode is added to the tree below the Relations node.

  5. Expand the VB Script subnode.
  6. Right-click VB Script.1 and select VB Script.1 object > Run.
  7. Select the 3D Shape and click OK to run the script.

    The two String type parameters are added to the document.