C#.Net实现AutoCAD块属性提取
https://blog.csdn.net/dengyiyu/article/details/2201175
本文主要给大家介绍一下SmartSoft中用C#.Net实现AutoCAD块属性提取的方法,并给出实例代码与大家共享。此类实现AutoCAD块属性提取功能,在VS.Net2003(2005)+AutoCAD2004(2007)下调试通过。
using System;
using AutoCAD=Autodesk.AutoCAD.Interop;
using System.Runtime.InteropServices ;
using dbx = Autodesk.AutoCAD.Interop.Common;
namespace SmartSoft.ACAD
{
///
/// 读取AutoCAD属性信息
///
public class AutoCADConnector:IDisposable
{
private AutoCAD.AcadApplication _Application;
private bool _Initialized;
private bool _Disposed;
#region 类初始化及析构操作
///
/// 类初始化,试图获取一个正在运行的AutoCAD实例,
/// 如果没有则新起动一个实例。
///
public AutoCADConnector()
{
try
{
//取得一个正在运行的AUTOCAD实例
this._Application = (AutoCAD.AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17");
}//end of try
catch
{
try
{
//建立一个新的AUTOCAD实例,并标识已经建立成功。
_Application = new AutoCAD.AcadApplicationClass();
_Initialized=true;
}
catch
{
throw new Exception ("无法起动AutoCAD应用程序,确认已经安装");
}
}//end of catch
}//end of AutoCADConnector
~AutoCADConnector()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this._Disposed && this._Initialized )
{
//如果建立了AUTOCAD的实列,调用QUIT方法以避免内存漏洞
this._Application.ActiveDocument.Close (false,"");
this._Application.Quit();
this._Disposed=true;
}
}
#endregion
#region 公共用户接口属性
///
/// 取得当前类所获得的AUTOCAD实例
///
public AutoCAD.AcadApplication Application
{
get
{
return _Application;
}
}//end of Application
#endregion
#region 公共用户接口方法
///
/// 根据给定的文件名以AxDbDocument类型返回该文档
///
public dbx.AxDbDocument GetThisDrawing(string FileName,string PassWord)
{
ACAD.AutoCADConnector Connector=new AutoCADConnector();
//这是AutoCAD2004的Programe ID
string programeID ="ObjectDBX.AxDbDocument.17";
AutoCAD.AcadApplication AcadApp = Connector.Application;
dbx.AxDbDocument dbxDoc;
dbxDoc=(dbx.AxDbDocument)AcadApp.GetInterfaceObject(programeID);
try
{
if (System.IO.File.Exists (FileName)==false) throw new Exception ("文件不存在。");
dbxDoc.Open(FileName,PassWord);
}// end of try
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message );
dbxDoc=null;
}
return dbxDoc;
}//end of function GetThisDrawing
///
/// 根据当前文档和块名取得当前块的引用
///
public dbx.AcadBlockReference GetBlockReference(dbx.AxDbDocument thisDrawing,string blkName)
{
dbx.AcadBlockReference blkRef=null;
bool found = false;
try
{
foreach (dbx.AcadEntity entity in thisDrawing.ModelSpace )
{
if (entity.EntityName=="AcDbBlockReference")
{
blkRef=(dbx.AcadBlockReference)entity;
//System.Windows.Forms.MessageBox.Show(blkRef.Name);
if (blkRef.Name.ToLower() ==blkName.ToLower() )
{
found = true;
break;
}
}//end of entity.EntityName=="AcDbBlockReference"
}// end of foreach thisDrawing.ModelSpace
}//end of try
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show ("图形中有未知的错误,格式不正确或图形数据库需要修愎。系统错误提示:" + e.Message ,"信息",System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
thisDrawing=null;
}//end of catch
if (!found) blkRef = null;
return blkRef;
}//end of function GetBlockReference
///
/// 根据给定的块引用(dbx.AcadBlockReference)和属性名返回属性值
///
public object GetValueByAttributeName(dbx.AcadBlockReference blkRef,string AttributeName)
{
object[] Atts=(object[])blkRef.GetAttributes();
object attValue=null;
for (int i=;i
{
dbx.AcadAttributeReference attRef;
attRef=(dbx.AcadAttributeReference)Atts[i];
if (attRef.TagString==AttributeName)
{
attValue= attRef.TextString ;
break;
}
}//end of for i
return attValue;
}// end of function
#endregion
}//end of class CAutoCADConnector
}//end of namespace AutoCAD
C#.Net实现AutoCAD块属性提取的更多相关文章
- AutoCAD开发1---获取块属性
Private Sub CommandButton1_Click() Dim pEntity As AcadObject Dim pBlock As AcadBlockReference Dim pP ...
- arcgis操作笔记-根据属性提取某区域要素
1. 提取
- 定位absolute使内联支持宽高(块属性变为内联,内容默认撑开)margin auto 失效
relative 没脱离文档流 absdute 完全脱离文档流 margin :auto 失效 相对整个文档偏离 相对父级定位 fixed 脱离文档流 与绝对定位特性一致 3.P标快不能包块级标签 ...
- Oracle EBS FORM 设置块属性
declare blk_id BLOCK; begin blk_id := Find_block('ADRP_HEADER'); Set_block_property(blk_id,insert_al ...
- CAD增强属性块的还原(转)
来自:http://blog.3snews.net/space.php?uid=13924959&do=blog&id=70174 作者:毛毛虫 Demo下载:CAD增强属性块的还原 ...
- 软件-绘图-AutoCAD:百科
ylbtech-软件-绘图-AutoCAD:百科 AutoCAD(Autodesk Computer Aided Design)是Autodesk(欧特克)公司首次于1982年开发的自动计算机辅助设计 ...
- 梦想CAD控件图块COM接口知识点
梦想CAD控件图块COM接口知识点 图块是将多个实体组合成一个整体,并给这个整体命名保存,在以后的图形编辑中图块就被视为一个实体.一个图块包括可见的实体如线.圆.圆弧以及可见或不可见的属性数据.图块的 ...
- Python【BeautifulSoup解析和提取网页数据】
[解析数据] 使用浏览器上网,浏览器会把服务器返回来的HTML源代码翻译为我们能看懂的样子 在爬虫中,也要使用能读懂html的工具,才能提取到想要的数据 [提取数据]是指把我们需要的数据从众多数据中挑 ...
- kaggle数据挖掘竞赛初步--Titanic<派生属性&维归约>
完整代码: https://github.com/cindycindyhi/kaggle-Titanic 特征工程系列: Titanic系列之原始数据分析和数据处理 Titanic系列之数据变换 Ti ...
随机推荐
- k8s学习 - 概念 - Pod
k8s学习 - 概念 - Pod 这篇继续看概念,主要是 Pod 这个概念,这个概念非常重要,是 k8s 集群的最小单位. 怎么才算是理解好 pod 了呢,基本上把 pod 的所有 describe ...
- infiniband install driver
硬件:Mellanox InfiniBand,主要包括 HCA(主机通道适配器)和交换机两部分 软件:CentOS 6.4 MLNX_OFED_LINUX-2.1-1.0.0-rhel6.4-x86_ ...
- Java编程思想:内部类基础部分
public class Test { public static void main(String[] args) { // Parcel1.test(); // Parcel2.test(); / ...
- python的ORM技巧记录
# -*- coding:utf-8 -*- from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, In ...
- [原创]wireshark&xterm安装、配置和使用
--wireshark && xterm--一.安装wireshark: #apt-get install wireshark二.启动wireshark: #wireshark 或者 ...
- Node.js socket 双向通信
使用场景: 聊天室:大量数据常驻交互: 技术栈: Node.js, Vue.js || 原生JS 服务端代码: const app = require('http').createServe ...
- C#3.0新增功能02 匿名类型
连载目录 [已更新最新开发文章,点击查看详细] 匿名类型提供了一种方便的方法,可用来将一组只读属性封装到单个对象中,而无需首先显式定义一个类型. 类型名由编译器生成,并且不能在源代码级使用. 每 ...
- 代码中批量执行Oracle SQL语句
今天在写一个工具(winform),作用是批量的INSERT OR UPDATE ORACLE数据库中的一个表. 执行的时候老是报错“[911] ORA-00911: invalid charact ...
- 自动生成Mybatis的Mapper文件
自动生成Mybatis的Mapper文件 工作中使用mybatis时我们需要根据数据表字段创建pojo类.mapper文件以及dao类,并且需要配置它们之间的依赖关系,这样的工作很琐碎和重复,myba ...
- idea使用技巧总结
1.idea代码自动补全 https://jingyan.baidu.com/article/36d6ed1f62e9821bcf4883af.html 2.优化_生成main方法_sysout方法 ...