How Do I Conditionally Block Executing PostableCommand.LinkSomething?

How Do I Conditionally Block Executing PostableCommand.LinkSomething?

structure1EKNKU
Enthusiast Enthusiast
192 Views
1 Reply
Message 1 of 2

How Do I Conditionally Block Executing PostableCommand.LinkSomething?

structure1EKNKU
Enthusiast
Enthusiast

Hi!

 

In the plugin (C#, .NET) I would like to monitor the fact that the user attempts to insert a Revit Link, PDF Link, or a CAD Link and this is quite easily doable by CreateAddInCommandBinding and BeforeExecuted.

 

However, I would also like to block this option, as if I had assigned an empty function to the AddInCommandBinding.Executed, but I would like to do it conditionally, if and only if the file attempted to be linked is bigger than the pre-defined filesize or its name contains any non-ASCII characters.

 

My questions are in fact two:

1. Where do I check the system information about the file which is attempted to be linked (I mean: where is this data stored? So far I've been looking through the members and nested members of Element in a loop through all Elements added or modified in DocumentChangedEvent raised right after linking the file but no success)?

2. How and where do I setup a condition that, after the check, blocks the further execution of PostableCommand or not?

193 Views
1 Reply
Reply (1)
Message 2 of 2

RPTHOMAS108
Mentor
Mentor

I think you need to go down another route. The path information is available but only after it has been inserted.

 

With the command binding you are aiming to block the command that inserts it.

 

Probably a better option is to implement IUpdater to remove the link or post failure during update that forces the transaction to be rolled back. However it depends on when path becomes available in the project. Would have to see if it can be found with below methods during the update (IUpdater.Execute). If not available may have to wait until after transaction is committed i.e. find it some other way to remove it.

 

See also

ExternalFileUtils.GetAllExternalFileReferences => collection of ElementId
ExternalFileUtils.GetExternalFileReference(Elementid)
ExternalFileReference.GetPath => ModelPath & ModelPathUtils
or
ExternalFileReference.GetAbsolutePath