Skip to content

varset_mutations

freecad.datamanager_wb.varsets.varset_mutations

Mutation helpers for FreeCAD VarSets.

Contains operations that modify VarSets, such as removing a variable property.

removeVarsetVariable(varset_name, variable_name, *, ctx=None)

Remove a variable/property from a VarSet.

Parameters:

Name Type Description Default
varset_name str

Name of the App::VarSet object in the active document.

required
variable_name str

Name of the property to remove.

required

Returns:

Type Description
bool

True if the property was removed, otherwise False.

Source code in freecad/datamanager_wb/varsets/varset_mutations.py
def removeVarsetVariable(
    varset_name: str,
    variable_name: str,
    *,
    ctx: FreeCadContext | None = None,
) -> bool:
    """Remove a variable/property from a VarSet.

    Args:
        varset_name: Name of the `App::VarSet` object in the active document.
        variable_name: Name of the property to remove.

    Returns:
        ``True`` if the property was removed, otherwise ``False``.
    """
    port = get_port(ctx)
    doc = port.get_active_document()
    if doc is None:
        return False

    varset = port.get_typed_object(doc, varset_name, type_id="App::VarSet")
    if varset is None:
        return False

    if not _has_property(varset, variable_name):
        return False

    return _try_remove_property(varset, variable_name)