ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

C# 通过COM接口实现导入外部块功能

2022-04-07 13:32:05  阅读:55  来源: 互联网

标签:ActiveDocument C# double acadApp insertionPoint dbxDoc 导入 new COM


private void btnBlock_Click(object sender, EventArgs e)
{

double[] insertionPoint = new double[3];
insertionPoint[0] = 0;
insertionPoint[1] = 0;
insertionPoint[2] = 0.0;
string progid = "ObjectDBX.AxDbDocument.22";
dbx.AxDbDocument dbxDoc;
dbxDoc = (dbx.AxDbDocument)m_acadApp.GetInterfaceObject(progid);
dbxDoc.Open("F:\\Testblock.dwg");//包含多个块的文件
AcadBlock block = (AcadBlock)dbxDoc.Blocks.Item("Testblock");//Testblock 该块只是文件中的其中一个,可以将其参数化
AcadObject[] obj = new AcadObject[1];
obj[0] = (AcadObject)block;
AcadExternalReference xrefInserted;
xrefInserted = dbxDoc.CopyObjects(obj, m_acadApp.ActiveDocument.Database.Blocks);//将块信息拷贝到当前块集合中
m_acadApp.ActiveDocument.ModelSpace.InsertBlock(insertionPoint, "Testblock", 1, 1, 1, 0);//插入到当前文件
m_acadApp.ZoomAll();
}

//创建块并插入块参照

double[] insertionPoint = new double[3];
insertionPoint[0] = 0;
insertionPoint[1] = 0;
insertionPoint[2] = 0.0;
AcadBlock destBlock = m_acadApp.ActiveDocument.Blocks.Add(insertionPoint, "TestBlock");
double[] startPoint = new double[3] { 0, 0, 0 };
double[] endPoint = new double[3] { 100, 100, 100 };
destBlock.AddLine(startPoint, endPoint);
m_acadApp.ActiveDocument.ModelSpace.AttachExternalReference(pathname, "TestBlock", insertionPoint, 1, 1, 1, 0, false);
m_acadApp.ZoomAll();
m_acadApp.Application.Update();

 

 

标签:ActiveDocument,C#,double,acadApp,insertionPoint,dbxDoc,导入,new,COM
来源: https://www.cnblogs.com/yingwu/p/16111805.html

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有