Example 2: Creating a Box or Sphere

Prerequisites:

Make sure you have completed the Example 1: Creating a Box example before beginning this example. Additionally, remember to exit the preview mode of the previous example by clicking on the Preview Extension button before starting this exercise.

  1. In the extension tree, right-click MyTool and choose "Add combo box." Alternatively, with your tool selected, you can select Tool Options from the Extension Builder Toolbar and choose "Add combo box."
  2. In the Properties panel, enter the following: Combo box name: "Box or Sphere"; Combo box values: "Box;Sphere"; Hud position: "Primary input"; Initial state: "Visible". Note that the Combo box values should be separated with semicolons.
  3. Click Create to add the combo box to your tool.
  4. In the Extension Tree, right-click MyTool and choose "Add text box." Alternatively, with your tool selected, you can select Tool Options from the Extension Builder Toolbar and choose "Add text box."
  5. In the Properties panel, enter the following information: Text box name: "Size"; Text box type: "Value(double)"; Initial Value: "0" (zero); Hud position: "Primary input"; and Initial state: "Visible".
  6. Click Create to add the text box to your tool.
  7. In the Script Editor, click to add a new script. Copy and paste the following code into the new script. Remove any formatting or spacing errors.

    
    # Python Script, API Version = V232
    def chooseShape(choice,shapeSize):
    if choice == "Box":
    BlockBody.Create(Point.Create(MM(-shapeSize), MM(-shapeSize), MM(0)), 
    Point.Create(MM(shapeSize), MM(shapeSize), MM(2*shapeSize)), ExtrudeType.ForceAdd)
    elif choice =="Sphere":
    SphereBody.Create(Point.Create(MM(0), MM(0), MM(0)), Point.Create(MM(shapeSize), 
    MM(0), MM(0)), ExtrudeType.None)
                    
  8. In the Script Editor, click Save As, name the script "chooseShapeReferenceScript," and choose a location to save your script.
  9. To reference the 'chooseShapeReferenceScript' script that you created for this tool, click Add reference script in the Extension Builder Toolbar located at the upper-left corner, locate the script, and click Open.
  10. Click "MyTool" in the extension tree.
  11. (Optional) In the Properties Panel, uncheck Close tool on complete to enable your tool to run multiple times. Only do this if you had previously selected this option in Example 1.
  12. Replace the 'MyTool' script in the Script editor with the following. Remove any formatting or spacing errors while copying and pasting the code below.

    
                    state = ScriptApi.GetTool("MyTool").ToolOptions[0].Value
                    shapeSize = ScriptApi.GetTool("MyTool").ToolOptions[1].Value
                    chooseShape(state,shapeSize)
  13. Click Apply.
  14. Click Preview Extension.
  15. In Preview Extension, MyTool has been updated with the combo and text boxes.

    Choose "Box" with size "3" and click Complete .