JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    help: Import DXF and calculate bounding box

    General Discussions
    2
    4
    601
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ashish
      Ashish last edited by

      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?

      z3dev 1 Reply Last reply Reply Quote 0
      • z3dev
        z3dev @Ashish last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • Ashish
          Ashish last edited by

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

          z3dev 1 Reply Last reply Reply Quote 0
          • z3dev
            z3dev @Ashish last edited by

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB | Contributors