AccoreConsole听起来有点拗口,其中文名可以叫做AutoCAD控制台或者无头AutoCAD。一句话概括,它是快速启动AutoCAD运行微环境,高效的处理图纸。你可以如同DOS命令行一样操作命令,处理图纸,而不需要打开AutoCAD。这在批处理大量图纸时非常有用。另外启动是不管有无license都可以正常操作,不占当前autoCAD的资源

安装AutoCAD后,在安装路径根目录下就可以看到这个可执行程序 AccoreConsole.exe


直入正题,Accoreconsole+scr+bat 纯命令只能单一机械的执行处理命令,今天笔者就结合C# AutoCAD NetApi 来探究下Accoreconsole的强大功能。。。。。。

1# 先写个cmd脚本调用AccoreConsole

%~dp0 代表当前脚本文件的文件夹路径,
/i 打开的图纸的全路径
/s 执行的scr文件的全路径
 set acadPath="C:\Program Files\Autodesk\AutoCAD 2019\"

 %acadPath%accoreconsole.exe /i %~dp0Drawing1.dwg /s %~dp0NetCmd.scr

 @pause

多个dwg文件执行需要改成如下,请根据AutoCAD的安装路径更改成对应的版本

 set acadPath="C:\Program Files\Autodesk\AutoCAD 2019\"
for %%i in (%~dp0*.dwg) do %acadPath%accoreconsole.exe /i %%i /s %~dp0NetCmd.scr @pause

2# 写个scr文件,命名为NetCmd.scr

netload "D:/MyProgrammingData/ShopDrawing/ShopDrawing/bin/Debug/ShopDrawing.dll"
(command "myNetcmd")
qsave
(setvar filedia 0)


secureload 0
cmdecho 0
netload "C:\Users\nslov\Desktop\Test\ShopDrawing.dll"
filedia 0
(if (= (getvar "WRITESTAT") 0) (Command "close"))
mySSsetTest
qsave


解释部分:secureload 0, 关闭dll加载提示
cmdecho 0 关闭回显

(if (= (getvar "WRITESTAT") 0) (Command "close"))

只读的话就执行退出,非只读才执行后面对应的命令

3# 编写c#代码,生成的dll为ShopDrawing.dll,注册cad命令“myNetcmd“

skd的dll只能引用这2个dll,AcDbMgd.dll,AcCoreMgd.dll

这2个dll都可以用,选择集经测试可以使用


 using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices.Core; namespace ShopDrawing
{
public class AccoreCmd
{
[CommandMethod("mySSsetTest")]
public void MyPlotModelSpace()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = HostApplicationServices.WorkingDatabase;
var ed = doc.Editor;
//转化成世界坐标系
if (ed.CurrentUserCoordinateSystem != Matrix3d.Identity) ed.CurrentUserCoordinateSystem = Matrix3d.Identity;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord ms = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
//获取块的边界范围
var psr = ed.SelectCrossingWindow(Point3d.Origin, new Point3d(, , ),
new Autodesk.AutoCAD.EditorInput.SelectionFilter(new TypedValue[] {
new TypedValue((int)DxfCode.Start, RXClass.GetClass(typeof(BlockReference)).DxfName)
}));
if (psr.Status == Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
{
foreach (SelectedObject item in psr.Value)
{
Entity ent = trans.GetObject(item.ObjectId, OpenMode.ForRead) as Entity;
if (ent != null)
{
BlockReference blkRef = ent as BlockReference;
if (blkRef.Name == "")
{
Polyline pline = new Polyline();
pline.AddVertexAt(, new Point2d(blkRef.GeometricExtents.MaxPoint.X, blkRef.GeometricExtents.MaxPoint.Y), , , );
pline.AddVertexAt(, new Point2d(blkRef.GeometricExtents.MinPoint.X, blkRef.GeometricExtents.MaxPoint.Y), , , );
pline.AddVertexAt(, new Point2d(blkRef.GeometricExtents.MinPoint.X, blkRef.GeometricExtents.MinPoint.Y), , , );
pline.AddVertexAt(, new Point2d(blkRef.GeometricExtents.MaxPoint.X, blkRef.GeometricExtents.MinPoint.Y), , , );
pline.AddVertexAt(, new Point2d(blkRef.GeometricExtents.MaxPoint.X, blkRef.GeometricExtents.MaxPoint.Y), , , );
ms.AppendEntity(pline);
trans.AddNewlyCreatedDBObject(pline, true);
}
}
}
trans.Commit();
}
else ed.WriteMessage("Can't Find Any Block");
}
}
}
}

4# 执行结果如下,双击bat文件执行如下,bat 文件和scr都要仔细调试,一步错步步错!!!

5# AutoCAD script脚本语法简介

  与cad命令行操作一样,命令行怎么输入,代码就怎写。。。

  1. 脚本文件空格作为命令或数据结束符来处理
  2. 脚本命令不要简写,以免歧义。
  3. 注释语法以分号表示。
  4. 最后一行必须为空行。
  5. 嵌入空格的长文件名用双引号括起来。 如open “my house”; 打开my house.dwg文件

最新文章

  1. 【Win10 UWP】微信SDK基本使用方法和基本原理
  2. SQL Server 查询性能优化 相关文章
  3. 使用Android Studio打Andorid apk包的流程
  4. Html 网页布局(一)
  5. EXT gridGroup
  6. Detecting diabetic retinopathy in eye images
  7. java第四课:数组
  8. RatingBar设置显示星星个数
  9. Android ANR、Force Closed(转)
  10. Speex Acoustic Echo Cancellation (AEC) 回声消除模块的使用
  11. PyCharm 安装指南
  12. ubuntu环境下docker安装步骤
  13. 【python】lambda创建匿名函数
  14. 小说接入UC浏览器内核技术对话(二)
  15. oracle 常用sql字符函数介绍
  16. Learning ROS for Robotics Programming Second Edition学习笔记(一) indigo v-rep
  17. Centos7 安装 scrapy
  18. ReentrantLock原理
  19. redis安全问题【原】
  20. spring cloud 注册、发现、消费、负载均衡

热门文章

  1. JPA中映射关系详细说明(一对多,多对一,一对一、多对多)、@JoinColumn、mappedBy说明
  2. 【spring boot 系列】spring data jpa 全面解析(实践 + 源码分析)
  3. msp430入门编程10
  4. 1sting 大数 递推
  5. [bzoj4131]并行博弈_博弈论
  6. CentOS系统下Hadoop、Hbase、Zookeeper安装配置
  7. [GraphQL] Query Local and Remote Data in Apollo Link State
  8. Mahout贝叶斯算法拓展篇3---分类无标签数据
  9. android 特殊符号开头的联系人归并至“#”下
  10. Creo二次开发—内存处理