Is it possible to disable a command similar to the SDK sample? I tried converting to python but not working. The command is still available. I’ve seen an example of IFamilyLoadOptions in python so wondered if it was possible w/this interface. Thanks
class Application(UI.IExternalApplication):
#s_commandId = "ID_FILE_IMPORT"
s_commandId = "ID_EDIT_DESIGNOPTIONS"
# Implements the OnStartup event
def OnStartup(self, application):
# Lookup the desired command by name
s_commandId = UI.RevitCommandId.LookupCommandId(self.s_commandId)
# Confirm that the command can be overriden
if not s_commandId.CanHaveBinding:
self.ShowDialog("Error", "The target command " + self.s_commandId + " selected for disabling cannot be overridden")
return UI.Result.Failed
# Create a binding to override the command.
# Note that you could also implement .CanExecute to override the accessibiliy of the command.
# Doing so would allow the command to be grayed out permanently or selectively, however,
# no feedback would be available to the user about why the command is grayed out.
try:
commandBinding = application.CreateAddInCommandBinding(s_commandId)
commandBinding.Executed += self.DisableEvent
except:
self.ShowDialog("Error", "This add-in is unable to disable the target command " + self.s_commandId + "; most likely another add-in has overridden this command.")
return UI.Result.Succeeded
# Implements the OnShutdown event
def OnShutdown(self, application):
s_commandId = UI.RevitCommandId.LookupCommandId(self.s_commandId)
# Remove the command binding on shutdown
if s_commandId.HasBinding:
application.RemoveAddInCommandBinding(s_commandId)
return UI.Result.Succeeded
# A command execution method which disables any command it is applied to (with a user-visible message).
def DisableEvent(self, sender, args):
self.ShowDialog("Disabled", "Use of this command has been disabled man.")
# Show the user a message
def ShowDialog(title, message):
td = UI.TaskDialog(title)
td.MainInstruction = message
td.TitleAutoPrefix = False
td.Show()
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
myApp = Application()
OUT = myApp
TransactionManager.Instance.TransactionTaskDone()