Skip to content

Trying to export STL file in python demos  #912

Description

@JinZjt

Hello Sir,
I am learning the python demos,especially the jupyter notebook. When I get the wing surface in Geom_bSplineSurface type, how can I export it to STL format file? Looking forward to your reply.

Activity

  1. joergbrech commented on Jul 18, 2022

    @joergbrech
    Contributor

    Thanks for opening an issue here! I will move this issue to the discussion board if you don't mind.

    I think this demo could help you along: https://github.com/rainman110/tigl-workshop/blob/master/Exercises/solutions/Exercise1_Basics_Solution.ipynb.

    Basically, you would use pythonocc to create a TopoDS_Face from your Geom_BSplineSurface. Then you can pass this face to a CNamedShape. The latter is a tigl class that can be added to an exporter:

    from tigl3 import curve_factories as cf
    from tigl3 import surface_factories as sf
    from tigl3.exports import create_exporter
    
    from tigl3.geometry import CNamedShape
    from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeFace
    
    # list of points on NACA2412 profile
    px = [1.000084, 0.975825, 0.905287, 0.795069, 0.655665, 0.500588, 0.34468, 0.203313, 0.091996, 0.022051, 0.0, 0.026892, 0.098987, 0.208902, 0.346303, 0.499412, 0.653352, 0.792716, 0.90373, 0.975232, 0.999916]
    py = [0.001257, 0.006231, 0.019752, 0.03826, 0.057302, 0.072381, 0.079198, 0.072947, 0.054325, 0.028152, 0.0, -0.023408, -0.037507, -0.042346, -0.039941, -0.033493, -0.0245, -0.015499, -0.008033, -0.003035, -0.001257]
    
    # lists of coordinates for 2 curves
    points1 = []
    points2 = []
    for x, y in zip(px, py):
        points1.append([x*100, y*100, 0])
        points2.append([x*100, y*100, 500])
    
    curve1 = cf.interpolate_points(points1)
    curve2 = cf.interpolate_points(points2)
    surface = sf.interpolate_curves([curve1, curve2])
    
    face = BRepBuilderAPI_MakeFace(surface, 1e-6).Face()
    named_face = CNamedShape(face, "myface")
    
    stl_exporter = create_exporter("stl")
    stl_exporter.add_shape(named_face)
    stl_exporter.write("test.stl")
  2. locked and limited conversation to collaborators on Jul 18, 2022
  3. converted this issue into a discussion #913 on Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions