Placement Error: "The user aborted the pick operation"

When I try to use uidoc.PromptForFamilyInstancePlacement I can place the family but then once I hit escape the family disappears and this exception is shown: “Exception: The user aborted the pick operation.”

# Oneline Diagram - Pick Picture

# Import libraries
from pyrevit import DB, revit, script, forms, output, UI
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import UIDocument, PostableCommand, RevitCommandId

from System.Collections.Generic import List

# Current document
doc = __revit__.ActiveUIDocument.Document
cView = doc.ActiveView
uidoc = __revit__.ActiveUIDocument
uiapp = uidoc.Application

# ################################################################################
# Debug toggles
globalDebug = True
disabledScript = False


def dprint(*printItems):
    if globalDebug:
        for pI in printItems:
            print(pI)


################################################################################
# Variables
output = output.get_output()
################################################################################

################################################################################
################################################################################
# image selector
################################################################################
################################################################################

path_two = 'L:/Revit/Development/PyRevit/DevTool/image'
dprint(path)

image = forms.select_image(
    script.get_bundle_files(path_two))

# Name
dprint("Name Test:")
name_and_type = image.split("\\")[1].split(".")[0]
family_name = name_and_type.split("!")[0]
dprint(family_name)
family_type = name_and_type.split("!")[1]

dprint(family_type)


################################################################################
################################################################################
# Collect the elements
################################################################################
################################################################################


component_collection = (FilteredElementCollector(doc).
                        OfCategory(DB.BuiltInCategory.OST_DetailComponents).
                        WhereElementIsElementType().
                        ToElements())

family = None
default_type = None

dprint("---===Detail Components===---")
for cc in component_collection:
    if str(cc.GetType()) == 'Autodesk.Revit.DB.FamilySymbol':
        dprint(cc.FamilyName)
        if cc.FamilyName == family_name:
            dprint("--Family Name Matched")
            family = cc
            type_name = DB.Element.Name.__get__(family)
            if type_name == family_type:
                default_type = family
                dprint("----Type Name Matched : " + str(type_name))
                break

dprint(default_type)


uidoc.PromptForFamilyInstancePlacement(default_type)

Is there a “finish” button at the top left instead of pushing escape?

Nope, just grayed out "Load” and “Rotate after placement”.

What type of symbol and what type of view?
uidoc.PromptForFamilyInstancePlacement(default_type) is pretty straightforward.
Your issue is probably outside of your posted code. Is there an open dialog in your code? Modal, non-modal?

..and you will need to place the placement inside a try-catch. Otherwise you keep placing and an escape will be an error.

from Autodesk.Revit.DB import *
from Autodesk.Revit.Exceptions import OperationCanceledException

symbol = next(
    (s for s in FilteredElementCollector(doc).OfClass(FamilySymbol)
     if s.Family.Name == "CMU-2 Core-Section1"),
    None
)

if symbol:
    try:
        uidoc.PromptForFamilyInstancePlacement(symbol)
    except OperationCanceledException:
        pass  # User cancelled with Esc
    except Exception as ex:
        # Ignore other cancellation-related exceptions, re-raise everything else
        if "cancel" not in str(ex).lower():
            raise
1 Like