Example #1
0
def process_stl(stl_filename, fmt2, fname2, data=None):
    """
    Converts STL to Nastran/Cart3d
    """
    assert fmt2 in ['stl', 'nastran', 'cart3d'], 'format2=%s' % fmt2
    if '*' in stl_filename:
        stl_filenames = glob.glob(stl_filename)
    else:
        stl_filenames = [stl_filename]
    assert len(stl_filenames) > 0, stl_filenames
    from pyNastran.converters.stl.utils import merge_stl_files

    model = merge_stl_files(stl_filenames, stl_out_filename=None)
    scale = data['--scale']
    if scale is not None:
        assert isinstance(scale, float), 'scale=%r type=%r' % (scale, type(scale))
        model.nodes *= scale

    # model = STL()
    # model.read_stl(stl_filename)
    if fmt2 == 'nastran':
        from pyNastran.converters.stl.stl_to_nastran import stl_to_nastran
        stl_to_nastran(model, fname2)
    elif fmt2 == 'cart3d':
        from pyNastran.converters.stl.stl_to_cart3d import stl_to_cart3d
        stl_to_cart3d(model, fname2)
    elif fmt2 == 'stl':
        is_binary = data['--binary']
        model.write_stl(fname2, is_binary=is_binary, float_fmt='%6.12f', stop_on_failure=False)
    # elif fmt2 == 'tecplot':
        # stl_to_tecplot(model, fname2)
    # elif fmt2 == 'ugrid':
        # stl_to_ugrid(model, fname2)
    else:
        raise NotImplementedError(fmt2)
Example #2
0
 def test_stl_to_cart3d_01(self):
     log = get_logger(level='warning')
     stl_filename = os.path.join(TEST_PATH, 'sphere.stl')
     cart3d_filename = os.path.join(TEST_PATH, 'sphere.tri')
     unused_model = stl_to_cart3d(stl_filename,
                                  cart3d_filename=None,
                                  log=log)
     argv = [
         'format_converter', 'stl', stl_filename, 'cart3d', cart3d_filename
     ]
     cmd_line_format_converter(argv=argv, quiet=True)
     os.remove(cart3d_filename)
Example #3
0
def process_stl(stl_filename, fmt2, fname2, data=None):
    """
    Converts STL to Nastran/Cart3d
    """
    assert fmt2 in ['stl', 'nastran', 'cart3d'], 'format2=%s' % fmt2
    if '*' in stl_filename:
        stl_filenames = glob.glob(stl_filename)
    else:
        stl_filenames = [stl_filename]
    assert len(stl_filenames) > 0, stl_filenames
    model = merge_stl_files(stl_filenames, stl_out_filename=None)
    scale = data['--scale']
    if scale is not None:
        assert isinstance(scale, float), 'scale=%r type=%r' % (scale, type(scale))
        model.nodes *= scale

    # model = STL()
    # model.read_stl(stl_filename)
    if fmt2 == 'nastran':
        stl_to_nastran(model, fname2)
    elif fmt2 == 'cart3d':
        # we don't have an STL -> Cart3d, so we:
        #    - STL -> BDF
        #    - BDF -> Cart3D
        stl_to_cart3d(model, fname2)
        #stl_to_nastran(stl_filename, fname2 + '.bdf')
        #stl_to_cart3d_filename(fname2 + '.bdf', fname2)
    elif fmt2 == 'stl':
        is_binary = data['--binary']
        model.write_stl(fname2, is_binary=is_binary, float_fmt='%6.12f', stop_on_failure=False)
    # elif fmt2 == 'tecplot':
        # stl_to_tecplot(model, fname2)
    # elif fmt2 == 'ugrid':
        # stl_to_ugrid(model, fname2)
    else:
        raise NotImplementedError(fmt2)
Example #4
0
 def test_stl_to_cart3d_01(self):
     log = get_logger(level='warning')
     stl_filename = os.path.join(TEST_PATH, 'sphere.stl')
     cart3d_filename = os.path.join(TEST_PATH, 'sphere.tri')
     stl_to_cart3d(stl_filename, cart3d_filename, log=log)
     os.remove(cart3d_filename)
Example #5
0
 def test_stl_to_cart3d_01(self):
     stl_filename = os.path.join(test_path, 'sphere.stl')
     cart3d_filename = os.path.join(test_path, 'sphere.tri')
     stl_to_cart3d(stl_filename, cart3d_filename)
     os.remove(cart3d_filename)
Example #6
0
 def test_stl_to_cart3d_01(self):
     stl_filename = os.path.join(test_path, 'sphere.stl')
     cart3d_filename = os.path.join(test_path, 'sphere.tri')
     stl_to_cart3d(stl_filename, cart3d_filename)
     os.remove(cart3d_filename)