File size: 3,238 Bytes
59e2ead
 
09b2e7e
59e2ead
 
 
 
 
 
 
 
09b2e7e
 
 
 
 
 
 
 
 
 
 
 
59e2ead
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09b2e7e
59e2ead
 
 
 
 
 
 
 
09b2e7e
 
59e2ead
09b2e7e
 
59e2ead
 
 
 
09b2e7e
59e2ead
 
09b2e7e
 
 
 
59e2ead
 
 
09b2e7e
 
59e2ead
09b2e7e
 
59e2ead
 
 
 
 
09b2e7e
 
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
74
75
76
77
78
79
80
81
82
from flask import Flask, request, jsonify
import subprocess
import sys
import os

app = Flask(__name__)

# Path to Fusion 360 script directory
SCRIPT_PATH = 'path_to_your_fusion_360_scripts_folder'  # Change this to your actual script path
OUTPUT_PATH = 'output'

# Function to install platform-specific dependencies
def install_platform_specific_dependencies():
    if sys.platform == "win32":  # Windows-specific dependencies
        try:
            subprocess.check_call([sys.executable, "-m", "pip", "install", "pywin32==303"])
            print("Successfully installed pywin32 on Windows.")
        except subprocess.CalledProcessError as e:
            print(f"Error installing pywin32: {e}")
    else:
        print("Skipping pywin32 installation for non-Windows platform.")

# Endpoint to generate Fusion 360 3D model
@app.route('/generate_model', methods=['POST'])
def generate_model():
    try:
        # Get the parameters from the request
        data = request.json
        length = data.get('length', 100.0)
        width = data.get('width', 50.0)
        height = data.get('height', 10.0)

        # Generate the Fusion 360 model using the script
        result = generate_fusion_360_model(length, width, height)

        # If model generation is successful, return success
        return jsonify({"status": "success", "message": result, "output_path": OUTPUT_PATH}), 200

    except Exception as e:
        return jsonify({"status": "error", "message": str(e)}), 500

# Endpoint to generate toolpath for CNC
@app.route('/generate_toolpath', methods=['POST'])
def generate_toolpath():
    try:
        # Get the parameters from the request (toolpath generation settings, etc.)
        data = request.json
        tool_diameter = data.get('tool_diameter', 10.0)
        feed_rate = data.get('feed_rate', 100.0)

        # Generate toolpath G-code using Fusion 360 API
        result = generate_cnc_toolpath(tool_diameter, feed_rate)

        # If successful, return success message and path to toolpath
        return jsonify({"status": "success", "message": result, "output_path": OUTPUT_PATH}), 200

    except Exception as e:
        return jsonify({"status": "error", "message": str(e)}), 500

# Function to generate Fusion 360 model (example)
def generate_fusion_360_model(length, width, height):
    try:
        # Fusion 360 API calls here to create model
        # Assuming you will add your Fusion 360 Python script logic here
        print(f"Creating model with dimensions: {length}x{width}x{height}")
        return "Model created successfully"
    except Exception as e:
        return f"Error creating model: {str(e)}"

# Function to generate CNC toolpath
def generate_cnc_toolpath(tool_diameter, feed_rate):
    try:
        # Example logic for generating CNC toolpath (this can be enhanced)
        print(f"Generating CNC toolpath with tool diameter: {tool_diameter} and feed rate: {feed_rate}")
        return "Toolpath generated successfully"
    except Exception as e:
        return f"Error generating toolpath: {str(e)}"

if __name__ == '__main__':
    install_platform_specific_dependencies()  # Call the function to handle platform-specific installs
    app.run(debug=True, host='0.0.0.0', port=5000)