Clash Query

Overview

The file clash_query.py 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, creation_timestamp: datetime = None, last_modified_timestamp: datetime = None, last_modified_by: str = '', comment: str = '')

Initializes a new instance of the ClashQuery class.

Parameters
  • identifier (int) – A unique identifier for the query.

  • query_name (str) – The name of the query.

  • object_a_path (str) – The path to the first object in the clash detection query.

  • object_b_path (str) – The path to the second object in the clash detection query.

  • clash_detect_settings (Dict[str, Any]) – A dictionary containing clash detection settings. Default is an empty dictionary if None is provided.

  • creation_timestamp (datetime) – The timestamp when the query was created. Default is the current date and time if None is provided.

  • last_modified_timestamp (datetime) – The timestamp when the query was last modified. Default is the current date and time if None is provided.

  • last_modified_by (str) – The name of the user who last modified the query.

  • comment (str) – A comment or note associated with the query.

Methods

load_settings_from_str(settings_str) bool

Deserializes settings values from a JSON string.

Parameters

settings_str (str) – A JSON string containing clash detection settings.

Returns

True on successful deserialization, otherwise False.

get_settings_as_str() str

Serializes the clash detection settings to a JSON string.

Returns

A JSON string representation of the clash detection settings.

update_last_modified_timestamp() None

Updates the last modified timestamp to the current date and 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: datetime

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

last_modified_timestamp: datetime

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.

last_modified_by: str

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

comment: datetime

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

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"