Hello,
I have linked a few drawing files to the Revit file and set Path as Absolute.
Now I have moved all the Revit files and linked drawing files to some other directory and opened the main Revit file programmatically.
I have written below code to resolve links before opening the file but my code is throwing exception at LaodFrom API.
Could you help me why it is throwing an exception ("An internal error has occurred.")?
am I doing anything wrong here?
private bool ResolveCADFileLinks(string iPath)
{
bool bSucceeded = true;
try
{
Document document = null;
DocumentSet documentSet = _uiapp.Application.Documents;
foreach (Document pDocument in documentSet)
{
if (String.Equals(iPath.ToLower(), pDocument.PathName.ToLower()))
{
document = pDocument;
break;
}
}
if (document == null)
{
document = _app.OpenDocumentFile(iPath);
}
string sCheckoutPath = "C:\temp";
if (document != null)
{
FilteredElementCollector linksCollector = new FilteredElementCollector(document).OfClass(typeof(CADLinkType));
int nCount = linksCollector.GetElementCount();
foreach (Element e in linksCollector)
{
if (e is CADLinkType)
{
CADLinkType cadLinkType = e as CADLinkType;
ExternalFileReference externalFile = e.GetExternalFileReference();
LinkedFileStatus linkedFileStatus = externalFile.GetLinkedFileStatus();
if (linkedFileStatus == LinkedFileStatus.NotFound)
{
string fileName, extAbsPath, newFilePath;
extAbsPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(externalFile.GetAbsolutePath());
fileName = Path.GetFileName(extAbsPath);
newFilePath = Path.Combine(sCheckoutPath, fileName);
LinkLoadResult linkLoadResult = cadLinkType.LoadFrom(newFilePath);
}
}
}
linksCollector.Dispose();
}
}
catch (Autodesk.Revit.Exceptions.ArgumentNullException ex)
{
bSucceeded = false;
MessageBox.Show(ex.ToString());
}
catch (FileArgumentNotFoundException ex)
{
bSucceeded = false;
MessageBox.Show(ex.ToString());
}
catch (Autodesk.Revit.Exceptions.InvalidOperationException ex)
{
bSucceeded = false;
MessageBox.Show(ex.ToString());
}
catch (Exception ex)
{
bSucceeded = false;
MessageBox.Show(ex.ToString());
}
return bSucceeded;
}
I think there is no overload of LoadFrom with one argument.
The available options are as follows:
LoadFrom(ExternalResourceReference resourceReference, WorksetConfiguration config)
LoadFrom(ModelPath path, WorksetConfiguration config)
with the second argument WorksetConfiguration object indicating which worksets in the link to open.
If you want to load the same set of worksets the link previously had, leave this argument as a null reference.(as per the documentation). Maybe you could pass a second argument as null.
I hope this helps
Hello Caroline,
Thanks for the reply.
Here LoadFrom API has two argument is for RevitLinkType.
But I am facing an issue with CADLinkType. Where LoadFrom API has one argument only.
For reference please check the below link.
https://www.revitapidocs.com/2021.1/41db0b8b-4bd4-02b0-f06a-a7a169802e1b.htm
Thanks
Can't find what you're looking for? Ask the community or share your knowledge.