pythonocc-core icon indicating copy to clipboard operation
pythonocc-core copied to clipboard

Extracting length, breadth and height from any given STEP file

Open Sathvick11 opened this issue 3 years ago • 1 comments

Hello, I want an algorithm or a function in Python OCC wherein you can easily find length ,breadth and height of any given STEP file. I'm currently working on it and am a beginner to this package and I would like to hear advice from you. Thanks in Advance.

Sathvick11 avatar Nov 28 '22 07:11 Sathvick11

hi sarhvick,

from OCC.Extend import TopologyUtils from OCC.Extend.DataExchange import read_step_file from itertools import combinations from OCC.Core.ShapeAnalysis import ShapeAnalysis_Edge from OCC.Core.BRep import BRep_Tool from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere from OCC.Core.gp import gp_Pnt from OCC.Core.TopAbs import TopAbs_VERTEX from OCC.Core.TopoDS import topods_Vertex from OCC.Core.TopExp import TopExp_Explorer from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCylinder from OCC.Core.Bnd import Bnd_Box from OCC.Core.gp import gp_Pnt from OCC.Core.BRepBndLib import brepbndlib_Add from OCC.Display.OCCViewer import rgb_color from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display()

file = "DENEME.stp" shp = read_step_file(file)

TOL = 1e-4

shape = read_iges_file("robot_arm.igs")

tol = TOL # tol = TOL (by default) bbox = Bnd_Box() bbox.SetGap(tol)

mesh = BRepMesh_IncrementalMesh(shp, tol, True) mesh.Perform()

this is adds +margin but is faster

brepbndlib_Add(shp, bbox, True)

XMin, YMin, ZMin, XMax, YMax, ZMax = bbox.Get() xmin = XMin xmax = XMax xlen = XMax - XMin ymin = YMin ymax = YMax ylen = YMax - YMin zmin = ZMin zmax = ZMax zlen = ZMax - ZMin print(xmax) print(ymax) print(zmax) center = gp_Pnt((XMax + XMin) / 2, (YMax + YMin) / 2, (ZMax + ZMin) / 2)

box = BRepPrimAPI_MakeBox(gp_Pnt(xmin,ymin,zmin),gp_Pnt(xmax,ymax,zmax)).Shape()

display.DisplayShape(shp) exp_solids = TopologyUtils.TopologyExplorer(shp) display.DisplayShape(box,update=True,color=rgb_color(0,0,0.1),transparency=1)

start_display()

SelmanBozkurt avatar Dec 31 '22 10:12 SelmanBozkurt