Hi,
I have 'generic model' families placed within a revit project created using c# reading from a *.xml data file. I now which to replace each instance with a linked revit file using the same insertion point. How can I achieve this with revit's api ?
Not sure if possible I would look into TransmissionData > ReadTransmissionData > WriteTransmissionData and see if that achieves what you need. Seems there is more support for linking non rvt links at present. Interested to see how you go...
Loading, unloading and editing path to Revit referenced files is only possible to Revit Rvt file that is closed.
TransmissionData class provides the methods to do the job. If the rvt file is opened, this file cannot be edited by methods in TransmissionData class.
Here is a sample to change the Revit linked model path.
<code_begin>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class Foo : IExternalCommand
{
static AddInId m_appId = new AddInId(new Guid("CF184371-E65A-4a35-BA4F-2959CA87A42D"));
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
Document doc = uidoc.Document;
FilePath location = new FilePath("C:\\file.rvt");
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, new FilePath("C:\\MyNewPath\\cut.rvt"), extRef.PathType, true);
}
}
// 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");
}
return Result.Succeeded;
}
}
<code_end>
Via setting the four parameter of SetDesiredReferenceData() method, we can also set a loaded linked file to be unload, and vice versa
Is there a way to make this work on Revit Server files?
TransmissionData.WriteTransmissionData(serverPath, transData) doesn't work on server files.
And if I modify it on local files they will loose the connection to the central file.
Hope this post in Jeremy's blog helps
Can't find what you're looking for? Ask the community or share your knowledge.