首页 > Windows开发 > 详细

AutoCAD2013 以上利用AccoreConsole+ c# NetApi 批量处理图纸

时间:2019-05-31 22:13:12      阅读:202      评论:0      收藏:0      [点我收藏+]

1# 先写个cmd脚本调用AccoreConsole

1 set acadPath="C:\Program Files\Autodesk\AutoCAD 2019\"
2 
3 %acadPath%accoreconsole.exe /i %~dp0Drawing1.dwg /s %~dp0NetCmd.scr
4 
5 @pause

多个dwg文件执行需要改成如下

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

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

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

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

skd的dll只能引用这三个

技术分享图片

 

 1 using AcApp = Autodesk.AutoCAD.ApplicationServices;
 2 using Autodesk.AutoCAD.Runtime;
 3 using System;
 4 using System.Collections.Generic;
 5 using System.Linq;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 using Autodesk.AutoCAD.DatabaseServices;
 9 using Autodesk.AutoCAD.ApplicationServices;
10 using Autodesk.AutoCAD.Geometry;
11 namespace ShopDrawing
12 {
13     public class AccoreCmd
14     {
15         [CommandMethod("myNetcmd")]
16         public void MyPlotModelSpace()
17         {
18             var doc = AcApp.Application.DocumentManager.MdiActiveDocument;
19             var db = HostApplicationServices.WorkingDatabase;
20             var ed = doc.Editor;
21             //转化成世界坐标系
22             if (ed.CurrentUserCoordinateSystem != Matrix3d.Identity) ed.CurrentUserCoordinateSystem = Matrix3d.Identity;
23             using (Transaction trans = db.TransactionManager.StartTransaction())
24             {
25                 BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
26                 BlockTableRecord ms = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
27                 //获取块的边界范围
28                 foreach (ObjectId oid in ms)
29                 {
30                     Entity ent = trans.GetObject(oid, OpenMode.ForRead) as Entity;
31                     if (ent != null && ent.GetType().Name == typeof(BlockReference).Name)
32                     {
33                         BlockReference blkRef = ent as BlockReference;
34                         Polyline pline = new Polyline();
35                         pline.AddVertexAt(0, new Point2d(blkRef.GeometricExtents.MaxPoint.X, blkRef.GeometricExtents.MaxPoint.Y), 0, 0, 0);
36                         pline.AddVertexAt(0, new Point2d(blkRef.GeometricExtents.MinPoint.X, blkRef.GeometricExtents.MaxPoint.Y), 0, 0, 0);
37                         pline.AddVertexAt(0, new Point2d(blkRef.GeometricExtents.MinPoint.X, blkRef.GeometricExtents.MinPoint.Y), 0, 0, 0);
38                         pline.AddVertexAt(0, new Point2d(blkRef.GeometricExtents.MaxPoint.X, blkRef.GeometricExtents.MinPoint.Y), 0, 0, 0);
39                         pline.AddVertexAt(0, new Point2d(blkRef.GeometricExtents.MaxPoint.X, blkRef.GeometricExtents.MaxPoint.Y), 0, 0, 0);
40                         ms.AppendEntity(pline);
41                         trans.AddNewlyCreatedDBObject(pline, true);
42                         //
43                     }
44                 }
45                 trans.Commit();
46             }
47         }
48     }
49 }

技术分享图片

 4# 执行结果如下,双击bat文件

 

技术分享图片

 

 

技术分享图片

AutoCAD2013 以上利用AccoreConsole+ c# NetApi 批量处理图纸

原文:https://www.cnblogs.com/NanShengBlogs/p/10957489.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!