tpaviot / pythonocc-core

Python package for 3D geometry CAD/BIM/CAM
GNU Lesser General Public License v3.0
1.39k stars 380 forks source link

Question: How to extract original file unit from STEP file #1353

Closed alex-all3dp closed 4 months ago

alex-all3dp commented 4 months ago

Hello,

I am using the following code to extract the geometry from a STEP file:

from OCC.Extend.DataExchange import read_step_file
from OCC.Core.BRepBndLib import brepbndlib
from OCC.Core.GProp import 

shape = read_step_file(file_path)

if shape is None:
  raise Exception("Failed to load model " + model_filepath)

bbox = Bnd_Box()
brepbndlib.AddOptimal(shape, bbox)
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
gprops = GProp_GProps()
brepgprop.VolumeProperties(shape, gprops)
volume = gprops.Mass()
brepgprop.SurfaceProperties(shape, gprops)
area = gprops.Mass()

dimensions = {
  "x": xmax - xmin,
  "y": ymax - ymin,
  "z": zmax - zmin,
}

return {
   "volume": volume,
    "area": area,
    "dimensions": dimensions,
}

Now it appears that OCC converts the geometry of the design to mm, even if it was originally designed in inch for example? Is that observation correct?

Is there a way to extract the original file unit from the STEP file in order to convert the values back to the original file unit, if needed?

Thank you for your help!

Kind regards Alex

alex-all3dp commented 4 months ago

Found a way using step_reader.FileUnits()