简体   繁体   English

Revit:在链接的模型中设置类型参数

[英]Revit: Set type parameter in linked models

Our Revit Add-In lets the user browse and set type parameters, including those in linked models. 我们的Revit加载项允许用户浏览和设置类型参数,包括链接模型中的参数。 It worked fine in Revit 2011 and earlier, but in Revit 2012 and 2013 we can no longer set these. 在Revit 2011及更早版本中,它工作正常,但在Revit 2012和2013中,我们无法再进行设置。 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.)" 在链接文档上构造事务时,我得到:“ Autodesk.Revit.Exceptions.ArguementException:文档是链接文件。事务只能在主文档(项目或族)中使用。”

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? 无法在链接模型上创建事务,也不能在事务外部修改模型-那么如何在Revit 2012/2013中修改链接模型? It worked fine in 2011 with the same code. 使用相同的代码,它在2011年运行良好。 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. 在包括The Building Coder博客在内的网上进行了大量搜索,但没有提及这一重大更改或如何解决。 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. 同样,相同的代码在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. 从Revit 2014开始,您可以卸载链接的文件。 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();

I started work with Revit 2012 and didn't know the behavior with the transactions in linked files. 我开始使用Revit 2012,但不知道链接文件中事务的行为。 But I also needed set parameter to the linked files and didn't find the way how to do it properly. 但是我还需要将参数设置为链接文件,却找不到正确执行方法。 And the RevitAPI help tells Transactions can only be used in primary documents (projects or families.) 而且RevitAPI帮助告诉Transaction只能在主文档(项目或系列)中使用。

I can guess that setting parameters in the linked file in the Revit 2011 was a bug, not a feature, because it is potentially unsafe. 我可以猜测,在Revit 2011中的链接文件中设置参数是一个错误,而不是功能,因为它可能不安全。

2 years later...I think you'll have to open the document in question, make it the activedocument and then try applying the code you want in there. 2年后...我想您必须打开有问题的文档,将其设置为activedocument,然后尝试在其中应用所需的代码。 if you need a code example, let me know and i'll try and whip something up 如果您需要一个代码示例,请让我知道,我将尝试整理一下

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM