/** @var CExObject $ex_object */
if (!$ex_object_id) {
    $ex_class = new CExClass();
    $ex_class->load($ex_class_id);
    $ex_objects = $ex_class_event->getExObjectForHostObject($object);
    $ex_object = reset($ex_objects);
    if (!$ex_object) {
        $ex_object = $ex_class->getExObjectInstance();
    }
} else {
    $ex_object = new CExObject($ex_class_id);
}
if ($preview) {
    $ex_object->_preview = true;
}
$creation_date = $ex_object->getCreateDate();
if ($object->_id && $object instanceof CSejour) {
    $object->loadRefCurrAffectation($creation_date);
}
$printer_id = null;
$printers = CMediusers::get()->loadRefFunction()->loadBackRefs("printers");
if (count($printers)) {
    $printer = reset($printers);
    $printer_id = $printer->_id;
}
$ex_object->_event_name = $event_name;
// Layout grid
if ($ex_object->_ref_ex_class->pixel_positionning && !$only_filled) {
    $grid = null;
    $out_of_grid = null;
    $groups = $ex_object->_ref_ex_class->getPixelGrid();