Skip to content

Generate, analyze, and visualize 3D clothoid curves seamlessly across SolidWorks, Python, and Excel. VBA macros for SolidWorks CAD modeling with Python scripts for curve analysis and visualization.

Notifications You must be signed in to change notification settings

ogunerkutay/SolidWorks-3D-Curve-Generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SolidWorks 3D Curve Generator VBA Macros and Python Integration

This repository includes multiple solutions for generating and analyzing 3D clothoid curves (spirals) using both SolidWorks VBA macros and Python scripts. The primary focus is on integrating SolidWorks for CAD modeling, Excel for data analysis, and Python for curve visualization and curvature computation.

Features

1. SolidWorks VBA Macros

First Macro (Basic Clothoid Curve)

  • Generates a 3D clothoid curve using parametric equations x(t)=cos(t²) and y(t)=sin(t²)
  • The z-coordinate is fixed at 0, but can be adjusted if needed
  • Automatically creates a 3D sketch in SolidWorks with points calculated at discrete intervals

Second Macro (Flexible Clothoid Curve)

  • Allows for custom start and end points in 3D space (startX, startY, startZ, endX, endY, endZ)
  • Linear interpolation between points combined with sine wave functions
  • Dynamic curve shape modification in 3D space

Parameters:

  • numPoints: Number of points for the curve (default: 100)
  • deltaT: Step size for the parametric values
  • startX, startY, startZ: Starting point coordinates
  • endX, endY, endZ: Ending point coordinates

Note: Results are automatically converted to SolidWorks' default unit system (meters)

2. Python Curve and Curvature Visualization

First Python Script

  • Generates 2D plot of the clothoid curve in the XY-plane
  • Integrates parametric equations numerically using numpy.cumsum()
  • Plots curvature κ(t) as 2t
  • Displays curve and curvature function in separate subplots

Second Python Script

  • Includes all functionality of the first script
  • Saves generated data (t, x, y, and curvature values) to Excel
  • Uses pandas DataFrame for data management
  • Creates curve_and_curvature.xlsx for analysis

Parameters:

  • t: Parameter range (0 to 2 or 1)
  • x(t): cos(t²) for x-coordinate
  • y(t): sin(t²) for y-coordinate
  • kappa(t): Curvature function (2t)

3. Excel Integration

  • Data export to Excel file with columns for t, x, y, and kappa
  • Facilitates curve analysis using spreadsheet tools
  • Compatible with both SolidWorks and Python workflows

Installation

Prerequisites

  • SolidWorks (any recent version)
  • Python 3.x
  • Required Python packages:
    pip install numpy matplotlib pandas

Usage

SolidWorks VBA Macros

  1. Open a part document in SolidWorks
  2. Access the VBA editor (Tools > Macro > New)
  3. Copy and paste the macro code
  4. Run the macro to generate the 3D clothoid curve

Python Scripts

  1. First Script (Visualization):

    python clothoid.py
  2. Second Script (Excel Export):

    python excelclothoid.py

Notes

  • SolidWorks macros require an active part document
  • Python scripts provide independent visualization and analysis
  • Excel integration enables data portability between tools

Contributing

Feel free to submit issues and enhancement requests!

About

Generate, analyze, and visualize 3D clothoid curves seamlessly across SolidWorks, Python, and Excel. VBA macros for SolidWorks CAD modeling with Python scripts for curve analysis and visualization.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages