- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个 C#.NET 程序,该程序通过 AutoCAD .NET API 与 AutoCAD 交互。该程序循环遍历目录中的 DWG 文件,并检查“testLayer”图层上的每个文本实体以查看其是否与“testText”匹配。我通过打开每个文件并创建一个 Selectionfilter 来获取“testLayer”层上的所有实体来实现此目的。
Application.DocumentManager.Open(curfile.FullName, false);
....
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction acTrans = doc.TransactionManager.StartTransaction())
{
ObjectIdCollection ents = new ObjectIdCollection();
// Set up filter and filter on layer name
TypedValue[] tvs = new TypedValue[1] { new TypedValue((int)DxfCode.LayerName, "testLayer")};
SelectionFilter sf = new SelectionFilter(tvs);
PromptSelectionResult psr = ed.SelectAll(sf);
if (psr.Status == PromptStatus.OK)
{
// Get the object ids for all of the entities for the filtered layer
ents = new ObjectIdCollection(psr.Value.GetObjectIds());
foreach (ObjectId objid in ents)
{
DBText dbText = acTrans.GetObject(objid, OpenMode.ForRead) as DBText;
if (dbText.TextString.Contains("testText")
{
return dbText.TextString;
}
}
return "";
}
else
{
return "";
}
}
}
但现在我正在将程序转换为旁加载底层数据库,因为程序打开和关闭每个 .DWG 文件花费的时间太长。问题是现在我正在使用
db.ReadDwgFile(currentDWG, FileOpenMode.OpenForReadAndAllShare, true, string.Empty);
读取文件而不实际打开它们,所以我无法使用
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor
和ed.SelectAll(sf)
用于我之前使用的选择过滤策略,因为文档实际上并未打开。那么,如何在不实际打开 DWG 文件的情况下获取名为“testLayer”的每个图层上的所有文本实体呢?
最佳答案
在“侧数据库”中,要模仿 SelectAll,您必须迭代所有布局中的所有实体并检查实体层。
编辑:在“侧数据库”中,为了模仿 SelectAll,您必须迭代所有布局中的所有实体并检查实体类型和图层。
private IEnumerable<ObjectId> GetTextEntitiesOnLayer(Database db, string layerName)
{
using (var tr = db.TransactionManager.StartOpenCloseTransaction())
{
var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId btrId in blockTable)
{
var btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
var textClass = RXObject.GetClass(typeof(DBText));
if (btr.IsLayout)
{
foreach (ObjectId id in btr)
{
if (id.ObjectClass == textClass)
{
var text = (DBText)tr.GetObject(id, OpenMode.ForRead);
if (text.Layer.Equals(layerName, System.StringComparison.CurrentCultureIgnoreCase))
{
yield return id;
}
}
}
}
}
}
}
关于c# - 如何在不打开文件 (C#.NET/AutoCAD) 的情况下获取 .DWG 文件中特定图层上的所有实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41062809/
AutoCAD 允许将 SPLINE 实体存储在仅由 拟合点,问题是,这样的样条定义有无限 数值正确的解决方案,Autodesk 不提供必要的 从给定的拟合点计算所需参数的信息。 tl;dr - 缺失
是否有用于解析 AutoCAD 文件(DWG 或 DXF)的库(最好是开源的)? 最佳答案 重复(或至少相关)Open source cad drawing (dwg) library in C# &
我看到了 v2.0: 75% there帖子提到 Autocad 并且有一个 AutoCADApp.cs文件,但我似乎找不到使用 Rubberduck 的引用在 Office 之外,在一些随机主机应用
我想提取 Autocad 文件的坐标(纬度、经度)和一些属性,例如名称和颜色。我可以通过 Java 程序执行此操作。 在 Autocad 中,哪种格式是正确的导出格式,以便我可以通过编程方式解析文件、
我使用 dot net 3.50 添加了一个 autocad,我引用了 autocad 2012 中的 acdbmgd.dll、acmgd.dll我该怎么做才能让它在 autocad 2010 和 a
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 3年前关闭。 Improve thi
这可能是我一直想念的简单的东西,但是...... 我可以获得实体名称,但是是否可以使用分配给变量的实体名称来让 Autocad 命令使用该实体作为要操作的选定对象? 最佳答案 要在“立即”模式下使用,
我开发了一个外部 WPF 应用程序来用 C# 生成绘图。我已经能够使用 Autodesk.AutoCAD.Interop 绘制、标注尺寸、添加 block 以及应用程序所需的所有其他内容,但是我似乎无
我已经运行 win32com 来访问 AutoCAD 相当长一段时间了,没有出现任何问题。我了解到应用 makepy 实用程序可以在交互式提示下创建更加用户友好的体验,因此我运行它并添加了“AutoC
我有一个 Autocad 绘图,它是一个土地方 block 的平面图,每个方 block 都包含一个数字。 我尝试通过选择将其转换为图像:文件->导出数据->和文件格式位图(bmp)。 (我有 Aut
我有一个三角形作为折线,我想画一个高度。我发出命令 "line"或 "_line"正确的点,但 AutoCAD 绘制从顶点到相邻顶点的线。 不只是在 AutoLISP 中,AutoCAD 不允许我在折
我想使用代码来分析 dwg 文件。任何人都知道任何 SDK 工具可以开始使用吗? 最佳答案 来自 Wikipedia : Autodesk 根据选择性许可条款销售名为 RealDWG 的读/写库,用于
本文为大家分享了AutoCAD .Net禁止图元被删除的具体代码,供大家参考,具体内容如下 禁止图元被用户删除可以通过 ObjectOverrule 实现。 以下代码: 1、命令 AddEra
我正在使用 C# 编写 AutoCAD 插件,需要在阴影对象的中间(例如,圆心)显示阴影属性。我在代码中有两个问题: 如何访问圆心? 如何获取hatch的属性? 我在 autocad 中的这一行遇到错
我正在研究一个autoCAD .net项目,在其中创建了MVVM模式以选择和修改实体。我想将所选实体的信息/值存储到 View 模型中,更改信息/值(通过弹出的WPF UI以及我的代码),然后将更改应
我正在实现一个应用程序,该应用程序在 AutoCAD 的 ObjectARX 界面中使用 COM 来自动执行绘图操作,例如打开和另存为。 根据文档,我应该能够调用 AcadDocument.SaveA
我对开发 AutoCAD 插件感兴趣,并试图了解几种不同类型的 AutoCAD 插件文件之间的关系: 随 AutoCAD 插件一起提供的托管 DLL ARX files附带 AutoCAD 插件 CU
我正在使用 C#.NET 编写 AutoCAD 插件。我需要一种方法来将 Table.IsReadEnabled 和 Table.IsWriteEnabled 设置为 true。我有一个名为 addR
使用 ObjectARX (C++) for AutoCAD 2010,AutoCAD 实体可以序列化吗? 我们需要将序列化的实体保存在数据库(Oracle、PostgreSQL 等,不是 AcDbD
我正在尝试制作一个表格,当用户提交更多数据时动态添加行: public void addRow(String[] data) { Transaction tr = doc.TransactionMan
我是一名优秀的程序员,十分优秀!