Command-exec hook

Thanks but unfortunately that results in the same issue (looping of the replaced command being posted by itself) which I think is because command-exec hooks replace the PostableCommand at all references so the default command can’t be posted.

This is a hook which disables Import CAD in .rvt files. Import CAD is necessary in some rare cases (mostly .rfa files) and I can’t get that bit to work.

If you want to try it this is the code from a command-exec[ID_FILE_IMPORT] hook:

from pyrevit import script, revit
from Autodesk.Revit.UI import UIApplication, RevitCommandId, PostableCommand

doc = revit.doc
uiapp = UIApplication(doc.Application)
count = []
if not doc.IsFamilyDocument:
    output = script.get_output()
    output.resize(100, 300)
    output.set_title('Forbidden')
    output.print_md('NEVER import CAD to Revit projects. Use Link CAD.')
else:
    found_id = RevitCommandId.LookupPostableCommandId(PostableCommand.ImportCAD)
    uiapp.PostCommand(found_id)