明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 398|回复: 0

[CAD梦想画图] 梦想云图Node.JS服务 ( 最近更新时间:2022-12-30 10:04:50 )

[复制链接]
发表于 2022-12-30 16:15 | 显示全部楼层 |阅读模式
本帖最后由 MxDraw 于 2023-1-3 15:27 编辑

说明
后台提供梦想Node.JS服务,方便调用控件后台功能,Windows服务程序所在目录:Bin\MxDrawServer\Windows,Linux服务程序所在目录:Bin\Linux\MxDrawServer




启动服务
Windows:进入Bin\MxDrawServer\Windows目录,运行start.bat启动服务,如下图:
Linux: 进入Bin\Linux\MxDrawServer,

执行如下命令,增加文件的执行权限
  1. su root
  2. chmod -R 777 *
复制代码

运行: ./node app.js 启动服务

服务启动后,默认会在1337端口监听,目录下有个ini.js文件,编辑该文件,配置服务参数,如下图:

服务使用
A.上传文件,DWG文件格式转换
服务接口说明:
直接调用POST对服务器上的文件进行转换:
服务接口说明:
*  POST users { cmd: "convert", file: "O:/1.dwg" }
*  file:  需要转的cad文件路径

如下代码:
  1. $.ajax({
  2.             url: 'http://localhost:1337/users',
  3.             data: { cmd: "convert", file: "O:/1.dwg" },
  4.             method: 'post'
  5.         }).success(function (res) {
  6.             console.log(res);
  7.         })
复制代码

前端上传文件转换如下:
POST convert file;file是<input id="input" type="file"> 选择的文件.
该接口后台源码在Bin\MxDrawNode\MxDrawNode\src\mxconvert\MxConvert.ts 中的CadToMx
参考例子:Bin\MxDrawServer\Test\sample.html
代码如下:
默认文件转换后存放位置如下图:
B. 保存批注到DWG文件
服务接口说明:
*  POST savecomment {filename:保存到的DWG文件;savefile :保存后的dwg, userConvertPath:false}
*  userConvertPath: 默认值是false,把当前图上的批注内容保存到指定的dwg文件中
*  filename: 是个相对路径,默认是相对于后台程序所在目录Bin\Release(windows),Bin\Linux\Bin(linux)
*  如果userConvertPath为接true,相对于Bin\Release\ini.json [linux:Bin\Linux\Bin\ini.json] 中的nodeConvert.path设置值
*  savefile: 也是个相对路径,同filename。该接口后台源码在Bin\MxDrawNode\MxDrawNode\src\mxconvert\SaveCommentToDwg.ts 中的SaveCommentToDWG.do

参考例子:SRC\sample\Browse\VueBrowse,代码如下:
demo运行后,点击“保存到DWG文件”,查看接口调用效果:
C. 得到到DWG文件中信息
参考例子: Bin\MxDrawServer\Test\sample.html
服务接口说明:
POST users {cmd:"getcaddata",cadfile:"1.dwg",outfile:"1.dwg.json"}

代码如下:
  1.    function TestPost(){
  2.         $.ajax({
  3.             url:'http://localhost:1337/users',
  4.             data:{cmd:"getcaddata",cadfile:"1.dwg",outfile:"1.dwg.json"},
  5.             method:'post'
  6.         }).success(function (res){
  7.             console.log(res);
  8.     })
  9.   }
复制代码

getcaddata的实现,参见“梦想控件2-后台读写CAD文件.doc”执行结果如下:


D.  DWG文件转成PDF
参考例子: Bin\MxDrawServer\Test\sample.html
服务接口说明:
POST tools { cmd: "cadtopdf", param: "file=O:/1.dwg" },

代码如下:
  1.     $.ajax({
  2.             url: 'http://localhost:1337/users/tools',
  3.             data: { cmd: "cadtopdf", param: "file=O:/1.dwg" },
  4.             method: 'post'
  5.         }).success(function (res) {
  6.             console.log(res);
  7.         })
复制代码


E.  DWG文件转成JPG
参考例子: Bin\MxDrawServer\Test\sample.html
服务接口说明:
POST tools { cmd: "cadtopdf", param: "file=O:/1.dwg" },

代码如下:
  1.     $.ajax({
  2.             url: 'http://localhost:1337/users/tools',
  3.             data: { cmd: "cadtojpg", param: "file=O:/1.dwg" },
  4.             method: 'post'
  5.         }).success(function (res) {
  6.             console.log(res);
  7.         })
复制代码



F.  对CAD图纸剪切,剪切输出pdf,dwg
参考例子: Bin\MxDrawServer\Test\sample.html
服务接口说明:
POST tools { cmd: "cutcad", param: "file=O:/hhhh.dwg out=O:/1.pdf lbx=60009.152793 lby=42457.503649 rtx=120145.567345 rty=85507.693766"},
out传的值扩展名是pdf输出pdf文件,是dwg时输出dwg
代码如下:
  1. $.ajax({
  2.             url: 'http://localhost:1337/users/tools',
  3.             data: { cmd: "cutcad", param: "file=O:/hhhh.dwg out=O:/1.pdf lbx=60009.152793 lby=42457.503649 rtx=120145.567345 rty=85507.693766"},
  4.             method: 'post'
  5.         }).success(function (res) {
  6.             console.log(res);
  7.         })
复制代码


G.  根据图框,折分pdf
参考例子: Bin\MxDrawServer\Test\sample.html
服务接口说明:
POST tools { cmd: "cadtopdf", file: "tk.dwg"},

调用 代码如下:
  1.      $.ajax({
  2.             url: 'http://localhost:1337/users',
  3.             data: { cmd: "cadtopdf", file: "O:/tk.dwg"},
  4.             method: 'post'
  5.         }).success(function (res) {
  6.             console.log(res);
  7.         })
复制代码


该功能的源码在:
Bin\MxDrawNode\MxDrawNode\src\mxconvert\CADToPDF.ts




您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-23 21:12 , Processed in 0.375239 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表