LoadFrom API is throwing exception for CADLinkType
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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;
}