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

2022/4/7 14:19:04

本文主要是介绍C# 通过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();

 

 



这篇关于C# 通过COM接口实现导入外部块功能的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程