revit two open the Transfer Project Standards (ElementTransformUtils.CopyElements)

Disclaimer: This article from the dark knight の creation, please indicate the source, the exchange qq1056291511 https://blog.csdn.net/birdfly2015/article/details/91047860

One, background

Small partners in the Revit secondary development, you may need to pass a document family, family instance, or other information to another project, this time we manually via Transfer Project Standards implementation. The following figure:
Here Insert Picture DescriptionSo how do we achieve it through the program?

Second, Solutions

Use ElementTransformUtils CopyElements class method, this method has three overloads, it can actually be selected according to the particular overload mode. Here replication material information to bloggers example, description of its use.

Third, the Code

//打开存储我们需要信息的文档
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document document = uidoc.Document;
//建立一个集合类(CopyElements需要的参数类型为ICollection)
ICollection<ElementId> copyIds = new Collection<ElementId>();
//这个是博主自己写的过滤方法,得到当前文档中所有混凝土的材质信息
IEnumerable<Element> elementList = CopyMaterialFromDocToDoc.FilterMutilElement(document, typeof(Material), "混凝土");
//将得到的单元信息Id添加到刚才定义好的copyIds 中
foreach (Element ele in elementList)
{
    copyIds.Add(ele.Id); 
}
//打开需要接受这些单元的文档
string file=@"需要接受这些单元的文档xxx"
Document doc = document.Application.OpenDocumentFile(file);
//开启单元传递事物
Transaction trans = new Transaction(doc, "传递单元");
trans.Start();
//实例化复制粘贴选项,这里实例化就行
CopyPasteOptions option = new CopyPasteOptions();
//由于材料信息与位移无关,所以位移为null,如果是族实例或者其他与位置有关的,这个地方就需要思考下设置了
ElementTransformUtils.CopyElements(document, copyIds, doc, null, option);
trans.Commit();
//保存关闭修改后的文档
doc.Save();
doc.Close(false);

IV Notes

1. Document here to correspond to each other, or will not pass a faulty units, such as family correspondence and documents to family documents, project documentation and project documentation to correspond, not correspond staggered;
2. Hello everyone, I am a nightのKnight, Welcome to the concern of my blog, I will continue to output revit secondary development and programming dry

Guess you like

Origin blog.csdn.net/birdfly2015/article/details/91047860