def METHOD_NAME(new_item, name=None):
    subject = new_item.subject
    if name:
        subject.name = new_item.diagram.gettext("New {name}").format(name=name)
    if subject.container:
        return
    diagram = new_item.diagram
    package = owner_package(diagram.owner)
    state_machines = (
        [i for i in package.ownedType if isinstance(i, UML.StateMachine)]
        if package
        else diagram.model.lselect(
            lambda e: isinstance(e, UML.StateMachine) and e.package is None
        )
    )
    if state_machines:
        state_machine = state_machines[0]
    else:
        state_machine = subject.model.create(UML.StateMachine)
        state_machine.name = new_item.diagram.gettext("State Machine")
        state_machine.package = package
    if state_machine.region:
        region = state_machine.region[0]
    else:
        region = subject.model.create(UML.Region)
        region.stateMachine = state_machine
    subject.container = region