コード例 #1
0
def read_stl(fn=None):
    """Read STL model from file fn.

    If no file is given, one is asked.
    The file fn should exist and contain a valid STL model.
    The STL model is stored in the Formex F.
    The workdir and project name are set from the filename.
    The Formex is stored under the project basename.
    The model is displayed.
    """
    global project,F
    if fn is None:
        fn = askFilename(GD.cfg['workdir'],"Stl files (*.stl)")
        if fn:
            clear()
            linewidth(1)
        else:
            return
    os.chdir(os.path.dirname(fn))
    message("Your current workdir is %s" % os.getcwd())
    project = os.path.splitext(fn)[0]
    message("Reading file %s" % fn)
    F = Formex(stl.read_ascii(fn))
    name = os.path.basename(project)
    projectLabel.setText(name)
    Globals().update({name:F})
    message("STL model %s has %d triangles" % (name,F.f.shape[0]))
    message("The bounding box is\n%s" % F.bbox())
    show_stl()
コード例 #2
0
def stl_import(fn):
    """Read and display an stl model from ascii file fn.
    
    Returns the model in a Formex.
    """
    message("Processing file %s" % fn)
    F = Formex(stl.read_ascii(fn))
    draw(F,color='green')
    message("There are %d triangles in the model" % F.f.shape[0])
    message("The bounding box is\n%s" % F.bbox())
    return F