This project demonstrates a parametric model adjustment for a tea cup using the SolidWorks API and .NET. It allows users to specify a target volume (in milliliters), adjust the dimensions of a cup model accordingly, and save the modified file.
- Parametric Design: Automatically adjusts cup and handle dimensions while maintaining aspect ratios.
- Volume Calculation: Calculates the new dimensions based on the desired inner volume.
- GUI Interface: User-friendly application to select files, folders, and target volume.
- Detailed Parameters Table: Displays current parameters, calculations, and logic in a structured format.
- Save Adjusted Model: Saves the updated SolidWorks part file in the specified destination folder.
-
SolidWorks Software
- SolidWorks must be installed on your system with API support.
-
.NET SDK Software
- Download and install the .NET 6.0 SDK (or later) from Microsoft .NET.
-
SolidWorks API DLLs Files
- Ensure you have access to the
SolidWorks.Interop.sldworks.dllandSolidWorks.Interop.swconst.dllfiles.
- Ensure you have access to the
-
Download the Project
-
Visit the GitHub repository: Tea Cup SolidWorks API.
-
Click on the Code button and select Download ZIP, or clone the repository:
git clone https://github.com/ephi052/TeaCupSolidWorksAPI.git
-
-
Run the Install Script
-
Navigate to the project folder:
cd TeaCupSolidWorksAPI -
Run the
install.batscript:.\install.bat
This script:
- Copies the required SolidWorks API DLLs into the
libsfolder. - Restores NuGet dependencies.
- Builds the project.
-
-
Prepare SolidWorks
- The project includes a sample parametric SolidWorks part file:
TEA CUP - Parametric.SLDPRT. - Use this file as input for the application.
- The project includes a sample parametric SolidWorks part file:
-
Launch the Application
Run the application from the command line:
dotnet run
The GUI interface will appear.
-
Select Input File
- Click Select File to choose a SolidWorks part file (
.SLDPRT).
- Click Select File to choose a SolidWorks part file (
-
Select Destination Folder
- Click Select Folder to specify where the adjusted file will be saved.
-
Enter Target Volume
- Input the desired inner volume (in milliliters) into the text box.
-
Run Adjustment
- Click Run to process the file.
- The application will calculate the new parameters, adjust the model, and save the updated file in the specified folder.
-
View Parameters Table
After processing, a new window will display:
- Current cup and handle parameters.
- Logic and calculations for the adjustments.
- Save status and path of the modified file.
The user interface for selecting files, folders, and target volume:
The output window displaying calculations and adjusted parameters:
An example of the adjusted tea cup model:
The inner volume of the tea cup is calculated based on the geometric dimensions:
-
Inner Cup Volume Formula: The cup is modeled as a combination of a cylindrical body and curved base:
-
Cylindrical Volume:
$$V_{cylinder} = \pi \times (R_{inner}^2) \times H$$ Where:-
$$R_{inner}$$ : Inner radius of the cup. -
$$H$$ : Height of the cup.
-
-
Curved Base Adjustment: The volume of the curved base is approximated based on its geometry.
$$V_{base adjustment} = \frac{\pi \times h^2 \times (3R - h)}{6}$$ Where:
-
$$3R$$ : Inner radius of the cup. -
$$h$$ : Height of the spherical cap, approximated as$$\frac{R_{\text{fillet}}}{2}$$ .
-
The total volume is:
$$V_{total} = V_{cylinder} - V_{base adjustment}$$ -
-
Aspect Ratio Maintenance: To ensure the cup maintains its original shape, the aspect ratio (
$$H / R_{inner}$$ ) is preserved during resizing. -
New Dimensions Calculation:
- Given a target volume
$$V_{target}$$ :- Calculate the new inner radius
$$R_{inner,new}$$ :$$R_{inner,new} = \sqrt{\frac{V_{target}}{\pi \times H}}$$ - Adjust the height
$$H_{new}$$ proportionally to maintain the aspect ratio:$$H_{new} = R_{inner,new} \times (H / R_{inner})$$
- Calculate the new inner radius
- Given a target volume
The handle dimensions are adjusted based on the updated cup dimensions:
-
Handle Height:
$$H_{handle} = H_{new} \times 0.67$$ Logic: The handle height is set to 67% of the new cup height. -
Handle Offset:
$$Offset_{handle} = H_{handle} \times 0.40$$ Logic: The offset is 40% of the handle height. -
Attachment Length:
$$L_{attach} = H_{handle} \times 0.60$$ Logic: The attachment length is 60% of the handle height. -
Outer Arc Radius: The outer arc radius of the handle is scaled proportionally to match the new cup height.
| Parameter | Symbol | Formula/Value |
|---|---|---|
| Height | Adjusted based on aspect ratio. | |
| Inner Radius | ||
| Base Radius | Defined in the model | |
| Wall Thickness | Defined in the model | |
| Fillet Radius | Defined in the model | |
| Inner Volume |
| Parameter | Symbol | Formula/Value |
|---|---|---|
| Handle Height | ||
| Handle Offset | ||
| Handle Attachment Length | ||
| Outer Arc Radius | Adjusted proportionally |
TeaCupSolidWorksAPI/
│
├── install.bat # Install script for dependencies and setup
├── README.md # Project documentation
├── .gitignore # Git ignore rules
├── libs/ # SolidWorks API DLLs
│ ├── SolidWorks.Interop.sldworks.dll
│ ├── SolidWorks.Interop.swconst.dll
├── Program.cs # Main application logic
├── TeaCupSolidWorksAPI.csproj # .NET project file
├── TEA CUP - Parametric.SLDPRT # Sample parametric SolidWorks part file
└── images/ # Screenshots for README
├── input_popup.png
├── output_popup.png
├── res.png
-
Volume Adjustment Logic:
- Calculates the new dimensions for the cup and handle while maintaining the original aspect ratio.
-
SolidWorks API Integration:
- Utilizes the SolidWorks API to programmatically read and modify part parameters.
-
Save Modified Part:
- Automatically saves the adjusted file with updated parameters in the specified folder.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature-name
- Commit your changes and push them:
git push origin feature-name
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.