help: Import DXF and calculate bounding box
-
I'm new to JSCAD.
Here is my use case: As a web user, I can load a DXF file so that we can automatically calculate the bounding box around the object.
How do I do this?
-
@Ashish Welcome!
There are a couple of ways to do this but let's just use the WEB UI (website).
The best way to do this is by making a project (directory) and put the parts into the directory.
- Create a directory, e.g. newdesign
- Copy the pieces into the 'newdesign' directory, both index.js and my.dxf
- Load the DXF as part of the design
const { transforms } = require('@jscad/modeling') const main = () => { let contents = require('./my.dxf') contents = transforms.scale([5, 5, 5], contents) // and measure, etc return contents }Once ready, drag and drop the 'newdesign' directory to the website.
-
@z3dev thank you so much, that helped with the loading of the DXF!
Few more questions if you don't mind.
I've taken "contents" and want to get the bounding box for it so I can determine its size. I read there a "getBounds()" that can be used: https://openjscad.xyz/dokuwiki/doku.php?id=en:design_guide_measurements
But contents itself doesnt have a method - ie contents.getBounds() doesnt exist. I probably don't understand the data model here I will admit. -
Sorry… that documentation is not complete. We will have to make some updates.

There’s slightly better documentation here.
Basically, your design needs to call measureBoudingBox(shape), which returns an array of points, lower and upper bounds.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login