Clash Query#

Overview#

File Name: clash_query.py

The file defines a class that is designed to manage settings for clash detection queries.

ClashQuery Class#

class ClashQuery#

A class that is designed to manage settings for clash detection queries. It includes functionality to serialize and deserialize settings, manage query metadata and update timestamps.

Constants#

VERSION: int = 2

The version number of the ClashQuery class for serialization purposes.

Constructor#

__init__(
identifier: int = 0,
query_name: str = '',
object_a_path: str = '',
object_b_path: str = '',
clash_detect_settings: Dict[str, Any] | None = None,
creation_timestamp: datetime | None = None,
last_modified_timestamp: datetime | None = None,
last_modified_by: str = '',
comment: str = '',
) None

Initializes a new instance of the ClashQuery class.

Parameters:
  • identifier (int, default is 0) – Unique identifier for the clash query.

  • query_name (str, default is "") – Name of the clash query.

  • object_a_path (str, default is "") – Path to the first object involved in the clash detection.

  • object_b_path (str, default is "") – Path to the second object involved in the clash detection.

  • clash_detect_settings (Optional[Dict[str, Any]], default is None) – Settings for the clash detection process.

  • creation_timestamp (Optional[datetime], default is None) – Timestamp when the query was created.

  • last_modified_timestamp (Optional[datetime], default is None) – Timestamp when the query was last modified.

  • last_modified_by (str, default is "") – Name of the user who last modified the query.

  • comment (str, default is "") – Additional comments or notes about the query.

load_settings_from_str(settings_str: str) bool

Deserializes settings values from the JSON string.

Parameters:

settings_str (str) – The JSON string containing settings.

Returns:

True on success, otherwise False.

Return type:

bool

get_settings_as_str() str

Serializes setting values to a JSON string and returns it.

Returns:

The JSON string representation of settings.

Return type:

str

update_last_modified_timestamp() None

Updates last modified timestamp with current date & time.

Properties#

identifier: int

Read-only property that returns the unique identifier of the query.

query_name: str

Property to get or set the name of the query. Setting this property updates the last modified timestamp.

object_a_path: str

Property to get or set the path to the first object in the clash detection query. Setting this property updates the last modified timestamp.

object_b_path: str

Property to get or set the path to the second object in the clash detection query. Setting this property updates the last modified timestamp.

clash_detect_settings: Dict[str, Any]

Property to get or set the clash detection settings as a dictionary. Setting this property updates the last modified timestamp.

creation_timestamp

Read-only property that returns the timestamp when the query was created.

Returns:

The creation timestamp.

Return type:

datetime

last_modified_timestamp

Property to get or set the timestamp when the query was last modified. Setting this property updates the last modified by user to the current user.

Returns:

The last modified timestamp.

Return type:

datetime

last_modified_by

Read-only property that returns the name of the user who last modified the query.

Returns:

The user who last modified.

Return type:

str

comment

Property to get or set a comment or note associated with the query. Setting this property updates the last modified timestamp.

returns:

The comment.

rtype:

str

Usage Example#

# Create a new ClashQuery instance
clash_detect_settings = {
    SettingId.SETTING_LOGGING.name: False,
    SettingId.SETTING_DYNAMIC.name: True,
    SettingId.SETTING_TOLERANCE.name: 0.05,
}

my_query = ClashQuery(
    query_name="My Example Query",
    object_a_path="/path/to/object_a",
    object_b_path="/path/to/object_b",
    clash_detect_settings=clash_detect_settings,
    comment="My example comment"
)

# Retrieve the settings as a JSON string
settings_str = clash_query.get_settings_as_str()

# Load query settings from a JSON string
success = clash_query.load_settings_from_str(settings_str)

# Update the query name and automatically update the last modified timestamp
clash_query.query_name = "Updated Query Name"

# Update the query comment and automatically update the last modified timestamp
clash_query.comment = "Updated comment"