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?
-
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.
-
@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. -
@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.