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: 

LoadFrom API is throwing exception for CADLinkType

3 REPLIES 3
Reply
Message 1 of 4
Harshil.JAINS8RVT
349 Views, 3 Replies

LoadFrom API is throwing exception for CADLinkType

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;
}

Labels (2)
3 REPLIES 3
Message 2 of 4

Hi @Harshil.JAINS8RVT 

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

Carol Gitonga, Developer Advocacy and Support, ADN Open
Message 3 of 4

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

 

Message 4 of 4

Hi @Harshil.JAINS8RVT
Do you solve the problem?

Thanks.

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

Post to forums  

Forma Design Contest


Rail Community