标签:AutoCAD NetApi blkRef c# pline AccoreConsole Autodesk GeometricExtents using
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文件
标签:AutoCAD,NetApi,blkRef,c#,pline,AccoreConsole,Autodesk,GeometricExtents,using 来源: https://www.cnblogs.com/NanShengBlogs/p/10957489.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。