Getting information from step-file

viter.alex

Looking around for some CAD
Hello all!
I'm very newbie with pytonocc. Till yesterday I knew nothing about it.
I need to process step files: get name of shape, volume, surface and so on.
Trying to do like this:

Python:
from OCC.Core.GProp import GProp_GProps
from OCC.Core.BRepGProp import brepgprop_VolumeProperties
from OCC.Extend.DataExchange import read_step_file
files = ["path1", "path2"]
prop = GProp_GProps()
tolerance = 1e-5 # Adjust to your liking
for file in files:
  my_shape = read_step_file(file)
  volume = brepgprop_VolumeProperties(my_shape, prop)
  print(volume)
And get a result that is different from FreeCad. On file un045831A-00Rev--1.stp I got a list of errors which I don't understand and no volume at all:

Code:
**  Model Complete Check List  **
Check:1 -- Global Check
Complex Type incorrect : SOLID_ANGLE_UNIT / SI_UNIT ...
Complex Type incorrect : NAMED_UNIT / LENGTH_UNIT ...
Check:2 -- Entity (n0:id) 170:#176   Type:(NAMED_UNIT,PLANE_ANGLE_UNIT,SI_UNIT)
Parameter n0.1 (dimensions) not Derived
Check:3 -- Entity (n0:id) 171:#177   Type:(NAMED_UNIT,SI_UNIT,SOLID_ANGLE_UNIT)
Count of Parameters is not 2 for si_unit
Parameter n0.1 (dimensions) not Derived
Check:4 -- Entity (n0:id) 804:#821   Type:(LENGTH_UNIT,NAMED_UNIT,SI_UNIT)
Complex Record n0.1235, member type LENGTH_UNIT not in alphabetic order
Parameter n0.1 (dimensions) not Derived
Complex Record n0.1235, member type SI_UNIT not in alphabetic order
 

Attachments

  • R00-251467-B.stp
    69.5 KB · Views: 1
  • TA1K4303F.stp
    132.8 KB · Views: 1
  • un045831A-00Rev--1.stp
    80.5 KB · Views: 1

viter.alex

Looking around for some CAD
Elaborate such variant.
Python:
def get_shape_info(path: Path) -> dict:
    name = path.name
    path = str(path)
    shp = read_step_file(path)
    t = TopologyExplorer(shp)
    prop = GProp_GProps()
    brepgprop_VolumeProperties(shp, prop)
    volume = prop.Mass()
    brepgprop_SurfaceProperties(shp, prop)
    surface = prop.Mass()
    return {"name": name,
            "fullPath": path,
            "volume": round(volume, 4),
            "surface": round(surface, 4),
            "facesCount": len(set(t.faces()))}
 
Top