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 ...
随机推荐
- pdfminer获取每页的layout
#! python2 # coding: utf-8 import sys from pdfminer import pdfparser from pdfminer import pdfdocumen ...
- MyBatis where、set、trim标签的用法
<!-- 4.3.1 where用法 <where>标签的作用:如果该便签包含的元素中有返回值,就插入一个where:如果 where后面的字符串是一and或or开头的,就将它们剔除 ...
- 洛谷P2384 最短路 题解
题目简叙: 请你求出从1到n的最短路径,其中最短路径☞这条路经过的边的权值的乘积. 题目分析: 很显然,这也是一道经典的单元最短路问题,首先我们可以考虑使用Floyd,显然,这是一个比较无脑简单的最短 ...
- C++小游戏——井字棋
#include<cstdio> #include<windows.h> #include<ctime> int main() { srand(time(NULL) ...
- 个人永久性免费-Excel催化剂功能第95波-地图数据挖宝之IP地址转地理地址及不同经纬度版本转换
经过上一波POI兴趣点查询后,地图数据挖宝也接近尾声,这次介绍在数据采集.准备过程中需要用到的一些转换功能,有IP地址转换地理地址及不同地图版本的经纬度转换. 背景知识 在电商.网络的数据分析过程中, ...
- Git初步配置 ubuntu服务器 windows客户端 虚拟机
最近自己配置了一下Git,虽然网上相关的内容满天飞(ps:大多都差不多,很多都是直接转载,说的也比较乱),但是我还是碰到了很多问题,这里我就把我配置的步骤分享一下,遇到的问题也说一下,新手之间相互学习 ...
- 基于Ajax的前后端分离
这种开发模式可以称为SPA (Single Page Application 单页面应用)时代. 这种模式下,前后端的分工非常清晰,前后端的关键协作点是 Ajax 接口.看起来是如此美妙,但回过头来看 ...
- Java--重载与重写的区别
1.重写必须继承,重载不用.2.重写的方法名,参数数目相同,参数类型兼容,重载的方法名相同,参数列表不同.3.重写的方法修饰符大于等于父类的方法,重载和修饰符无关.4.重写不可以抛出父类没有抛出的一般 ...
- [PXE] Linux(centos6)中PXE 服务器搭建,PXE安装、启动及PXE理论详解
[PXE] Linux(centos6)中PXE 服务器搭建,PXE安装.启动及PXE理论详解 本篇blog主要讲述了[PXE] linux(centos)PXE无盘服务器搭建,安装,启动及pxe协议 ...
- 算法-一步步教你如何用c语言实现堆排序(非递归)
看了左神的堆排序,觉得思路很清晰,比常见的递归的堆排序要更容易理解,所以自己整理了一下笔记,带大家一步步实现堆排序算法 首先介绍什么是大根堆:每一个子树的最大值都是子树的头结点,即根结点是所有结点的最 ...