Spaces:
Build error
Build error
File size: 1,628 Bytes
ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 f08bcf5 8134dc8 38cc103 8134dc8 ed199a0 38cc103 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 8134dc8 ed199a0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import os
import gradio as gr
import FreeCAD
import Part
def generate_apdl_from_freecad(freecad_file_path):
"""
Generate an APDL script from a FreeCAD file.
Parameters:
freecad_file_path: Path to the FreeCAD file (.FCStd).
Returns:
Path to the generated APDL script.
"""
# Open the FreeCAD file
doc = FreeCAD.openDocument(freecad_file_path)
obj = doc.Objects[0] # Assuming a single object in the file
# Extract bounding box dimensions
bbox = obj.Shape.BoundBox
length = bbox.XLength
width = bbox.YLength
height = bbox.ZLength
# Generate APDL script
apdl_script = f"""
/prep7
block, 0, {length:.4f}, 0, {width:.4f}, 0, {height:.4f}
/mesh
esize, 10
vmesh, all
allsel, all
/solu
antype, static
d, 1, ux, 0
d, 1, uy, 0
d, 1, uz, 0
f, 2, fy, -1000
solve
/exit
"""
apdl_path = "/tmp/generated_apdl.txt"
with open(apdl_path, "w") as f:
f.write(apdl_script)
# Close the FreeCAD document
FreeCAD.closeDocument(doc.Name)
return apdl_path
def process_freecad_file(freecad_file):
"""
Process the FreeCAD file and generate an APDL script.
Parameters:
freecad_file: Uploaded FreeCAD file (.FCStd).
Returns:
Path to the generated APDL script.
"""
apdl_script_path = generate_apdl_from_freecad(freecad_file.name)
return apdl_script_path
# Gradio Interface
app = gr.Interface(
fn=process_freecad_file,
inputs=gr.File(label="Upload FreeCAD File (.FCStd)"),
outputs=gr.File(label="Download Generated APDL Script"),
live=True,
)
if __name__ == "__main__":
app.launch()
|