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.
-
Step 1: Add the macro tools
Right clicking on the area of the command manager to add the macro tools
-
Step 2: Record the macro
Left click and record the macro
-
Step 3: Create the sketch
-
Step 4: Create the extrusión
-
Step 5: Stop the macro
Left click and stop the record
-
Step 6: Save the macro
-
Step 7: Edit the macro
Left click and edit the macro
-
Step 8: Generate the form
Right click on macro - Insert - UserForm
-
Step 9: Create the text box
Click on TextBox
-
Step 10: Locate the text box
With one click place it in the UserForm window, repeat the step to place another TextBox
-
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
-
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
-
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
-
Step 14: Cut the code
From the macro window - Macro (Code), select the code without the last End Sub paragraph and cut it
-
Step 15: Start programming
In the UserForm window double click on the created CommandButton to start programming
-
Step 16: Paste the code
Paste the copied code into the Macro window - UserForm (Code)
-
Step 17: Cut the call form
For the macro to call the code, from the Macro - UserForm (Code) window cut Sub main ()
-
Step 18: Paste the call form
Paste into Macro - Macro (Code), write the name of the form as is UserForm1 and add .show
-
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
-
Step 20: Type diameter
Write diameter / 2 and 0 in the following position
-
Step 21: Type thickness
Add thickness
-
Step 22: Save the macro
-
Step 23: Run the macro
-
Step 24: Enter the values you want