Revit link Reload from

Revit link Reload from

mgutierrezBM9E9
Contributor Contributor
272 Views
2 Replies
Message 1 of 3

Revit link Reload from

mgutierrezBM9E9
Contributor
Contributor

 

List<Element> rvtLinks = new FilteredElementCollector(doc).OfClass(typeof(RevitLinkInstance))
.ToList();

foreach (Element link in rvtLinks)
{
RevitLinkType linkType = link as RevitLinkType;
if (linkType != null)
{

LinkLoadResult loadResult = linkType.LoadFrom(newModelPath, new WorksetConfiguration());

}
else if (link.Name.Contains("Record EC -"))
{
RevitLinkOptions linkOptions = new RevitLinkOptions(false);

LinkLoadResult loadResult = RevitLinkType.Create(doc, newModelPath, linkOptions);
LogTrace($"modelPath directory: {loadResult.ElementId}");

}
//Document linkDoc = link.GetLinkDocument();
}

 


I'm collecting my linked models and I'm interested in the cases where the link as RevitLinkType return null values as those are the ones that I wish to reload from a local path, particularly for the following 2nd listed model:

 

mgutierrezBM9E9_0-1733417625643.png

I have not found a way to achieve that. All I can do so far with null values is to create a new revit link type. However, this does not fix the issue because the outcome is a revit file linked to the root model at a default location. Instead, I only want to reload them since those models have been already moved and aligned at a certain position.

 

How can I use the "reload from" command for those listed linked models??

0 Likes
Accepted solutions (1)
273 Views
2 Replies
Replies (2)
Message 2 of 3

scgq425
Advocate
Advocate
Accepted solution

Hi @mgutierrezBM9E9 :

if you link file change location in main revit file , use this api can reload file and not change the real-location in main revit 

 var revitLinkType = doc.GetElement(333166) as RevitLinkType; // deleted a file and let this link vaild and not found
           var status =  revitLinkType.GetLinkedFileStatus();
           if (status == LinkedFileStatus.NotFound)
           {
               var localPath2 = ModelPathUtils.ConvertUserVisiblePathToModelPath(@"D:\B.rvt");
               revitLinkType.LoadFrom(localPath2,new WorksetConfiguration());
           }

 

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes
Message 3 of 3

mgutierrezBM9E9
Contributor
Contributor

Thanks for answering me. Indeed, Ishould've used RevitLinkType instead of RevitLinkInstance

0 Likes