Need help with how to link a *.rvt via Revit 2012 api (C#)?

Need help with how to link a *.rvt via Revit 2012 api (C#)?

adywren
Contributor Contributor
1,357 Views
4 Replies
Message 1 of 5

Need help with how to link a *.rvt via Revit 2012 api (C#)?

adywren
Contributor
Contributor

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 ?

 

 

 

 

0 Likes
1,358 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

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...

0 Likes
Message 3 of 5

Anonymous
Not applicable

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

0 Likes
Message 4 of 5

Anonymous
Not applicable

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. 

0 Likes
Message 5 of 5

Joe.Ye
Alumni
Alumni

 

Hope this post in Jeremy's blog helps

 

Access Central File TransmissionData on Revit Server

http://thebuildingcoder.typepad.com/blog/2011/11/access-transmissiondata-of-central-file-on-revit-se...



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
0 Likes