Check if can delete a view

Check if can delete a view

FrankHolidaytoiling
Advocate Advocate
1,397 Views
5 Replies
Message 1 of 6

Check if can delete a view

FrankHolidaytoiling
Advocate
Advocate

I want to see if a warning is going to be presented to user to say hey, dont delete that view as it will delete view x,y,z as well. I used something similar to this to prevent walls being created with errors, however is there something more staightforward or do i need to get some boolean flag return from a call to the below. it doesnt seem to work as i have to try to delete an object before it rolls back the error.

 

 

private static void SendTransactionToSwallower(Transaction transSwallow)
{
FailureHandlingOptions failOpt = transSwallow.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(new WarningRollback());
failOpt.SetClearAfterRollback(true);
transSwallow.SetFailureHandlingOptions(failOpt);
}

class WarningRollback : IFailuresPreprocessor
{
FailureProcessingResult IFailuresPreprocessor.PreprocessFailures(FailuresAccessor a)
{
IList<FailureMessageAccessor> failures = a.GetFailureMessages();

foreach (FailureMessageAccessor f in failures)
{
FailureSeverity fseverity = a.GetSeverity();

a.ResolveFailure(f);
return FailureProcessingResult.ProceedWithRollBack;

}
return FailureProcessingResult.Continue;
}

}

0 Likes
Accepted solutions (3)
1,398 Views
5 Replies
Replies (5)
Message 2 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @FrankHolidaytoiling ,

I think Postfailure is what you are looking for

https://www.revitapidocs.com/2015/5d25d459-a1b0-eef4-4766-b00bd1f5ba79.htm 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 6

FrankHolidaytoiling
Advocate
Advocate
Accepted solution

Hi Kumar,

How can I use this code to find if a warning is generated after I delete say a view with one or more callouts. So I can set a flag to say cant delete view or can delete view in the calling code?

0 Likes
Message 4 of 6

Moustafa_K
Collaborator
Collaborator
Accepted solution

Hi

AFAIK I think it is not possible something similar was raised here:

https://forums.autodesk.com/t5/revit-api-forum/iupdater-needs-ondeleting-trigger-changetype/td-p/792...

Indeed your idea is great and valid, especially there is no Undo feature if a view is deleted. if a view is deleted, it is gone forever, unless you did not save. it would be great if we can extract back the deleted view from the original file before saving via API and UI as well.

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 5 of 6

KSDA174502195
Explorer
Explorer
Problem solved?
Message 6 of 6

FrankHolidaytoiling
Advocate
Advocate

Is there a failure that is reported if on deleting a view another view will be deleted because it is not referenced in any other views?

FailureDefinitionId id = f.GetFailureDefinitionId();
if (BuiltInFailures.SomeFailureClasses.ASpecificFailureType == id)
{

}

0 Likes