Hii…I am getting one inp file as a output of beso code which contain fem mesh.I want to convert that fem mesh to normal mesh using FemMesh2mesh method.Manually in freecad i am able to do but from the python script I am getting error for file opening also.Here attaching the python script .
import FreeCAD as App
import Mesh
def export_inp_to_stl(inp_file_path, stl_file_path):
try:
doc = App.newDocument()
# Import the INP file directly into the document
doc.import_inp(inp_file_path)
# Step 2: Find the FEM mesh object (assuming only one exists in the document)
fem_mesh_object = None
for obj in App.ActiveDocument.Objects:
if 'Fem::FemMeshObject' in obj.PropertiesList:
fem_mesh_object = obj
break
if fem_mesh_object is None:
raise Exception("No FEM mesh object found in the document.")
# Create a Mesh object using femmesh2mesh
mesh_obj = doc.addObject("Mesh::Feature", "Mesh")
mesh_obj.Mesh = fem_mesh.Mesh
# Export the Mesh object to STL
Mesh.export([mesh_obj], stl_file_path) # This assumes you want to export the entire mesh
print(f"Export successful. STL file saved as {stl_file_path}")
except Exception as e:
print(f"Error during export: {e}")
Example usage:
inp_file_path = r"D:\file080_state1.inp"
stl_file_path = r"C:\Users\Supriya Chaugule\Downloads\Inp.stl"
export_inp_to_stl(inp_file_path, stl_file_path)