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: 

Update Linked Files Path

1 REPLY 1
Reply
Message 1 of 2
john.allanjones
1552 Views, 1 Reply

Update Linked Files Path

 

Hello,

 

I am trying to update an linked files path in Revit 2014 using a IExternalApplication. This code runs all the way trough with no errors but the link is not changed, It dosen't seem to actually commit the changes, any suggestions please ?

 

Many thanks in advance

 

 

 

 private static void LinksUpdate(ModelPath path, DocRvt doc)
        {
            // access transmission data in the given Revit file
            TransmissionData transData = TransmissionData.ReadTransmissionData(path);
            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)
                    {
                        bool ShouldLoad;
                        if (extRef.GetLinkedFileStatus().ToString() == "Loaded")
                        {
                            ShouldLoad = true;
                        }
                        else
                        {
                            ShouldLoad = false;
                        }

                        using (Transaction trans = new Transaction(doc, "Links Updater"))
                        {
                            trans.Start();

                            ModelPath ExsiitngModelPath = extRef.GetAbsolutePath();
                            string ExistingStringPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(ExsiitngModelPath);

                            string NewStringPath = ExistingStringPath.Replace(@"Testing\A", @"Testing\B");

                            ModelPath NewPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(NewStringPath);
                            PathType NewPathType = PathType.Relative;

                            transData.SetDesiredReferenceData(refId, NewPath, NewPathType, ShouldLoad);
                            transData.IsTransmitted = true;

                            TransmissionData.WriteTransmissionData(path, transData);
                            
                            trans.Commit();
                        }
                    }
                }                
            }
            else
            {
                TaskDialog.Show("Unload Links", "The document does not have any transmission data");
            }
        }

 

1 REPLY 1
Message 2 of 2

Dear John,

 

Thank you for your query.

 

I am pretty sure that you do not need to open or commit any transactions for this operation, since the TransmissionData is not a Revit database element.  The call to WriteTransmissionData takes care of saving the data back to the external file.

 

I think the TransmissionData is part of the external file.

 

From you question, you seem to want to update the link to it saved in the currenly open Revit project.

 

For that, you should probably be looking at the RevitLinkInstance class instead, which represents an instance of a RevitLinkType, i.e., a linked file within the project.

 

Here is an old post of its path property:

 

http://adndevblog.typepad.com/aec/2012/10/accessing-linked-file-path-information-using-revit-net-api...

 

The ExternalFileReference.GetPath method read and returns the path of the link, relative or absolute according to the link's settings

 

That all seems to be read-only, though.

 

Somebody seems to have tried to achieve the same as you in the past:

 

http://forums.autodesk.com/t5/revit-api/find-and-replace-linked-revit-and-autocad-file-paths/td-p/35...

 

The suggestions there lead back to the transmission data approach.

 

Have you tried modifying the transmission data information without having the project loaded?

 

Maybe the changes that you set up will only be noticeable if the file is not loaded, and you can see the effect next time you load it.

 

I hope this helps.

 

Please let us know how you get on with this and what solution you end up with.

 

Thank you!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

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

Post to forums  

Rail Community


Autodesk Design & Make Report