Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

4 REPLIES 4
Reply
Message 1 of 5
adywren
969 Views, 4 Replies

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

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 ?

 

 

 

 

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: adywren

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

Message 3 of 5
Anonymous
in reply to: Anonymous

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

Message 4 of 5
Anonymous
in reply to: Anonymous

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. 

Message 5 of 5
Joe.Ye
in reply to: Anonymous

 

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community