枫叶棋语 发表于 2023-2-26 12:51:18

Pycad 通过服务器调用CPython

CPython代码,运行Cpython,创建服务器


from flask import Flask, request
__author__ = 'fengyeqiyu'
__publisher__ = 'Pycad'
app = Flask(__name__)
@app.route('/add')
def add()://传入两个参数a,b
    a=request.args.get('a')
    b=request.args.get('b')
    return str(eval(a)+eval(b))
if __name__ == '__main__':
    app.run()


Pycad代码
# -*- coding: utf-8 -*
from pycad.runtime import *
from pycad.system import *
# clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Clipboard
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
from Autodesk.AutoCAD.EditorInput import *
from pycad.runtime.edx import *
import System
from System.Net import WebRequest
from System.IO import StreamReader
from System.Text import Encoding
@command()
def webdata(doc):
    __author__ = 'fengyeqiyu'
    __publisher__ = 'Pycad'
    url = r'http://127.0.0.1:5000/add?a=1&b=1'
    request = WebRequest.Create(url)
    response = request.GetResponse()
    result = StreamReader(response.GetResponseStream()).ReadToEnd()
    print(result)
运行结果返回2,现在的问题是如何在命令开启时自动运行Cpython,以及运行结束后关闭服务器,还请高人指点。



枫叶棋语 发表于 2023-2-26 12:55:13

还有一种可能,使用pythonnet运行
页: [1]
查看完整版本: Pycad 通过服务器调用CPython