This application allows you to convert SVG files to Onshape 3D models by leveraging the Onshape API. It provides both a web interface and a JavaScript library for programmatic interaction with Onshape.
- OAuth authentication with Onshape
- List and create Onshape documents
- Create basic 3D models from examples
- Convert SVG files to Onshape models
- JavaScript library for Onshape API interaction
-
Clone the repository:
git clone https://github.com/yourusername/svg-to-onshape.git cd svg-to-onshape
-
Install dependencies:
npm install
-
Create a
.env
file with your Onshape API credentials:ONSHAPE_CLIENT_ID=your_client_id ONSHAPE_CLIENT_SECRET=your_client_secret ONSHAPE_CALLBACK_URL=http://localhost:3000/oauth/callback SESSION_SECRET=your_session_secret
You can get your Onshape API credentials by creating an application in the Onshape Developer Portal.
npm start
The application will be available at http://localhost:3000
.
- Open your browser and navigate to
http://localhost:3000
- Click "Authenticate with Onshape" to connect to your Onshape account
- Use the examples or upload an SVG file to convert
The Onshape client library can be used programmatically:
const OnshapeClient = require('./src');
// Create a client instance
const client = new OnshapeClient({
getAuthHeaders: () => ({
'Authorization': `Bearer ${accessToken}`
}),
unitSystem: 'inch'
});
// Example: Create a document
async function createDocument() {
const document = await client.createDocument('My Document', 'Created programmatically');
console.log('Created document:', document);
// Get a part studio
const partStudio = await client.getPartStudio({ document });
// Create a sketch
const sketch = await Sketch.create({
partStudio,
plane: partStudio.features.topPlane,
name: "Example Sketch"
});
// Add a circle to the sketch
await sketch.addCircle([0, 0], 0.5);
// Extrude the sketch
const extrude = await Extrude.create({
partStudio,
faces: await sketch.getEntities(),
distance: 1,
name: "Example Extrude"
});
}
The SVG conversion process involves:
- Parsing the SVG file
- Converting SVG paths to Onshape sketch entities
- Creating sketches in Onshape
- Extruding the sketches to create 3D objects
Currently, the application supports:
- Basic shapes (circles, rectangles)
- Simple paths
- Basic transformations
To run integration tests that connect to the actual Onshape API:
-
Create a
.env
file in the project root with your Onshape API credentials:ONSHAPE_ACCESS_KEY=your_access_key_here ONSHAPE_SECRET_KEY=your_secret_key_here
-
Run the integration tests:
npm run test:integration
Note: If credentials are not provided, integration tests will be skipped automatically.
MIT
This project uses the Onshape API. Learn more about Onshape at onshape.com.
/onshape-client
/src
/api
rest-api.js // Core API functionality
endpoints.js // Endpoint definitions
schema.js // Data models/schema
/features
sketch.js // Sketch feature implementation
extrude.js // Extrude feature implementation
plane.js // Plane implementations
/entities
entity.js // Entity base and implementations
/utils
credentials.js // Credential management
misc.js // Miscellaneous utilities
index.js // Main export
package.json
README.md
- REST API Client: Core implementation for making HTTP requests to Onshape
- Feature Classes: Implementations for Sketch, Extrude, etc.
- Entity Management: Classes for entities like faces, edges, etc.
- Authentication: OAuth integration
- Utilities: Helper functions, error handling, etc.