统计模块空间的标注的标注值及上下公差,包括块中标注。
效果图


代码简洁明了
csharp
[CommandMethod("QSDimToCSV")]
public void DimToCSV()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
try
{
// 创建类型过滤器(选择所有标注类型)
TypedValue[] filterList = new TypedValue[]
{
new TypedValue((int)DxfCode.Operator, "<or"),
new TypedValue((int)DxfCode.Start, "DIMENSION"), // 标注
new TypedValue((int)DxfCode.Start, "INSERT"), // 块引用
new TypedValue((int)DxfCode.Operator, "or>")
};
SelectionFilter filter = new SelectionFilter(filterList);
// 提示用户选择标注
PromptSelectionResult res = ed.GetSelection(filter);
if (res.Status != PromptStatus.OK)
{
return;
}
System.Windows.Forms.SaveFileDialog openFileDialog = new System.Windows.Forms.SaveFileDialog();
openFileDialog.Title = "选择文件";
openFileDialog.Filter = "csv文件(*.csv)|*.csv|所有文件 (*.*)|*.*";
openFileDialog.FilterIndex = 1; // 默认选中第一个过滤器
openFileDialog.RestoreDirectory = true; // 恢复之前的目录
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return ;
}
QinShiBase.CCSV csv = new QinShiBase.CCSV(openFileDialog.FileName);
csv.Write(new List<string> { "测量值","上公差","下公差"});
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
foreach (SelectedObject sel in res.Value)
{
Entity entity = tr.GetObject(sel.ObjectId, OpenMode.ForWrite) as Entity ;
Add( csv, entity as Dimension);
QinShiCad.CEnumBlock.Enum(tr,entity as BlockReference,onEnum);
}
tr.Commit();
}
csv.Flush();
void onEnum(Entity entity)
{
Add(csv, entity as Dimension);
}
}
catch(System.Exception ex)
{
CLogFactory.MainLog.Write(ex.ToString(), "异常");
}
void Add( QinShiBase.CCSV csv, Dimension dim)
{
if (dim != null)
{
try
{
csv.Write(new List<string> { "" + dim.Measurement, "" + dim.Dimtp, "" + dim.Dimtm });
}
catch(System.Exception ex)
{
CLogFactory.MainLog.Write(ex.ToString()+"\n"+ dim.ToString(), "异常");
}
}
}
}

扩展阅读
| 我想对大家说的话 |
|---|
| 工作中遇到的问题,可以按类别查阅鄙人的算法文章,请点击《算法与数据汇总》。 |
| 学习算法:按章节学习《喜缺全书算法册》,大量的题目和测试用例,打包下载。重视操作 |
| 有效学习:明确的目标 及时的反馈 拉伸区(难度合适) 专注 |
| 员工说:技术至上,老板不信;投资人的代表说:技术至上,老板会信。 |
| 闻缺陷则喜(喜缺)是一个美好的愿望,早发现问题,早修改问题,给老板节约钱。 |
| 子墨子言之:事无终始,无务多业。也就是我们常说的专业的人做专业的事。 |
| 如果程序是一条龙,那算法就是他的是睛 |
| 失败+反思=成功 成功+反思=成功 |
视频课程
先学简单的课程,请移步CSDN学院,听白银讲师(也就是鄙人)的讲解。
https://edu.csdn.net/course/detail/38771
如何你想快速形成战斗了,为老板分忧,请学习C#入职培训、C++入职培训等课程
https://edu.csdn.net/lecturer/6176
测试环境
操作系统:win7 开发环境: VS2019 C++17
或者 操作系统:win10 开发环境: VS2022 C++17
如无特殊说明,本算法 用**C++**实现。
