def stl_export(fn,F,header="Created by stl_examples.py"): """Export an stl model stored in Formex F in Abaqus .inp format.""" message("Creating nodes and elements. This may take some time!") GD.app.processEvents() nodes,elems = F.nodesAndElements() nnodes = nodes.shape[0] nelems = elems.shape[0] message("There are %d unique nodes and %d triangle elements in the model." % (nnodes,nelems)) stl_abq.abq_export(fn,nodes,elems,'S3',header)
def export_volume(): if PF['volume'] is None: return types = [ "Abaqus INP files (*.inp)" ] fn = askFilename(GD.cfg['workdir'],types,exist=False) if fn: print "Exporting volume model to %s" % fn updateGUI() nodes,elems = PF['volume'] stl_abq.abq_export(fn,nodes,elems,'C3D%d' % elems.shape[1],"Abaqus model generated by tetgen from surface in STL file %s.stl" % PF['project'])
def export_surface(): if PF['surface'] is None: return types = [ "Abaqus INP files (*.inp)" ] fn = askFilename(GD.cfg['workdir'],types,exist=False) if fn: print "Exporting surface model to %s" % fn updateGUI() nodes,elems = PF['surface'] stl_abq.abq_export(fn,nodes,elems,'S3',"Abaqus model generated by pyFormex from input file %s" % os.path.basename(fn))
def export_stl(): """Export an stl model stored in Formex F in Abaqus .inp format.""" global project,F if ack("Creating nodes and elements.\nFor a large model, this could take quite some time!"): GD.app.processEvents() GD.message("Creating nodes and elements.") nodes,elems = F.feModel() nnodes = nodes.shape[0] nelems = elems.shape[0] GD.message("There are %d unique nodes and %d triangle elements in the model." % (nnodes,nelems)) stl_abq.abq_export(project+'.inp',nodes,elems,'S3',"Created by stl_examples.py")
def export_tetgen_volume(): global nodes,elems updateGUI() if elems is not None: print "Exporting volume model" stl_abq.abq_export('%s-volume.inp' % project,nodes,elems,'C3D%d' % elems.shape[1],"Abaqus model generated by tetgen from surface in STL file %s.stl" % project)
def export_tetgen_surface(): global nodes,surf updateGUI() if surf is not None: print "Exporting surface model" stl_abq.abq_export('%s-surface.inp' % project,nodes,surf,'S3',"Abaqus model generated by tetgen from surface in STL file %s.stl" % project)
fn = askFilename(".","Stl files (*.stl)") if not fn: exit() F = stl_import(fn) bn = os.path.splitext(fn)[0] if ack("Shall I export this in Abaqus .inp format (SLOW!)?"): stl_export(bn+'.inp',F,"Abaqus model converted from STL file %s" % fn) if ack("Shall I create a tetraeder mesh inside the surface?"): stl_tetgen(fn) if ack("Shall I read the generated mesh?"): nodes,elems,surf = read_tetgen(bn+'.1') # tetgen add extra '.1' volume = Formex(nodes[elems-1]) surface = Formex(nodes[surf-1]) clear() if ack("Shall I show the surface mesh (triangles)?"): draw(surface) if ack("Shall I show the volume mesh (tetraeders)?"): draw(volume,eltype='tet',color='random') if ack("Shall I export the surface mesh in Abaqus .inp format?"): stl_abq.abq_export(bn+'-surface.inp',nodes,surf,'S3',"Abaqus model generated by tetgen from surface in STL file %s" % fn) if ack("Shall I export the volume mesh in Abaqus .inp format?"): stl_abq.abq_export(bn+'volume.inp',nodes,elems,'C3D%d' % elems.shape[1],"Abaqus model generated by tetgen from surface in STL file %s" % fn) # End