models.Property¶
- class Property(json, **kwargs)[source]¶
A virtual object representing a KE-chain property.
- Variables:
bulk_update – flag to postpone update of properties until manually requested
type – The property type of the property. One of the types described in
pykechain.enums.PropertyType
category – The category of the property, either Category.MODEL of Category.INSTANCE
description – description of the property
unit – unit of measure of the property
model – the id of the model (not the model object)
output – a boolean if the value is configured as an output (in an activity)
part – The (parent) part in which this property is available
value – the property value, can be set as well as property
validators – the list of validators that are available in the property
is_valid – if the property conforms to the validators
is_invalid – if the property does not conform to the validator
Construct a Property from a json object.
- refresh(json: Dict | None = None, url: str | None = None, extra_params: Optional = None) None [source]¶
Refresh the object in place.
- has_value() bool [source]¶
Predicate to indicate if the property has a value set.
This predicate determines if the property has a value set. It will not make a call to KE-chain API (in case of reference properties). So it is a tiny fraction ‘cheaper’ in terms of processing time than checking the Property.value itself.
It will return True if the property_type is a Boolean and set to a value of False.
- Returns:
True if the property has a value set, otherwise (also when value is None) returns False
- Return type:
Bool
- property use_bulk_update¶
Set or get the toggle to asynchronously update property values.
- classmethod set_bulk_update(value)[source]¶
Set global class attribute to toggle the use of bulk-updates of properties.
- property value: Any¶
Retrieve the data value of a property.
Setting this value will immediately update the property in KE-chain.
- Returns:
the value
- classmethod update_values(client: Client, use_bulk_update: bool = False) None [source]¶
Perform the bulk update of property values using the stored values in the Property class.
- Parameters:
client (Client) – Client object
use_bulk_update (bool) – set the class attribute, defaults to False.
- Returns:
None
- serialize_value(value: [T]) T [source]¶
Serialize the value to be set on the property.
- Parameters:
value (Any) – non-serialized value
- Returns:
serialized value
- model() AnyProperty [source]¶
Model object of the property if the property is an instance otherwise itself.
Will cache the model object in order to not generate too many API calls. Otherwise will make an API call to the backend to retrieve its model object.
- Returns:
Property model object if the current Property is an instance.
- Return type:
pykechain.models.AnyProperty
- property validators¶
Provide list of Validator objects.
- Returns:
list of
PropertyValidator
objects- Return type:
list(PropertyValidator)
- property is_valid: bool | None¶
Determine if the value in the property is valid.
If the value of the property is validated as ‘valid’, than returns a True, otherwise a False. When no validators are configured, returns a None. It checks against all configured validators and returns a single boolean outcome.
- Returns:
True when the value is valid
- Return type:
bool or None
- property is_invalid: bool | None¶
Determine if the value in the property is invalid.
If the value of the property is validated as ‘invalid’, than returns a True, otherwise a False. When no validators are configured, returns a None. It checks against all configured validators and returns a single boolean outcome.
- Returns:
True when the value is invalid
- Return type:
bool
- validate(reason: bool = True) List[bool | Tuple] [source]¶
Return the validation results and include an (optional) reason.
If reason keyword is true, the validation is returned for each validation the [(<result: bool>, <reason:str>), …]. If reason is False, only a single list of validation results for each configured validator is returned.
- Parameters:
reason (bool) – (optional) switch to indicate if the reason of the validation should be provided
- Returns:
list of validation results [bool, bool, …] or a list of validation results, reasons [(bool, str), …]
- Return type:
list(bool) or list((bool, str))
- Raises:
Exception – for incorrect validators or incompatible values
- property representations¶
Get and set the property representations.
- classmethod create(json: dict, **kwargs) AnyProperty [source]¶
Create a property based on the json data.
This method will attach the right class to a property, enabling the use of type-specific methods.
It does not create a property object in KE-chain. But a pseudo
Property
object.
- edit(name: str | None = <pykechain.utils.Empty object>, description: str | None = <pykechain.utils.Empty object>, unit: str | None = <pykechain.utils.Empty object>, options: ~typing.Dict | None = <pykechain.utils.Empty object>, **kwargs) None [source]¶
Edit the details of a property (model).
Setting an input to None will clear out the value (exception being name).
- Parameters:
name (basestring or None or Empty) – (optional) new name of the property to edit. Cannot be cleared.
description (basestring or None or Empty) – (optional) new description of the property. Can be cleared.
unit (basestring or None or Empty) – (optional) new unit of the property. Can be cleared.
options (dict or None or Empty) – (options) new options of the property. Can be cleared.
kwargs – (optional) additional kwargs to be edited
- Returns:
None
- Raises:
APIError – When unable to edit the property
IllegalArgumentError – when the type of the input is provided incorrect.
Examples
>>> front_fork = project.part('Front Fork') >>> color_property = front_fork.property(name='Color') >>> color_property.edit(name='Shade',description='Could also be called tint, depending on mixture',unit='RGB')
>>> wheel_property_reference = self.project.model('Bike').property('Reference wheel') >>> wheel_model = self.project.model('Wheel') >>> diameter_property = wheel_model.property('Diameter') >>> spokes_property = wheel_model.property('Spokes') >>> prefilters = {'property_value': diameter_property.id + ":{}:lte".format(15)} >>> propmodels_excl = [spokes_property.id] >>> options = dict() >>> options['prefilters'] = prefilters >>> options['propmodels_excl'] = propmodels_excl >>> wheel_property_reference.edit(options=options)
Not mentioning an input parameter in the function will leave it unchanged. Setting a parameter as None will clear its value (where that is possible). The example below will clear the description, but leave everything else unchanged.
>>> wheel_property.edit(description=None)
- delete() None [source]¶
Delete this property.
- Returns:
None
- Raises:
APIError – if delete was not successful
- copy(target_part: Part, name: str | None = None) Property [source]¶
Copy a property model or instance.
- Parameters:
target_part (
Part
) – Part object under which the desired Property is copiedname (basestring) – how the copied Property should be called
- Returns:
copied
Property
model.- Raises:
IllegalArgumentError – if property and target_part have different Category
Example
>>> property_to_copy = client.property(name='Diameter') >>> bike = client.model('Bike') >>> property_to_copy.copy(target_part=bike, name='Bike diameter?')
- move(target_part: Part, name: str | None = None) Property [source]¶
Move a property model or instance.
- Parameters:
target_part (
Part
) – Part object under which the desired Property is movedname (basestring) – how the moved Property should be called
- Returns:
copied
Property
model.- Raises:
IllegalArgumentError – if property and target_part have different Category
Example
>>> property_to_move = client.property(name='Diameter') >>> bike = client.model('Bike') >>> property_to_move.move(target_part=bike, name='Bike diameter?')
pykechain Property Types¶
- class AttachmentProperty(json, **kwargs)[source]¶
A virtual object representing a KE-chain attachment property.
Construct a Property from a json object.
- property value¶
Retrieve the data value of this attachment.
Will show the filename of the attachment if there is an attachment available otherwise None Use save_as in order to download as a file.
Example
>>> file_attachment_property = project.part('Bike').property('file_attachment') >>> if file_attachment_property.value: ... file_attachment_property.save_as('file.ext') ... else: ... print('file attachment not set, its value is None')
- clear() None [source]¶
Clear the attachment from the attachment field.
- Raises:
APIError – if unable to remove the attachment
- property filename: str | None¶
Filename of the attachment, without the full ‘attachment’ path.
- json_load()[source]¶
Download the data from the attachment and deserialise the contained json.
- Returns:
deserialised json data as
dict
- Raises:
APIError – When unable to retrieve the json from KE-chain
JSONDecodeError – When there was a problem in deserialising the json
Example
Ensure that the attachment is valid json data
>>> json_attachment = project.part('Bike').property('json_attachment') >>> deserialised_json = json_attachment.json_load()
- upload(data: Any, **kwargs: Any) None [source]¶
Upload a file to the attachment property.
When providing a
matplotlib.figure.Figure
object as data, the figure is uploaded as PNG. For this, matplotlib should be installed.- Parameters:
data (basestring) – File path
- Raises:
APIError – When unable to upload the file to KE-chain
OSError – When the path to the file is incorrect or file could not be found
- save_as(filename: str | None = None, **kwargs) None [source]¶
Download the attachment to a file.
- Parameters:
filename (basestring or None) – (optional) File path. If not provided, will be saved to current working dir with self.filename.
One can pass the size parameter as kwargs. See more in Enum:ImageSize or alternatively customize the desired image size like this (width_value, height_value)
- Raises:
APIError – When unable to download the data
OSError – When unable to save the data to disk
- class SelectListProperty(json, **kwargs)[source]¶
A virtual object representing a KE-chain single-select list property.
Construct a Property from a json object.
pykechain References Property Types¶
- class MultiReferenceProperty(json, **kwargs)[source]¶
A virtual object representing a KE-chain multi-references property.
New in version 1.14.
Construct a ReferenceProperty from a json object.
- choices() List[Part] [source]¶
Retrieve the parts that you can reference for this MultiReferenceProperty.
This method makes 2 API calls: 1) to retrieve the referenced model, and 2) to retrieve the instances of that model.
- Returns:
the
Part
’s that can be referenced as aPartSet
.- Raises:
APIError – When unable to load and provide the choices
Example
>>> reference_property = project.part('Bike').property('a_multi_reference_property') >>> referenced_part_choices = reference_property.choices()
- set_prefilters(property_models: List[AnyProperty | str] = None, values: List[Any] = None, filters_type: List[FilterType] = None, prefilters: List[PropertyValueFilter] = None, overwrite: bool | None = False, clear: bool | None = False, validate: bool | Part | None = True) None [source]¶
Set the pre-filters on a MultiReferenceProperty.
- Parameters:
property_models (list) – list of Property models (or their IDs) to set pre-filters on
values (list) – list of values to pre-filter on, value has to match the property type.
filters_type (list) – list of filter types per pre-filter, one of
enums.FilterType
, defaults to FilterType.CONTAINSprefilters (list) – list of PropertyValueFilter objects
overwrite (bool) – whether existing pre-filters should be overwritten, if new filters to the same property are provided as input. Does not remove non-conflicting prefilters. (default = False)
clear (bool) – whether all existing pre-filters should be cleared. (default = False)
validate (bool) – whether the pre-filters are validated to the referenced model, which can be provided as well
- Raises:
IllegalArgumentError – when the type of the input is provided incorrect.
- get_prefilters(as_lists: bool | None = False) List[PropertyValueFilter] | Tuple[List[str]] [source]¶
Retrieve the pre-filters applied to the reference property.
- Parameters:
as_lists – (O) (default = False) If True, the pre-filters are returned as three lists of property model UUIDs, values and filter types.
- Returns:
prefilters
- set_excluded_propmodels(property_models: List[AnyProperty | str], overwrite: bool | None = False, validate: bool | Part | None = True) None [source]¶
Exclude a list of properties from being visible in the part-shop and modal (pop-up) of the reference property.
- Parameters:
property_models (list) – list of Property models (or their IDs) to exclude.
overwrite – flag whether to overwrite existing (True) or append (False, default) to existing filter(s).
:type overwrite bool :param validate: whether the pre-filters are validated to the referenced model, which can be provided as well :type validate: bool
:raises IllegalArgumentError
- get_excluded_propmodel_ids() List[str] [source]¶
Retrieve a list of property model UUIDs which are not visible.
- Returns:
list of UUIDs
:rtype list
- set_sorting(sort_property: AnyProperty | str | None = None, sort_name: bool | str | None = False, sort_direction: SortTable | str | None = 'ASC', clear: bool | None = False) None [source]¶
Set sorting on a specific property (or name) of the referenced part model.
- Parameters:
sort_property (
Property
or UUID) – The property model on which the part instances are being sorted onsort_name (bool) – If set to True it will sort on name of the part. It is ignored if sort_property is None
sort_direction (basestring (see
enums.SortTable
)) – The direction on which the values of property instances are being sorted on: * ASC (default): Sort in ascending order * DESC: Sort in descending orderclear (bool) – whether all existing sorting should be cleared. If set to True, it will ignore all the other parameters
:raises IllegalArgumentError
- class ActivityReferencesProperty(json, **kwargs)[source]¶
A virtual object representing a KE-chain Activity References property.
New in version 3.7.
Construct a ReferenceProperty from a json object.
- class ScopeReferencesProperty(json, **kwargs)[source]¶
A virtual object representing a KE-chain Scope References property.
Construct a ReferenceProperty from a json object.
- set_prefilters(prefilters: List[ScopeFilter] | None = None, clear: bool | None = False) None [source]¶
Set pre-filters on the scope reference property.
- Parameters:
prefilters (list) – list of Scope Filter objects
clear (bool) – whether all existing pre-filters should be cleared. (default = False)
- Returns:
None
- get_prefilters() List[ScopeFilter] [source]¶
Return a list of ScopeFilter objects currently configured on the property.
- Returns:
list of ScopeFilter objects
:rtype list
- set_active_filter_switch(switch_visible: bool)[source]¶
Set the switch between active and inactive scopes on the scope reference property.
- Parameters:
switch_visible (bool) – trigger the switch of showing active or inactive scopes
- set_columns(list_of_columns: List[ScopeReferenceColumns] | None = None)[source]¶
Set the columns visible inside the Scope selection dialog.
- Parameters:
list_of_columns (List of columns) – all the columns possible of a Scope
- class UserReferencesProperty(json, **kwargs)[source]¶
A virtual object representing a KE-chain User References property.
Construct a ReferenceProperty from a json object.
- class FormReferencesProperty(json, **kwargs)[source]¶
A virtual object representing a KE-chain Form References property.
New in version 3.7.
Construct a ReferenceProperty from a json object.