How to access edge dimensions in pythonocc?

1k views Asked by At

I'm trying to use PythonOCC to read in wireframe data (see this link) that is in IGES or STEP format, for eventual use in building a FE beam-element model.

Where in PythonOCC can I actually extract properties about edges and curves? I've built this sample that prints out all vertices in a file:

from OCC.Extend.DataExchange import read_iges_file
from OCC.Core.TopExp import (TopExp_Explorer,
                        topexp_MapShapesAndAncestors,
                        topexp_FirstVertex,
                        topexp_LastVertex)
from OCC.Core.TopAbs import *
from OCC.Core.TopoDS import TopoDS_Shape, topods
from OCC.Core.BRep import BRep_Tool, BRep_Tool_Pnt, BRep_Tool_IsGeometric, BRep_Tool_Parameter, BRep_Tool_Curve
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve
from OCC.Core.GeomTools import GeomTools_CurveSet

shape = read_iges_file('tubes.iges')

topExp = TopExp_Explorer()
topExp.Init(shape, TopAbs_EDGE)

def print_vertex(va):
    print(BRep_Tool().Pnt(va).Coord(1), BRep_Tool().Pnt(va).Coord(2), BRep_Tool().Pnt(va).Coord(3))

while topExp.More():
    edge = topExp.Current()
    first, last = topexp_FirstVertex(edge), topexp_LastVertex(edge)
    curv = BRepAdaptor_Curve(edge).Curve()
    print_vertex(first)
    print_vertex(last)
    
    topExp.Next()
    print()

That said, what I really want is to know if a curve is a line versus an arc, and if it's an arc, what the centerpoint and radius are.

1

There are 1 answers

0
Tiberio On

I am trying to do something similar. If this can be useful, I am using the following snippet to get the type of a Curve and then extracting vertices:

    # given and Edge edge
    curv = BRepAdaptor_Curve(edge).Curve()
    a = 0.0
    b = 0.0
    [curve_handle, a, b] = OCC.BRep.BRep_Tool.Curve(edge)
    print(curve_handle.GetObject().DynamicType().GetObject().Name())
    initial_point = OCC.gp.gp_Pnt()
    final_point = OCC.gp.gp_Pnt()
    
    curve_handle.GetObject().D0(a, initial_point)
    curve_handle.GetObject().D0(b, final_point)
    
    print(f'init: ({initial_point.X()}, {initial_point.Y()}), end ({final_point.X()}, {final_point.Y()})')