Reload Link CAD

Reload Link CAD

Anonymous
Not applicable
2,185 Views
13 Replies
Message 1 of 14

Reload Link CAD

Anonymous
Not applicable

Hi there,

 

I wonder if we could programmatically reload linked CAD in Revit

 

This need comes from my actual works since I usually reload linked CAD to keep track of the changes every time the linked CAD is revised. And I found it extremely annoying when I need to repeatedly open the Manage Links >> switch to CAD Formats >> find a link in the very long list of Linked CAD >> Reload

 

I skimmed through many posts related to this issue but none of them seem to be able to address this issue

 

I am playing around with the outline idea shown in the below code

Hope to some can help me out

 

Thank you

Nguyen Duy Hoa

 

 

 

public void ReloadLinkedCAD(Document doc)
{
	IList<ImportInstance> importIntaces = new FilteredElementCollector(doc).OfClass(typeof(ImportInstance)).Cast<ImportInstance>().Where(i => i.IsLinked == true).ToList();            
	using (Transaction t = new Transaction(doc, "Reload Imports"))
	{
		t.Start();
		foreach (ImportInstance ints in importIntaces)
		{
			if (ints.Category.Name.EndsWith(".dwg"))
			{
				ElementId typeId = ints.GetTypeId();
				CADLinkType cadLink = doc.GetElement(typeId) as CADLinkType;
				//How to reload cadLink?
			}
		}
		t.Commit();
	}
}
0 Likes
2,186 Views
13 Replies
Replies (13)
Message 2 of 14

jeremytammik
Autodesk
Autodesk

Dear Duy Hoa,

 

Read the Revit API Help file RevitAPI.chm:

 

RevitLinkType.LoadFrom Method (ModelPath, WorksetConfiguration)

 

Loads or reloads the Revit link from disk. The link will be loaded from the input path.

 

Best regards,

 

Jeremy



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

0 Likes
Message 3 of 14

Anonymous
Not applicable

Dear Mr. Jeremy,

 

Thank you for your sugestion

 

You are perfectly correct in your reply that we can programmatically reload RevitLinkType instances, however, what I want to reload is CadLinkType (not RevitLinkType), this is where the problem lie

 

I had cheked the RevitAPI.chm and found that CadLinkType class is not equipped with any method for loading or reloading

 

May I have any other advices?

 

Thank you

Nguyen Duy Hoa

0 Likes
Message 4 of 14

Audun_Opdal
Explorer
Explorer

Hi,

 

Did you find any solution on this ?

 

Regards,

Audun

0 Likes
Message 5 of 14

jeremytammik
Autodesk
Autodesk

Dear Duy and Audun,

 

I am checking with the development team.

 

Thank you for your patience.

 

Cheers, 

 

Jeremy



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

0 Likes
Message 6 of 14

Anonymous
Not applicable

Dear Mr. Jeremy,

 

Thank you for your attention

 

This matter is such a need in my routine job
Please inform us when you get the solution


Look forward to hearing good news from you

 

Thank you,

Nguyen Duy Hoa

0 Likes
Message 7 of 14

jeremytammik
Autodesk
Autodesk

Dear Nguyen Duy Hoa,

 

The development team reply:

 

You cannot currently reload CADLinkType directly in any released version.

 

You can however use the TransmissionData class to request a “reload from this new file the next time I open the document”:

 

http://thebuildingcoder.typepad.com/blog/2011/03/many-issues-resolved.html

 

http://thebuildingcoder.typepad.com/blog/2011/10/using-the-writetransmissiondata-method.html

 

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

 

I hope this helps.

 

Best regards

 

Jeremy



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

0 Likes
Message 8 of 14

Anonymous
Not applicable

Dear Mr. Jeremy,

 

Thank you for your endeavor in finding the reply for my concerned issue
I will give that a try and will inform you the result later

 

Best Regards,

Nguyen Duy Hoa

0 Likes
Message 9 of 14

Anonymous
Not applicable

Any chance this has changed in the last 4 years?

This function is the only piece I'm missing in a revision control project.

Thanks

0 Likes
Message 10 of 14

Anonymous
Not applicable
Message 11 of 14

Anonymous
Not applicable

Hi

I want to reload a CAD Link from an other path (the File Server have got at new name:- ), but can't make it work

Is that not possible or do I make somethoing wrong ??

NewPath is the fullpath to the CAd file

 

 foreach (CADLinkType CADtypeLink in CADlinkInstances)
 {
       ExternalFileReference er = CADtypeLink.GetExternalFileReference();
       ModelPath mp = er.GetPath();
       string userVisiblePath = ModelPathUtils.ConvertModelPathToUserVisiblePath(mp);
       String NewPath = userVisiblePath.Replace(Paths[0], Paths[1]);

        if (!File.Exists(NewPath))
        {
            MissingPaths.Add(NewPath);
         }
         else
         {
              LinkLoadResult CAD_LLR  = CADtypeLink.LoadFrom(NewPath);
         }
}
 
Regards Anders
0 Likes
Message 12 of 14

Anonymous
Not applicable

@Anonymous 

Are the current paths relative?

I'm not sure how you're constructing 'Paths', but you might need to call some MakeAbsolute() function on Paths[1] before userVisiblePath.Replace().

 

From documentation for CADLinkType.LoadFrom (my underline):

 

Parameters

path Type: System String
A path on disk giving the location of the linked file. This path must be absolute. The link's path will remain PathType.Absolute or PathType.Relative, whichever it was before. If the link was previously to an external server location, the path type will be relative.

 

0 Likes
Message 13 of 14

Anonymous
Not applicable

Hi

Thanks, is helped to set the path to absolut, in Revit before making the changes 😉

 

Transaction Tr = new Transaction(doc, "Change Paths");
Tr.Start();

foreach (CADLinkType CADtypeLink in CADlinkInstances)
{
ExternalFileReference er = CADtypeLink.GetExternalFileReference();
ModelPath mp = er.GetAbsolutePath();

string userVisiblePath = ModelPathUtils.ConvertModelPathToUserVisiblePath(mp);
String NewPath = userVisiblePath.Replace(Paths[0], Paths[1]); // replacing the old servername with the new servername

if (!File.Exists(NewPath))
{
MissingPaths.Add(NewPath); // making a list of missing paths
}
else
{
try
{
LinkLoadResult CAD_LLR = CADtypeLink.LoadFrom(NewPath);
}
catch (Exception ex)
{
TaskDialog.Show("Error", ex.ToString());
}
}
}

Tr.Commit();

Message 14 of 14

Anonymous
Not applicable

Hi @Anonymous , How about the method to reload a cad link in the version of 2016 ?

0 Likes