Resolving PromptForFamilyInstancePlacement Error in Revit API
Reference
Here are some solutions using hooks to cancel, but they failed in my function. Record here for researching failure reasons later.
Revit secondary development knowledge sharing (12) Sending Esc key to Revit
How to listen to keyboard events in RevitConsulted SDK content, but also failed to run. Put it here to see if there is any inspiration later.
1 | // Use custom Revit drag and drop behavior |
Solution
https://thebuildingcoder.typepad.com/blog/2017/05/prompt-cancel-throws-exception-in-revit-2018.html
https://forums.autodesk.com/t5/revit-api-forum/revit-2018-api-undocumented-changes-have-you-found-any/m-p/7074819
Jimmy analyzed why it was modified and the current solution in the article. Using try-catch to capture can complete the operation before 2017. It was because the Autodesk development engineer felt that the user double-clicking Esc to cancel would cause some misoperations, so OperationCanceledException error was added to avoid this. For other discussions, please refer to the two reference URLs above.
Since I know why the error occurs, simply adding a try-catch can solve this problem. This problem lasted from 5:30 pm to 9:00 pm. I kept trying to use hooks to operate on this, but for some reason, the hook can normally display user keyboard input but cannot perform double-click Esc operation, and binding documentchanged will also cancel directly, which cannot be handled logically either. In short, it was a mess. Below is the very simple solution.
1 | try |
This ensures normal placement and completion when the user double-clicks Esc to cancel.







