Idempotent operations to ensure a datbase object exists.
Attributes
mlogger = get_logger(__name__)
module-attribute
Classes
Functions
ensure_sharedparam(sparam_name, sparam_categories, sparam_group, load_param=True, allow_vary_betwen_groups=False, doc=None)
Source code in pyrevitlib/pyrevit/revit/db/ensure.py
| def ensure_sharedparam(sparam_name, sparam_categories, sparam_group,
load_param=True, allow_vary_betwen_groups=False,
doc=None):
doc = doc or DOCS.doc
if query.model_has_parameter(sparam_name, doc=doc):
if allow_vary_betwen_groups:
param = query.get_project_parameter(sparam_name, doc=doc)
if isinstance(param.param_def, DB.InternalDefinition) \
and not param.param_def.VariesAcrossGroups:
param.param_def.SetAllowVaryBetweenGroups(doc, True)
return True
elif load_param:
create.create_shared_param(
sparam_name,
sparam_categories,
sparam_group,
doc=doc,
allow_vary_betwen_groups=allow_vary_betwen_groups
)
return True
|
ensure_sharedparam_file(spfilepath)
Source code in pyrevitlib/pyrevit/revit/db/ensure.py
| def ensure_sharedparam_file(spfilepath):
if spfilepath and not HOST_APP.app.SharedParametersFilename:
HOST_APP.app.SharedParametersFilename = spfilepath
elif HOST_APP.app.SharedParametersFilename \
and not op.normpath(HOST_APP.app.SharedParametersFilename) \
== op.normpath(spfilepath):
HOST_APP.app.SharedParametersFilename = spfilepath
return HOST_APP.app.OpenSharedParameterFile()
|
ensure_family(family_name, family_file, doc=None)
Source code in pyrevitlib/pyrevit/revit/db/ensure.py
| def ensure_family(family_name, family_file, doc=None):
doc = doc or DOCS.doc
famsym = query.get_family(family_name, doc=doc)
if not famsym:
with transaction.Transaction('Load Family', doc=doc):
mlogger.debug('Family \"%s\" did not exist.', family_name)
if create.load_family(family_file, doc=doc):
return query.get_family(family_name, doc=doc)
else:
raise PyRevitException('Error loading family from: {}'
.format(family_file))
return famsym
|
ensure_element_ids(mixed_list)
Source code in pyrevitlib/pyrevit/revit/db/ensure.py
| def ensure_element_ids(mixed_list):
element_id_list = []
if not hasattr(mixed_list, '__iter__'):
mixed_list = [mixed_list]
for item in mixed_list:
if isinstance(item, DB.ElementId):
element_id_list.append(item)
elif isinstance(item, DB.Element):
element_id_list.append(item.Id)
elif hasattr(item, 'Id') and isinstance(item.Id, DB.ElementId):
element_id_list.append(item.Id)
elif isinstance(item, int):
element_id_list.append(DB.ElementId(item))
return element_id_list
|
ensure_workset(workset_name, partial=False, doc=None)
Source code in pyrevitlib/pyrevit/revit/db/ensure.py
| def ensure_workset(workset_name, partial=False, doc=None):
doc = doc or DOCS.doc
workset = query.model_has_workset(workset_name, partial=partial, doc=doc)
if workset:
return workset
else:
return create.create_workset(workset_name, doc=doc)
|
ensure_text_type(name, font_name=None, font_size=0.01042, tab_size=0.02084, bold=False, italic=False, underline=False, with_factor=1.0, doc=None)
Source code in pyrevitlib/pyrevit/revit/db/ensure.py
| def ensure_text_type(name,
font_name=None,
font_size=0.01042,
tab_size=0.02084,
bold=False,
italic=False,
underline=False,
with_factor=1.0,
doc=None):
doc = doc or DOCS.doc
# check if type exists
for ttype in query.get_types_by_class(DB.TextNoteType, doc=doc):
if query.get_name(ttype) == name:
return ttype
# otherwise create it
return create.create_text_type(
name,
font_name=font_name,
font_size=font_size,
tab_size=tab_size,
bold=bold,
italic=italic,
underline=underline,
with_factor=with_factor,
doc=doc)
|
revision_has_numbertype(revision)
Source code in pyrevitlib/pyrevit/revit/db/ensure.py
| def revision_has_numbertype(revision):
doc = revision.Document
none_numtype = coreutils.get_enum_none(DB.RevisionNumberType)
if HOST_APP.is_newer_than(2022):
numbering = doc.GetElement(revision.RevisionNumberingSequenceId)
if numbering:
return numbering.NumberType != none_numtype
else:
return revision.NumberType != none_numtype
|