How to get control points/ knots information from STEP file


I am new to OPEN CASCADE and facing a problem related to accessing the control points, knot, vertex etc.

I am able to import the STEP file in python using pythonocc package but not able to access the above mentioned details of the curve. It is a B_SPLINE_CURVE_WITH_KNOTS.

The object imported gets translated into  TopoDS_Shape using step_reader.Shape() method but accessing its details is the main aim of my work. 

I also appreciate the solution in C++ or any other programming language.

My python code to import the STEP file is as follows: 

from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity,IFSelect_CountByItem, IFSelect_ListByItem
from OCC.Core.TopAbs import TopAbs_EDGE

step_reader = STEPControl_Reader()
status = step_reader.ReadFile('D:/Python projtcts/2D-Spline_STEP214.stp')

if status == IFSelect_RetDone:  # check status
    failsonly = False
    step_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
    step_reader.PrintCheckLoad(failsonly, IFSelect_CountByItem)
    step_reader.PrintCheckLoad(failsonly, IFSelect_ListByItem)
    step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)

    ok = step_reader.TransferRoot(1)
    _nbs = step_reader.NbShapes()
    aResShape = step_reader.Shape(1)

    print("Error: can't read file.")

n = step_reader.NbRootsForTransfer()
m = step_reader.TransferRoot()
Benjamin Bihler's picture

Have a look at TopExp_Explorer. It lets you iterate over your shape's subshapes.


anirudha.vyasamudra_155866's picture

Hello Benjamin,

My design is just a 2D-Spline, so there are no subshapes. I am attaching the step file and the resulting output/image from the code. I just want the details of this curve such as vertex, control points, knots. So I don't know how will  TopExp_Explore will help me with my task. Can you just a reply with a part of or a dummy code needed to extract any information from this step file. 

Benjamin Bihler's picture

Even though you consider your geometry as one shape, the topology may be represented in a different way (you might want to check the articles "Topology and Geometry in Open CASCADE" of the blog "Open CASCADE Notes"). For example the vertices of your spline are the start and stop point.

In C++ you could try the following:

   TopoDS_Shape twoDSplineStep214 = ...
    for (TopExp_Explorer edgeExplorer(twoDSplineStep214, TopAbs_EDGE);
        double first, last;
        Handle(Geom_Curve) myCurve = BRep_Tool::Curve(
                TopoDS::Edge(edgeExplorer.Value()), first, last);

        Handle(Geom_BSplineCurve) spline = Handle(Geom_BSplineCurve)::DownCast(myCurve);

        std::cout << "First knot: " << spline->Knot(1) << std::endl;