Solidworks Tutorial - Macro to generate a cylinder or disk automatically

In this solidworks tutorial I intend to show how to generate a macro, which through a user form automatically creates a cylinder or disk with custom values for diameter and thickness.
This function can be very helpful when you need to create some type of extrusion quickly.

En este tutorial de solidworks pretendo mostrar como generar una macro, la cual por medio de un formulario de usuario crea un cilindro o disco automáticamente con valores personalizados de diámetro y espesor.
Esta función puede ser de mucha ayuda cuando se requiere crear algún tipo de extrusión rapidamente.

  1. Step 1: Add the macro tools

    Right clicking on the area of the command manager to add the macro tools

  2. Step 2: Record the macro

    Left click and record the macro



  3. Step 3: Create the sketch




  4. Step 4: Create the extrusión



  5. Step 5: Stop the macro

    Left click and stop the record


  6. Step 6: Save the macro




  7. Step 7: Edit the macro

    Left click and edit the macro


  8. Step 8: Generate the form

    Right click on macro - Insert - UserForm

  9. Step 9: Create the text box

    Click on TextBox

  10. Step 10: Locate the text box

    With one click place it in the UserForm window, repeat the step to place another TextBox

  11. Step 11: Create and locate the label

    Click on Label and place it in the UserForm window, repeat the last step to place another Label


  12. Step 12: Name the label

    Click on Label 1 and go to the Properties Caption tab and give the name you want, repeat for Label 2



  13. Step 13: Create the command button

    Add CommandButton and place it in the UserForm window and then give it a name in the Properties tab - CommandButton


  14. Step 14: Cut the code

    From the macro window - Macro (Code), select the code without the last End Sub paragraph and cut it


  15. Step 15: Start programming

    In the UserForm window double click on the created CommandButton to start programming


  16. Step 16: Paste the code

    Paste the copied code into the Macro window - UserForm (Code)


  17. Step 17: Cut the call form

    For the macro to call the code, from the Macro - UserForm (Code) window cut Sub main ()

  18. Step 18: Paste the call form

    Paste into Macro - Macro (Code), write the name of the form as is UserForm1 and add .show


  19. Step 19: Create the variables

    Add the variables in the Macro window - UserForm (Code):

    Dim diameter As Double

    Dim thickness As Double

    diameter = CDbl (TextBox1.Text) / 1000

    thickness = CDbl (TextBox2.Text) / 1000


  20. Step 20: Type diameter

    Write diameter / 2 and 0 in the following position


  21. Step 21: Type thickness

    Add thickness


  22. Step 22: Save the macro



  23. Step 23: Run the macro



  24. Step 24: Enter the values you want



Comments