Traversing the Entire B-Rep of a STEP file

Need help, or want to share a macro? Post here!
Post Reply
mntruell
Posts: 8
Joined: Mon Jun 27, 2022 2:16 am

Traversing the Entire B-Rep of a STEP file

Post by mntruell »

Given an imported B-Rep, how can I do the following with the FreeCAD Python API:

1) Enumerate all Shells, Faces, Wires, Edges, and Vertices
2) Get the parametric description of each Shell/Face/Wire/Edge/Vertex
3) Get the adjacency info of each (i.e. how can I know which Faces are connected to which Wires)
User avatar
Chris_G
Veteran
Posts: 2139
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Traversing the Entire B-Rep of a STEP file

Post by Chris_G »

mntruell wrote: Wed Jun 29, 2022 1:18 am 1) Enumerate all Shells, Faces, Wires, Edges, and Vertices

Code: Select all

def info_subshapes(shape):
    """Print the list of subshapes of a shape.
    info_subshapes(my_shape)
    """
    sh = ["Solids",
          "Compounds",
          "CompSolids",
          "Shells",
          "Faces",
          "Wires",
          "Edges",
          "Vertexes"]
    print("-> Content of {}".format(shape.ShapeType))
    for s in sh:
        subs = shape.__getattribute__(s)
        if subs:
            if (len(subs) == 1) and (subs[0].isEqual(shape)):
                pass  # hide self
            else:
                print("{}: {}".format(s, len(subs)))

mntruell
Posts: 8
Joined: Mon Jun 27, 2022 2:16 am

Re: Traversing the Entire B-Rep of a STEP file

Post by mntruell »

How do I get a parametric description of each Face or Edge?
User avatar
Chris_G
Veteran
Posts: 2139
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Traversing the Entire B-Rep of a STEP file

Post by Chris_G »

What do you call parametric description ?
An Edge is the bounded portion of a geometric curve (Edge.Curve) between 2 parameters (Edge.FirstParameter, Edge.LastParameter).
A Face is a portion of a geometric surface (Face.Surface) bounded by wires (Face.Wires).
Each Wire is made of Edges (Wire.Edges) and the 2D parametric representation of such an edge is obtained by :

Code: Select all

curve2d, firstpar, lastpar = the_face.curveOnSurface(the_edge)
Post Reply