Revit中:在链接模型组类型参数 [英] Revit: Set type parameter in linked models

查看:1152
本文介绍了Revit中:在链接模型组类型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的Revit中加载项允许用户浏览和设置参数的类型,包括那些在链接模型。它在2011年Revit和早期工作正常,但在Revit 2012年和2013我们再也不能设置这些。当在链接的文档构建交易我得到:Autodesk.Revit.Exceptions.ArguementException:文档是链接文件的事务只能在主要文件(项目或家庭)用



确定,所以我们不能对链接模型使用事务。所以,我想设置参数没有交易,但后来我得到一个异常说我们不能修改事务之外的模式。



不能创建链接的交易模型,不能修改模型的事务之外 - 那么,如何在Revit 2012/2013修改链接的模式?它在2011年的工作罚款相同的代码。做网上搜索,包括建筑编码器博客相当数量,但没有发现提到这个理由重大更改或如何解决它的。 ?任何人都可以伸出援助之手。



我们的代码很简单 - 我们在模型中得到一个参数,启动一个事务并尝试设置的参数值。再次,相同的代码工作没有错误在2011年的Revit。

  //元素类型是文档的DOC 
的的ElementType //为此我们要设置一个类型参数。
参数typeParameter = elementType.get_Parameter(pararmeterName);
交易的交易=新交易(DOC,更新的Revit类型); //这里异常抛出,如果文档是链接模型
transaction.Start();

typeParameter.Set(FooValue);

器transaction.commit();


解决方案

由于Revit中2014年,您可以卸载链接文件。所以,在开始交易,然后重新装入该交易结束后,之前只是卸载您的文件。

  //卸载所有链接
VAR loadedExternalFilesRef =新的List< RevitLinkType>();
变种收集=新FilteredElementCollector(文件);
的foreach
{
ExternalFileReference extFileRef = element.GetExternalFileReference()(在collector.OfClass(typeof运算(RevitLinkType))元素进行);
如果(空== || extFileRef extFileRef.GetLinkedFileStatus()= LinkedFileStatus.Loaded!)
继续;
VAR revitLinkType =(RevitLinkType)元素;
loadedExternalFilesRef.Add(revitLinkType);
revitLinkType.Unload(NULL);
}

//执行事务中的

//刷新链接
的foreach(RevitLinkType revitLinkType在loadedExternalFilesRef)
revitLinkType你的东西。加载();


Our Revit Add-In lets the user browse and set type parameters, including those in linked models. It worked fine in Revit 2011 and earlier, but in Revit 2012 and 2013 we can no longer set these. When constructing the transaction on the linked document I get: "Autodesk.Revit.Exceptions.ArguementException: Document is a linked file. Transactions can only be used in primary documents (projects or families.)"

OK, so we can't use transactions on linked models. So I tried setting the parameter without a transaction, but then I got an exception saying we cannot modify the model outside of a transaction.

Can't create a transaction on linked models and can't modify a model outside of a transaction--so how does one modify a linked model in Revit 2012/2013? It worked fine in 2011 with the same code. Did a fair amount of searching online including The Building Coder blog, but found no mention of this breaking change or how to work around it. Can anyone lend a hand?

Our code is straightforward--we get a parameter in the model, start a transaction and attempt to set a parameter value. Again the same code works without error in Revit 2011.

// elementType is an ElementType in document doc 
// for which we want to set a type parameter.
Parameter typeParameter = elementType.get_Parameter(pararmeterName);
Transaction transaction = new Transaction(doc, "Update Revit Type"); // Exception thrown here if doc is a linked model
transaction.Start();

typeParameter.Set("FooValue");

transaction.Commit();

解决方案

Since Revit 2014, you can unload the linked files. So just unload your files before starting the transaction, then reload them after the transaction has ended.

// Unload all links
var loadedExternalFilesRef = new List<RevitLinkType>();
var collector = new FilteredElementCollector(document);
foreach (Element element in collector.OfClass(typeof(RevitLinkType)))
{
    ExternalFileReference extFileRef = element.GetExternalFileReference();
    if (null == extFileRef || extFileRef.GetLinkedFileStatus() != LinkedFileStatus.Loaded) 
        continue;
    var revitLinkType = (RevitLinkType)element;
    loadedExternalFilesRef.Add(revitLinkType);
    revitLinkType.Unload(null);
}

// Do your stuff in a transaction

// Reload links
foreach (RevitLinkType revitLinkType in loadedExternalFilesRef)
    revitLinkType.Load();

这篇关于Revit中:在链接模型组类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆