Hi there!
I am trying to link an IFC model into a Revit file, from an add-in, by using the following code extracted from a dynamo node in the Genius Loci package.
IFCImportOptions ifcImportOptions = new IFCImportOptions();
ifcImportOptions.Intent = IFCImportIntent.Reference;
ifcDoc = app.OpenIFCDocument(ifcFiles.First(), ifcImportOptions);
SaveAsOptions saveAsOptions = new SaveAsOptions();
saveAsOptions.OverwriteExistingFile = true;
RevitLinkOptions revitLinkOptions = new RevitLinkOptions(true);
string rvtFilePath = ifcFiles.First() + ".rvt";
ifcDoc.SaveAs(rvtFilePath, saveAsOptions);
ifcDoc.Close(false);
LinkLoadResult ifcLoadResult = RevitLinkType.CreateFromIFC(doc, ifcFiles.First(), rvtFilePath, false, revitLinkOptions);
The code works like a charm, but Revit throws the following error message.
From dynamo I would manually click on `Continue Without Save` and the process of linking the IFC will continue and complete successfully.
The problem comes when I use that code inside an `IExternalEventHandler` for my Revit add-in `IExternalCommand`, as the error can't be handled until the entire add-in code has finish running. Therefore when the code reaches line 9 `SaveAs()`, it fails as there is an active Error that can't be omitted.
I have tried to handle the error from `App.cs` with the following code but without luck, and I can see that the default resolution is `Save File And Continue` which doesn't work in this case, I need to be able to programatically resolve the error with the `Continue Without Save`.
private void CheckWarnings(object sender, FailuresProcessingEventArgs e)
{
FailuresAccessor accessor = e.GetFailuresAccessor();
FailureHandlingOptions op = accessor.GetFailureHandlingOptions();
op.SetForcedModalHandling(false);
accessor.SetFailureHandlingOptions(op);
IList<FailureMessageAccessor> failList = accessor.GetFailureMessages(); // Inside event handler, get all warnings
foreach (FailureMessageAccessor failure in failList)
{
// check FailureDefinitionIds against ones that you want to dismiss,
FailureDefinitionId failID = failure.GetFailureDefinitionId();
// prevent Revit from showing Unenclosed room warnings
if (failure.GetSeverity() == FailureSeverity.DocumentCorruption)
{
e.SetProcessingResult(FailureProcessingResult.ProceedWithCommit);
}
}
e.SetProcessingResult(FailureProcessingResult.Continue);
}
Any ideas on how can I do that?
Hi there!
I am trying to link an IFC model into a Revit file, from an add-in, by using the following code extracted from a dynamo node in the Genius Loci package.
IFCImportOptions ifcImportOptions = new IFCImportOptions();
ifcImportOptions.Intent = IFCImportIntent.Reference;
ifcDoc = app.OpenIFCDocument(ifcFiles.First(), ifcImportOptions);
SaveAsOptions saveAsOptions = new SaveAsOptions();
saveAsOptions.OverwriteExistingFile = true;
RevitLinkOptions revitLinkOptions = new RevitLinkOptions(true);
string rvtFilePath = ifcFiles.First() + ".rvt";
ifcDoc.SaveAs(rvtFilePath, saveAsOptions);
ifcDoc.Close(false);
LinkLoadResult ifcLoadResult = RevitLinkType.CreateFromIFC(doc, ifcFiles.First(), rvtFilePath, false, revitLinkOptions);
The code works like a charm, but Revit throws the following error message.
From dynamo I would manually click on `Continue Without Save` and the process of linking the IFC will continue and complete successfully.
The problem comes when I use that code inside an `IExternalEventHandler` for my Revit add-in `IExternalCommand`, as the error can't be handled until the entire add-in code has finish running. Therefore when the code reaches line 9 `SaveAs()`, it fails as there is an active Error that can't be omitted.
I have tried to handle the error from `App.cs` with the following code but without luck, and I can see that the default resolution is `Save File And Continue` which doesn't work in this case, I need to be able to programatically resolve the error with the `Continue Without Save`.
private void CheckWarnings(object sender, FailuresProcessingEventArgs e)
{
FailuresAccessor accessor = e.GetFailuresAccessor();
FailureHandlingOptions op = accessor.GetFailureHandlingOptions();
op.SetForcedModalHandling(false);
accessor.SetFailureHandlingOptions(op);
IList<FailureMessageAccessor> failList = accessor.GetFailureMessages(); // Inside event handler, get all warnings
foreach (FailureMessageAccessor failure in failList)
{
// check FailureDefinitionIds against ones that you want to dismiss,
FailureDefinitionId failID = failure.GetFailureDefinitionId();
// prevent Revit from showing Unenclosed room warnings
if (failure.GetSeverity() == FailureSeverity.DocumentCorruption)
{
e.SetProcessingResult(FailureProcessingResult.ProceedWithCommit);
}
}
e.SetProcessingResult(FailureProcessingResult.Continue);
}
Any ideas on how can I do that?
Can't find what you're looking for? Ask the community or share your knowledge.