AutoCAD.net

nuget 搜索autocad.net

System.InvalidProgramException异常错误

autocad.net通过组件方式访问autocad,所以需要和autocad通信,不能单独exe启动
参考:https://forums.autodesk.com/t5/forums/forumtopicprintpage/board-id/152/message-id/53529/print-single-message/false/page/1

表空间

  • Block Table(块表)
  • Layer Table(层表)
  • TextStyle Table(文字样式表)
  • DimStyle Table(尺寸样式表)
  • Linetype Table(线型表)
  • UCS Table(用户坐标系表)
  • View Table(视图表)
  • Viewport Table(视口表)
  • RegApp Table(应用程序注册表)
  • DrawOrderTable (绘图层级)

对应的访问方式:BlockTable、LayerTable、TextStyleTable、DimStyleTable…

autocad纤程

autocad使用纤程(用户模式下的线程,一个线程可包含多个纤程),纤程转换线程:

PVOID ConvertThreadToFiber(PVOID pvParam);

autocad调试,线程和纤程交互需要添加,否则只能调试纤程代码不能调试线程

Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("NEXTFIBERWORLD", 0);

添加上面配置后autocad才能附加调试
调试过程中vs频繁崩溃
VS 2015 设置

Turn on “Use Managed Compatibility Mode” via Tools –> Options –> Debugging.
Turn on “Enable native code debugging”(托管兼容模式) from Project –> Properties –> Debug.
Turn off "Xaml ui Debug"

System.InvalidOperationException: 已在“VisualTreeChanged”事件期间更改可视化树。

Tools -> Options -> Debugging -> General ->
Uncheck: Enable UI Debugging Tools for XAML

加载字体(**形未定义)

  • 建议不要使用vs2017,开发是问题比较多,而且vs2017出现了平凡退出的情况
  • 打开调试本地代码,才能加载字体调试,否则只能独立运行加载字体,或者平凡出现** 形未定义(加载字符集错误)

edit.getpoint()阻塞用户交互

autocad用户交互,阻塞当前代码执行,不阻塞消息事件,所以和自定义界面交互,可能出现循环阻塞在同一行代码的情况,需要把函数定义成命令(相同命令重复执行阻塞,只能内部条件避免

 [CommandMethod("命令名称", CommandFlags.Session)]

避免autocad提示gedit 3内部异常
或者发送取消命令(autocad 2014)

 Doc.Editor.IsQuiescent判断是否有命令Doc.SendStringToExecute("\x03", false, false, false);   取消,无空格,其他命令需要(非同步执行,C++ autocad com组件可以实现同步执行)Doc.SendStringToExecute(" ", false, false, false);   一个空格空输入Application.SetSystemVariable("FILEDIA", 0);命令隐藏Application.SetSystemVariable("FILEDIA", 1);命令打开

Cad purge清理为引用数据

 public void ClearUnrefedBlocks(){Document doc = Application.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;Database db = doc.Database;using (Transaction trans = db.TransactionManager.StartTransaction()){BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)as BlockTable;foreach (ObjectId oid in bt){BlockTableRecord btr = trans.GetObject(oid, OpenMode.ForWrite)as BlockTableRecord;if (btr.GetBlockReferenceIds(false, false).Count == 0&& !btr.IsLayout){btr.Erase();}}trans.Commit();}}

代理对象

autocad支持自定义对象和以C++Com模式实现的ObjectARX对象(代理对象)
代理对象通过Object Enabler创建

  • Object Enabler 可使图形中的自定义对象的行为比代理图形更加智能

数据操作

修改数据line转polyline(添加LockDocument、UpgradeOpen、DowngradeOpen避免异常)

 using (Transaction trans = DwgConvert.Doc.Database.TransactionManager.StartTransaction()){using (DocumentLock m_DocumentLock = Doc.LockDocument()){entity.UpgradeOpen();//打开Autodesk.AutoCAD.DatabaseServices.Line ln = entity as Autodesk.AutoCAD.DatabaseServices.Line;Polyline pl = new Polyline();pl.AddVertexAt(0, new Point2d(ln.StartPoint.X,ln.StartPoint.Y),0,0,0);pl.AddVertexAt(1, new Point2d(ln.EndPoint.X,ln.EndPoint.Y), 0, 0, 0);pl.Layer = ln.Layer;pl.ConstantWidth = proIntRes.Value;modelSpace.AppendEntity(pl);entity.Database.TransactionManager.AddNewlyCreatedDBObject(pl,true);ln.Erase();//删除数据entity.DowngradeOpen();}trans.Commit();}

其他数据修改操作封装

//插入图块(非外部文件)
public static void InsertBlock(this BlockTableRecord blokRec, Autodesk.AutoCAD.Geometry.Point3d pt){using (Database sourceDb = new Database(true, false)){Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline(4);pl.AddVertexAt(0, new Autodesk.AutoCAD.Geometry.Point2d(50,-50), 0, 0, 0);pl.AddVertexAt(1, new Autodesk.AutoCAD.Geometry.Point2d(-50,-50), 0, 0, 0);pl.AddVertexAt(2, new Autodesk.AutoCAD.Geometry.Point2d(0,100), 0, 0, 0);pl.AddVertexAt(3, new Autodesk.AutoCAD.Geometry.Point2d(50, -50), 0, 0, 0);using (Transaction trans = sourceDb.TransactionManager.StartTransaction()){BlockTable bt = trans.GetObject(sourceDb.BlockTableId, OpenMode.ForRead) as BlockTable;BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;btr.AppendEntity(pl);trans.AddNewlyCreatedDBObject(pl, true);trans.Commit();}ObjectId blockId = blokRec.Database.Insert("camera", sourceDb, false);BlockReference blockRef = new BlockReference(pt, blockId); // 通过块定义添加块参照blokRec.AppendEntity(blockRef); //把块参照添加到块表记录blockRef.Database.TransactionManager.AddNewlyCreatedDBObject(blockRef, true);//return blockRef;}}
//获取图层名称public static ObjectId GetLayerObjectId(this Database db, string layerName){LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);//if (!lt.Has(layerName))//{//    LayerTableRecord ltr = new LayerTableRecord();//    ltr.Name = layerName;//    lt.UpgradeOpen();//    lt.Add(ltr);//    db.TransactionManager.AddNewlyCreatedDBObject(ltr, true);//    lt.DowngradeOpen();//}if (lt.Has(layerName))return lt[layerName];elsereturn ObjectId.Null;}//设置图层名称public static void SetLayer(this Database db, string layerName){LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);if (lt.Has(layerName)){db.Clayer = lt[layerName];}}//添加Block属性public static void AddAttsToBlocks(this BlockReference block, AttributeDefinition atts){Database db = block.Database;//获取数据库对象BlockTableRecord btr = db.TransactionManager.GetObject(block.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;btr.UpgradeOpen();btr.AppendEntity(atts);db.TransactionManager.AddNewlyCreatedDBObject(atts, true);//db.TransactionManager.Dispose();btr.DowngradeOpen();}//添加Block属性public static void AddAttributeDefinitionToBlocks(this ObjectId blockId, AttributeDefinition atts){Database db = blockId.Database;//获取数据库对象BlockTableRecord btr = blockId.GetObject(OpenMode.ForWrite) as BlockTableRecord;btr.AppendEntity(atts);db.TransactionManager.AddNewlyCreatedDBObject(atts, true);db.TransactionManager.Dispose();btr.DowngradeOpen();}//修改Block属性public static void UpdateAttributesInBlock(this BlockReference blockRef, Dictionary<string, string> attNameValues){foreach (ObjectId id in blockRef.AttributeCollection){AttributeReference attref = id.GetObject(OpenMode.ForRead) as AttributeReference;if (attNameValues.ContainsKey(attref.Tag.ToUpper())){attref.UpgradeOpen();//设置属性值attref.TextString = attNameValues[attref.Tag.ToUpper()].ToString();attref.DowngradeOpen();}}}//查询属性public static string GetValueAttributesInBlock(this BlockReference blockRef, string attNameValue){foreach (ObjectId id in blockRef.AttributeCollection){AttributeReference attref = id.GetObject(OpenMode.ForRead) as AttributeReference;if (attNameValue.ToUpper() == attref.Tag.ToUpper()){//设置属性值return attref.TextString;}}return "";}//添加属性public static void AddAttributeToBlockTableRecord(this BlockTableRecord blokRec, BlockReference blockRef, Dictionary<string,string> atts){if (!blokRec.HasAttributeDefinitions)//添加属性定义{AttributeDefinition aDef = new AttributeDefinition() { Tag=""};blokRec.ObjectId.AddAttributeDefinitionToBlocks(aDef);}foreach (KeyValuePair<string, string> attribute in atts){if (blockRef.GetValueAttributesInBlock(attribute.Key) == ""){AttributeReference attRef = new AttributeReference() { Tag = attribute.Key, TextString = attribute.Value };if (attribute.Key == "图例编码" || attribute.Key == "类型编号" || attribute.Key == "图例分类")attRef.Visible = false;blockRef.AttributeCollection.AppendAttribute(attRef);blockRef.Database.TransactionManager.AddNewlyCreatedDBObject(attRef, true);attRef.Dispose();}else{blockRef.UpdateAttributesInBlock(new Dictionary<string, string>() { { attribute.Key, attribute.Value } });}}}public static BlockReference ReferenceOuterFileBlock(this BlockTableRecord blokRec, Autodesk.AutoCAD.Geometry.Point3d pt,string file,string name){ObjectId refid = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.AttachXref(file, name);//ObjectId refid = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.OverlayXref(file, name);// 通过外部文件获取图块定义的ObjectIdBlockReference blockRef = new BlockReference(pt, refid); // 通过块定义添加块参照blokRec.AppendEntity(blockRef); //把块参照添加到块表记录blockRef.Database.TransactionManager.AddNewlyCreatedDBObject(blockRef, true); // 通过事务添加块参照到数据库return blockRef;}public static BlockReference ImportOuterFileBlock(this BlockTableRecord blokRec, Autodesk.AutoCAD.Geometry.Point3d pt,string file,string name){//Database sourceDb = new Database(false, true);//sourceDb.ReadDwgFile(file, FileShare.Read, true, "");//ObjectIdCollection blockIds = new ObjectIdCollection();//using (Transaction ts = database.TransactionManager.StartTransaction())//{//    BlockTable bt = (BlockTable)ts.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, false);//    foreach (ObjectId btrId in bt)//    {//        BlockTableRecord btr = (BlockTableRecord)ts.GetObject(btrId, OpenMode.ForRead, false);//        if (!btr.IsAnonymous && !btr.IsLayout)//            blockIds.Add(btrId);//        btr.Dispose();//    }//    IdMapping mapping = new IdMapping();//    sourceDb.WblockCloneObjects(blockIds, database.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);//}//sourceDb.Dispose();if (!File.Exists(file)) throw new Exception(string.Format("\n文件找不到({0})",file));using (Database sourceDb = new Database(false, false)){sourceDb.ReadDwgFile(file, FileShare.Read, true, "");sourceDb.CloseInput(true);ObjectId blockId = blokRec.Database.Insert(name, sourceDb, false);BlockReference blockRef = new BlockReference(pt, blockId); // 通过块定义添加块参照blokRec.AppendEntity(blockRef); //把块参照添加到块表记录blockRef.Database.TransactionManager.AddNewlyCreatedDBObject(blockRef, true);return blockRef;}}public static void AddDataToEntity(this Entity entity,Dictionary<string,string> dict){//绑定数据if (entity.ExtensionDictionary == ObjectId.Null){entity.CreateExtensionDictionary();}DBDictionary xDict = entity.Database.TransactionManager.GetObject(entity.ExtensionDictionary, OpenMode.ForRead) as DBDictionary;foreach (KeyValuePair<string, string> pair in dict){if (!xDict.Contains(pair.Key)){xDict.UpgradeOpen();Xrecord xRec = new Xrecord();ResultBuffer rb = new ResultBuffer();rb.Add(new TypedValue((int)DxfCode.Text, pair.Value));xRec.Data = rb;xDict.SetAt(pair.Key, xRec);xDict.DowngradeOpen();entity.Database.TransactionManager.AddNewlyCreatedDBObject(xRec, true);}}}public static string GetEntityData(this Entity entity,string key){//获取数据using (Transaction tr = entity.Database.TransactionManager.StartTransaction()){if (entity.ExtensionDictionary != ObjectId.Null){DBDictionary xDict = tr.GetObject(entity.ExtensionDictionary, OpenMode.ForRead) as DBDictionary;if (xDict.Contains(key)){ObjectId xRecId = xDict.GetAt(key);Xrecord xRec = tr.GetObject(xRecId, OpenMode.ForRead) as Xrecord;if (xRec != null)return xRec.Data.AsArray()[0].Value.ToString();elsereturn "";}}return "";}}public static void ScaleModel(this BlockReference entity, string text){//图例缩放//Extents3d extend = entity.GeometryExtentsBestFit(Autodesk.AutoCAD.Geometry.Matrix3d.Rotation(entity.Rotation,new Autodesk.AutoCAD.Geometry.Vector3d(0,0,1),entity.Position));//double dMaxX = extend.MaxPoint.X, dMaxY = extend.MaxPoint.Y, dMinX = extend.MinPoint.X, dMinY = extend.MinPoint.Y;List<Point> ptls = new List<Point>();Block.RecurBlockReference(entity, new Point(),0, ref ptls);//解析数据if (ptls.Count == 0) return;double dMaxX = ptls.Max(o => o.X), dMaxY = ptls.Max(o => o.Y), dMinX = ptls.Min(o => o.X), dMinY = ptls.Min(o => o.Y);string[] size = text.Split(new string[] { "mm", "*" }, StringSplitOptions.RemoveEmptyEntries);if (size.Length < 2) return;double sizelong, sizewidth;double.TryParse(size[0], out sizelong);double.TryParse(size[1], out sizewidth);Autodesk.AutoCAD.Geometry.Scale3d scale = new Autodesk.AutoCAD.Geometry.Scale3d(sizelong == 0 ? 1 : sizelong / (dMaxX - dMinX), sizewidth == 0 ? 1 : sizewidth / (dMaxY - dMinY), 1);entity.UpgradeOpen();entity.ScaleFactors = entity.ScaleFactors.PostMultiplyBy(scale);entity.DowngradeOpen();}[CommandMethod("DrawOrderTest")] //绘图层级次序static public void DrawOrderTest(){Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;Editor ed = doc.Editor;string message = "\nSelect a entity to move to bottom";PromptEntityOptions options = new PromptEntityOptions(message);PromptEntityResult acSSPrompt = ed.GetEntity(options);if (acSSPrompt.Status != PromptStatus.OK)return;using (Transaction tr = db.TransactionManager.StartTransaction()){Entity ent = tr.GetObject(acSSPrompt.ObjectId,OpenMode.ForRead) as Entity;//get the blockBlockTableRecord block = tr.GetObject(ent.BlockId,OpenMode.ForRead) as BlockTableRecord;//get the draw oder table of the blockDrawOrderTable drawOrder =tr.GetObject(block.DrawOrderTableId,OpenMode.ForWrite) as DrawOrderTable;ObjectIdCollection ids = new ObjectIdCollection();ids.Add(acSSPrompt.ObjectId);//move the selected entity so that entity is//drawn in the beginning of the draw order.drawOrder.MoveToBottom(ids);tr.Commit();}
}

文件操作

public static void NewDoc(string fileName){if (File.Exists(fileName)){OpenDoc(fileName);}else{string strTemplatePath = "acadiso.dwt";DocumentCollection acDocMgr = Application.DocumentManager;Document acDoc = acDocMgr.Add(strTemplatePath);acDocMgr.MdiActiveDocument = acDoc;acDoc.Database.SaveAs(fileName, true, DwgVersion.Current, Doc.Database.SecurityParameters);}}public static void OpenDoc(string fileName){DocumentCollection acDocMgr = Application.DocumentManager;foreach(Document doc in acDocMgr){if (doc.Database.Filename == fileName){//文件是否打开acDocMgr.MdiActiveDocument = doc;return;}}if (File.Exists(fileName))acDocMgr.Open(fileName, false);elsePutMessage("File " + fileName + " does not exist.");}public static void SaveDoc(string fileName){Doc.Database.SaveAs(fileName, true, DwgVersion.Current,Doc.Database.SecurityParameters);}

autocad命令

base命令(修改图块基点)
THUMBSAVE 保存缩略图
解组 ungroup
导出图像后再导出块对象
pu(-pu)资源清理,减小dwg文件大小(最好先剪贴或者拷贝后操作)
laydel 删除图层
XR外部参照管理
attmode 0属性文字不显示
pe选择多个直线转换多段线,x多段线转直线
cui 菜单管理
cuiload 菜单重加载(修改cui文件后需要调用cuiload卸载后加载刷新菜单栏)
netload加载插件或者autocad里面帮助搜索插件,按照说明设置文件夹导入

菜单自定义

cui命令加载或者cuiload重新加载cuix文件
工具栏

//工具栏Toolbar fdTb = cs.MenuGroup.Toolbars.FindToolbarWithName("XXXX");if (fdTb != null)fdTb.ToolbarItems.Clear();elsefdTb = new Toolbar("XXXX", cs.MenuGroup);ToolbarButton tlBtn1 = new ToolbarButton(mMar1.ElementID, "XXXX", fdTb, 0);ToolbarButton tlBtn2 = new ToolbarButton(mMar2.ElementID, "XXXX", fdTb, 0);ToolbarButton tlBtn3 = new ToolbarButton(mMar3.ElementID, "XXXXX", fdTb, 1);fdTb.ToolbarItems.Add(tlBtn1);fdTb.ToolbarItems.Add(tlBtn2);fdTb.ToolbarItems.Add(tlBtn3);fdTb.ToolbarVisible = ToolbarVisible.show;

菜单栏

PopMenu pmParent = cs.MenuGroup.PopMenus.FindPopWithName(customName);if (pmParent == null)pmParent = new PopMenu(customName, new StringCollection() { "POP14" }, "PMU_191_D624B", cs.MenuGroup);//清除菜单pmParent.PopMenuItems.Clear();new PopMenuItem(new MenuMacro(maGroup, "xxx", "xxxxx", ""), "xxx", pmParent, -1);new PopMenuItem(new MenuMacro(maGroup, "xxxx", "xxxx", ""), "xxxx", pmParent, -1);new PopMenuItem(pmParent, 2);MenuMacro mMar1 = new MenuMacro(maGroup, "xxxx", "SWJX_ScaleModel", "");mMar1.macro.SmallImage = LoginInfo.instance().AppPath+ "/Resources/尺寸.bmp";new PopMenuItem(mMar1, "xxx", pmParent, -1);new PopMenuItem(new MenuMacro(maGroup, "xxxxx", "xxxxxx", ""), "xxxx", pmParent, -1);MenuMacro mMar2 = new MenuMacro(maGroup, "xxxxx", "xxxx", "");mMar2.macro.SmallImage = LoginInfo.instance().AppPath + "/Resources/xx.bmp";new PopMenuItem(mMar2, "xxxx", pmParent, -1);MenuMacro mMar3 = new MenuMacro(maGroup, "xxxxx", "xxxxxx", "");mMar3.macro.SmallImage = LoginInfo.instance().AppPath + "/Resources/x.bmp";new PopMenuItem(mMar3, "xxxxx", pmParent, -1);
#if DEBUGnew PopMenuItem(new MenuMacro(maGroup, "xxxx", "xxxxxx", ""), "xxxx", pmParent, -1);
#endifnew PopMenuItem(new MenuMacro(maGroup, "xxxxx", "xxxxx", ""), "xxxxxx", pmParent, -1);
#if DEBUGnew PopMenuItem(pmParent, 9);
#elsenew PopMenuItem(pmParent, 8);
#endifnew PopMenuItem(new MenuMacro(maGroup, "xxxxx", "xxxxx", ""), "xxxxx", pmParent, -1);
#if DEBUGnew PopMenuItem(pmParent, 11);
#elsenew PopMenuItem(pmParent, 10);
#endifnew PopMenuItem(new MenuMacro(maGroup, "xxxxx", "SWJX_InsertCamera", ""), "xxxxxx", pmParent, -1);cs.MenuGroup.PopMenus.Add(pmParent);

功能区、选项卡、面板

             RibbonTabSource myRibbonTab = null;foreach (RibbonTabSource ribTab in cs.MenuGroup.RibbonRoot.RibbonTabSources){//选项卡...}Autodesk.AutoCAD.Customization.RibbonPanelSource panelSrc3 = null;foreach (Autodesk.AutoCAD.Customization.RibbonPanelSource ribPanel in          cs.MenuGroup.RibbonRoot.RibbonPanelSources){//面板...}

添加到工作区

//添加到工作区foreach (Workspace wk in cs.Workspaces){foreach(WorkspacePopMenu pm in wk.WorkspacePopMenus){//菜单...}if (!bFound){//找不到添加,使用cui命令检查cuix是否有多余的错误资源(影响绑定关系,最好每次调试清理一次)wk.WorkspacePopMenus.Add(new WorkspacePopMenu(wk, pmParent) { Display = 1 });}foreach (WorkspaceToolbar tbl in wk.WorkspaceToolbars){//工具栏...}if (!bFound){//找不到添加,使用cui命令检查cuix是否有多余的错误资源(影响绑定关系,最好每次调试清理一次)wk.WorkspaceToolbars.Add(new WorkspaceToolbar(wk, fdTb) { Display=1});}foreach (WSRibbonTabSourceReference pm in wk.WorkspaceRibbonRoot.WorkspaceTabs){//面板}if (!bFound){//找不到添加,使用cui命令检查cuix是否有多余的错误资源(影响绑定关系,最好每次调试清理一次)wk.WorkspaceRibbonRoot.WorkspaceTabs.Add(WSRibbonTabSourceReference.Create(myRibbonTab));}...}if (cs.IsModified) cs.Save();Application.ReloadAllMenus();

进度条

private static ProgressMeter s_Pmeter = new ProgressMeter();

动态修改数据

tr.Commit();//提交后修改绘制
tr.TransactionManager.QueueForGraphicsFlush();

鼠标右键

ContextMenuExtension cm = new ContextMenuExtension();
Autodesk.AutoCAD.ApplicationServices.Application.AddDefaultContextMenuExtension(cm);

cad颜色设置

  • 1-255 255中基本颜色
  • 0 表示 ByBlock
  • 256 表示 ByLayer

内存中绘cad图

int Width = 512,WallThickness = 60;Autodesk.AutoCAD.GraphicsSystem.Manager gsm = doc.GraphicsManager;using (Transaction tran = doc.Database.TransactionManager.StartTransaction()){ViewportTableRecord vTbRec = (ViewportTableRecord)tran.GetObject(doc.Editor.ActiveViewportId, OpenMode.ForRead);using (Autodesk.AutoCAD.GraphicsSystem.View view = new Autodesk.AutoCAD.GraphicsSystem.View()){using (Autodesk.AutoCAD.GraphicsSystem.Device dev = gsm.CreateAutoCADOffScreenDevice()){dev.DeviceRenderType = Autodesk.AutoCAD.GraphicsSystem.RendererType.Default;dev.BackgroundColor = System.Drawing.Color.Black;dev.Add(view);dev.Update();using (Autodesk.AutoCAD.GraphicsSystem.Model model = gsm.CreateAutoCADModel()){view.VisualStyle = new Autodesk.AutoCAD.GraphicsInterface.VisualStyle(vst);view.Mode = Autodesk.AutoCAD.GraphicsSystem.RenderMode.FlatShaded;using (Transaction tr = doc.Database.TransactionManager.StartTransaction()){Point Max = new Point() { X = double.NaN, Y = double.NaN }, Min = new Point() { X= double.NaN,Y= double.NaN};LayerTable layTbl = tr.GetObject(doc.Database.LayerTableId, OpenMode.ForRead) as LayerTable;BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);foreach (ObjectId btId in bt){BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btId, OpenMode.ForRead);foreach (ObjectId btrId in btr){BlockTableRecord modelSpace = tr.GetObject(btId, OpenMode.ForRead) as BlockTableRecord;//删除未被引用的块if (modelSpace.GetBlockReferenceIds(false, false).Count == 0 && !modelSpace.IsLayout)continue;DBObject obj = tr.GetObject(btrId, OpenMode.ForRead);if ((obj is Autodesk.AutoCAD.DatabaseServices.Line || obj is Polyline || obj is Polyline3d) && (obj as Entity).Layer == LayerName.instance()[(int)LayerTag.Wall]){Entity entity = (obj as Entity);//entity.UpgradeOpen();//entity.Color = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.White);//entity.DowngradeOpen();//获取数据的最大边界if (double.IsNaN(Max.X) || Max.X < entity.GeometricExtents.MaxPoint.X)Max.X = entity.GeometricExtents.MaxPoint.X;if (double.IsNaN(Min.X)|| Min.X > entity.GeometricExtents.MinPoint.X)Min.X = entity.GeometricExtents.MinPoint.X;if (double.IsNaN(Max.Y) || Max.Y < entity.GeometricExtents.MaxPoint.Y)Max.Y = entity.GeometricExtents.MaxPoint.Y;if (double.IsNaN(Min.Y) || Min.Y > entity.GeometricExtents.MinPoint.Y)Min.Y = entity.GeometricExtents.MinPoint.Y;//if (obj is Polyline && (obj as Polyline).ConstantWidth > WallThickness)//    WallThickness = (int)(obj as Polyline).ConstantWidth/2;view.Add(obj, model);}}}tr.Commit();//Max.Z = Doc.Database.Extmax.Z;//Min.Z = Doc.Database.Extmin.Z;Max.X += WallThickness; Max.Y += WallThickness; Min.X -= WallThickness; Min.Y -= WallThickness;if (double.IsNaN(Max.X) || double.IsNaN(Min.X) || double.IsNaN(Max.Y) || double.IsNaN(Min.Y)){dev.OnSize(new System.Drawing.Size(Width, (int)(Width * (doc.Database.Extmax.Y - doc.Database.Extmin.Y) / (doc.Database.Extmax.X - doc.Database.Extmin.X))));view.ZoomExtents(doc.Database.Extmax, doc.Database.Extmin);view.SetView(vTbRec.Target, vTbRec.Target.Subtract(new Vector3d(0, 0, 1)), Vector3d.ZAxis, doc.Database.Extmax.X - doc.Database.Extmin.X, doc.Database.Extmax.Y - doc.Database.Extmin.Y);using (System.Drawing.Bitmap bitmap = view.GetSnapshot(new System.Drawing.Rectangle(0, 0, Width, (int)(Width * (doc.Database.Extmax.Y - doc.Database.Extmin.Y) / (doc.Database.Extmax.X - doc.Database.Extmin.X))))){Bitmap2Png(bitmap).Save(filename);dev.Erase(view);view.EraseAll();}}else{dev.OnSize(new System.Drawing.Size(Width, (int)(Width * (Max.Y - Min.Y) / (Max.X - Min.X))));view.ZoomExtents(Max.ToPoint3d(), Min.ToPoint3d());view.SetView(vTbRec.Target, vTbRec.Target.Subtract(new Vector3d(0, 0, 1)), Vector3d.ZAxis, Max.X - Min.X, Max.Y - Min.Y);using (System.Drawing.Bitmap bitmap = view.GetSnapshot(new System.Drawing.Rectangle(0, 0, Width, (int)(Width * (Max.Y - Min.Y) / (Max.X - Min.X))))){Bitmap2Png(bitmap).Save(filename);dev.Erase(view);view.EraseAll();}}}}}}}

标注

  • 半径标注RadialDimension
  • 角度标注LineAngularDimension2
  • 转角标注RotatedDimension
  • 多重引线MLeader
     MLeader mld = new MLeader();int ldNum = mld.AddLeader();int lnNum = mld.AddLeaderLine(ldNum);mld.AddFirstVertex(lnNum, startPt);mld.AddLastVertex(lnNum, endPt);mld.ArrowSymbolId = arrId;mld.LeaderLineType = LeaderType.SplineLeader;

autocad.net相关推荐

  1. 2016-2022年AutoCAD起重机吊装计划和索具图纸

    AutoCAD Crane Lifting Plan and Rigging Drawings 2016-2022 完成AutoCAD 2D高级起重机提升计划和索具图纸-基于项目的培训 你会学到什么 ...

  2. Autocad 3D 完全学习教程

    Autocad 3D 完全学习教程 你会学到什么 如何使用AutoCAD三维基本特征 了解如何在AutoCAD中创建和开发三维模型 准备实体.网格和曲面几何图形 不同的命令2d和3D 要求 不需要事先 ...

  3. AutoCAD 2D与3D大师班学习教程 AutoCAD 2D and 3D Masterclass

    用实例和解决问题的方法完成从基础到专业的AutoCAD课程. 你会学到什么 AutoCAD课程包含创建计划和模型的命令和不同方法的详细使用. 本课程包括对AutoCAD中使用的所有命令和工具的详细解释 ...

  4. 学习如何在AutoCad土木工程中绘制建筑设计图

    学习如何在AutoCad中绘制建筑设计图从平面图到AutoCad土木工程中的整栋建筑 你会学到: 如何绘制房屋地图 如何绘制建筑设计 如何从AutoCad打印或出图 AutoCaD使用 AutoCaD ...

  5. 使用脚本完成AutoCAD自动化任务课程

    The complete AutoCAD Automation tasks course Using Script MP4 |视频:h264,1280×720 |音频:AAC,44.1 KHz,2 C ...

  6. 终极AutoCAD大师班:成为AutoCAD专家

    Ultimate AutoCAD Masterclass: Become an Expert in AutoCAD 流派:电子学习| MP4 |视频:h264,1280×720 |音频:AAC,44. ...

  7. 使用AutoCAD 2021创建真实世界的土木设计项目

    由工程组织创建|最后更新日期:2021年9月 时长:7h 24m | 7节| 64节讲座|视频:1280×720,44 KHz | 大小解压后3 GB 流派:电子学习|语言:英语+中英文字幕(根据原英 ...

  8. 激动人心的AutoCAD .net开发技术

    自从了解了vsto和sc(SmartClient)技术后,对以前Win32的二次开发技术,再也没有一点兴趣.对Office VBA,  AutoCAD lisp, VBA,  PowerBuilder ...

  9. AutoCAD.NET API 最新(2012)教程下载及在线视频教程DevTV 第8讲 用户界面

    Autodek最近发布了基于最新版的AutoCAD 2012的.net API开发教程.基本内容包括: Overview of .NET( AutoCAD.NET API概览  ) Plugin Ba ...

  10. Civil 3D 二次开发 创建AutoCAD对象—— 00 ——

    不积跬步无以至千里,不积小流无以成江海.虽然创建一条直线.添加一个图层这样的小程序没有什么实际意义(内部命令很简单就可以完成),但对于初学二次开发的您来说,这可是一大步,这一步跨出去,您就跨进了二次开 ...

最新文章

  1. [Oracle] - 性能优化工具(5) - AWRSQL
  2. 全世界都在问Java开发凉了吗?意外的惊喜
  3. leetcode算法题--矩阵中的幸运数
  4. 辞九门回忆用计算机,辞九门回忆(单轨,曲速70,适合UTAU调教;midishow首发)...
  5. 详解:数据库名、实例名、ORACLE_SID、数据库域名、全局数据库名、服务名
  6. centos6.3 nginx php,CentOS 6.3下nginx、php-fpm、drupal快速部署
  7. Python《使用Selenium 和pyautogui 实现自动登录淘宝》
  8. Softmax回归模型的构建和实现(Fashion-MNIST图像分类)
  9. Spring Framework 核心原理与源码解析-大纲
  10. docker 安装_Docker-安装
  11. 怎么用debug看jdbc查询的resultset中查出的数据_用了这个 ORM 工具,我只用一天就把项目数据库给换了
  12. MCU —— 数码管显示笔记
  13. 饭饭的Selenium+xlwt笔记
  14. 苹果macOS Big Sur 11.4 正式版发布
  15. 数据分析 -- Pandas①
  16. Mockplus原型设计学习笔记(1)—— 图层的调节
  17. 数字温度计的c语言编程,基于DS18B20数字温度计的设计(全文完整版)
  18. 胡忠想|微博微服务架构的Service Mesh实践之路
  19. 利用Google Translator作为代理向受感染计算机发送任意命令并执行(Google Translator Reverse Shell) Poc详解...
  20. java 对接 PayPal 或者 Stripe 支付,订阅

热门文章

  1. Advanced features
  2. golang泛型介绍
  3. ABP Freamwork 生成种子数据 表名abpUser不存在
  4. 【 第11关:基于邻接表的深度优先遍历】【编程题实训-图】【头歌】【bjfu-282】
  5. 大数据解密:《人民的名义》是怎么火起来的?
  6. 智慧旅游规划信息管理系统
  7. 帝国cms手机和pc站数据同步建站教程
  8. 【科普】笔记本电脑选购指南
  9. 选址问题模型验证01: The cycle hub location problem
  10. 什么软件可以一键抠图?这篇文章告诉你