Prevent deletion of elements not on active workset

Prevent deletion of elements not on active workset

jmmiller.southlandind
Enthusiast Enthusiast
920 Views
3 Replies
Message 1 of 4

Prevent deletion of elements not on active workset

jmmiller.southlandind
Enthusiast
Enthusiast

I am exploring the possibility of utilizing  an IUpdater with a custom defined FailureDefinition to try to prevent elements not on a user's active workset from being deleted. I am being inspired by Jeremy Tammik's post on Lock the Model, e.g. Prevent Deletion.   

 

I know on the surface it would seem that what I am seeking to do is not possible. With the most obvious reason being the fact that with using an IUpdater triggered by  Element.GetChangeTypeElementDeletion(), the element is already deleted from the model and as such no information other than the deleted element's ID can be obtained through the IUpdater to allow filtering out elements that should be illegal for deletion to passthrough to the failure message. 

 

However I am hopeful that perhaps there is indeed a way to achieve my goal of preventing deletion of elements not on a user's current active workset. This hope is born from the fact that when a list  of deleted element IDs is  collected  through the IUpdater and added  as failing elements to a failure message the end user is presented with a warning that includes workset information.  see first image below. Below are also images of the very simple IUpdater and Failure Definition used to generate the user warning in seen in the first image. 

 

My questions are why can I see the workset of the deleted element in the warning, but I can not access it in the IUpdater? Is their a way to actually get the workset of the deleted element? Or maybe a back door way I could use the fact that the warning contains the workset of the element to my advantage to achieve my goal?

 

Thanks in advance for any advice or insight anyone is willing to provide. 

 

UserWarningExample.PNG

IUpdater.PNG

 

FailureDef.PNG

 

0 Likes
Accepted solutions (1)
921 Views
3 Replies
Replies (3)
Message 2 of 4

RPTHOMAS108
Mentor
Mentor
Accepted solution

I don't think it is possible for the reasons you outlined. Failure messages are stored separately which is why they indicate Elements no longer with us.

 

There may be an approach with:

UIApplication.CreateAddInCommandBinding
PostableCommand.Delete
AddInCommandBinding.BeforeExecuted

'Check workset of selected elements.
BeforeExecutedEventArgs.Cancel = True

 

There was a similar thing I tested using the above to prompt the user before deleting something, which got really annoying very quickly (when I forgot to delete the .addin file).

 

When Pandora opened that box of hers the only thing left inside was hope, some say it is the cruellest of diseases.

0 Likes
Message 3 of 4

aclarke
Advocate
Advocate

look into the undo features?

deleted items can be brought back with undo, so the info is still there.

Maybe when an element gets deleted and triggers the updater, have the updater activate undo to bring back the deleted element?

 

just thoughts.

0 Likes
Message 4 of 4

jmmiller.southlandind
Enthusiast
Enthusiast

Thanks @RPTHOMAS108 for pointing me to the CommandBinding route. After a little trial and error I was able to successfully get to the end goal I was after. 

0 Likes