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: 

Handle DocumentCorruption error when linking IFC

0 REPLIES 0
Reply
Message 1 of 1
antonio90rodriguez
199 Views, 0 Replies

Handle DocumentCorruption error when linking IFC

antonio90rodriguez
Participant
Participant

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.

antonio90rodriguez_0-1662910600895.png

 

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. 

antonio90rodriguez_1-1662910963525.png

 

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?

0 Likes

Handle DocumentCorruption error when linking IFC

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.

antonio90rodriguez_0-1662910600895.png

 

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. 

antonio90rodriguez_1-1662910963525.png

 

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?

Labels (6)
0 REPLIES 0

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

Post to forums  

Autodesk Design & Make Report