Open file without links .rvt/.dwg (Revit Server)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I would like to know if it's possible to open revit file without links (rvt, dwg) from Revit Server using a macro. I open several models every day and it is time consuming. I assume that it could look like:
1. Open Revit and run macro (application-level).
2. "Open" window shows up, so I can select the path even if the file is located at Revit Server.
3. File opens without loading links.
I've found an article with a part of code at: https://knowledge.autodesk.com/support/revit/learn-explore/caas/CloudHelp/cloudhelp/2014/ENU/Revit/f...
"Code Region: Unload Revit Links"
I've also found a way to open file with dialog window: https://forums.autodesk.com/t5/revit-api-forum/macro-open-document-as-detach-from-central-and-save-t... (I don't need to save the model, so half of this code is not neccesary). I've tried to build something on my own.
I'm wondering you can help me to take the next step. To be honest, this is the second macro at my lifetime so treat me like a newbie.
/*
* Created by SharpDevelop.
* User:
* Date: 08.10.2022
* Time: 22:25
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace OpenWithoutLinks
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("C86F282B-D3C8-4C78-863D-31735C04068C")]
public partial class ThisApplication
{
private void Module_Startup(object sender, EventArgs e)
{
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
#region Revit Macros generated code
private void OpenFile()
{
OpenFileDialog theDialogRevit = new OpenFileDialog();
theDialogRevit.Title = "Select Revit Project Files";
theDialogRevit.Filter = "RVT files|*.rvt";
theDialogRevit.FilterIndex = 1;
theDialogRevit.InitialDirectory = @"C:\";
theDialogRevit.Multiselect = false;
if (theDialogRevit.ShowDialog() == DialogResult.OK)
}
private void UnloadRevitLinks(ModelPath location)
/// This method will set all Revit links to be unloaded the next time the document at the given location is opened.
/// The TransmissionData for a given document only contains top-level Revit links, not nested links.
/// However, nested links will be unloaded if their parent links are unloaded, so this function only needs to look at the document's immediate links.
{
// access transmission data in the given Revit file
TransmissionData transData = TransmissionData.ReadTransmissionData(location);
if (transData != null)
{
// collect all (immediate) external references in the model
ICollection<ElementId> externalReferences = transData.GetAllExternalFileReferenceIds();
// find every reference that is a link
foreach (ElementId refId in externalReferences)
{
ExternalFileReference extRef = transData.GetLastSavedReferenceData(refId);
if (extRef.ExternalFileReferenceType == ExternalFileReferenceType.RevitLink)
{
// we do not want to change neither the path nor the path-type
// we only want the links to be unloaded (shouldLoad = false)
transData.SetDesiredReferenceData(refId, extRef.GetPath(), extRef.PathType, false);
}
}
// make sure the IsTransmitted property is set
transData.IsTransmitted = true;
// modified transmission data must be saved back to the model
TransmissionData.WriteTransmissionData(location, transData);
}
else
{
Autodesk.Revit.UI.TaskDialog.Show("Unload Links", "The document does not have any transmission data");
}
}
#endregion
public void e()
{
}
}
}
Best Regards
Piotr