Our Ruby Scripting ChatBOT for Chief Architect X16 Macros

Meet our Kevin Transue Bot


Things to Know Before You script

You must provide variables from the software in order to receive a working script. This is the most common problem with non-working scripts.
If you do not provide the correct variables, the Bot will make some up, which will not work. The bot can instruct you on how to find them if you ask it to.
Ruby is capable of text replacement and reporting, it is not a programmatic language, as in it cannot modify how the program functions such as conditionally changing the geometric width of an object


Ruby Scripting Guide and Info

    • Select an object in Chief Architect.

    • With the object selected, go to CAD/Text/Text Macro Management

    • in the TMM console, go to Object Properties

    • In the Expanded Macro Value Window, there are a number of variables that the object you selected reports. These are called NVPs. You can read about NVPs down at the bottom of this guide

    • Choose which NVP variables you will need to help the bot execute your script

    • Make sure to tell the bot that these variables are reporting from the software and that it should use them

    • You will need to specify the context of the script, owner or referenced or both. Owner indicates that the script will be run on the owner object, such as a script for a cabinet placed in the label of the cabinet

    • referenced might be a text box that is reporting information about that cabinet within the text box, which is the owner, and the cabinet is being referenced

    • context with both owner and referenced needs to be handled within the body of the script itself so please instruct the bot accordingly

    • Once the bot has given you a script, you can ask it for instructions on how to use the script.

  • NVP in Ruby:

    In Ruby, NVP stands for Name-Value Pair. It is a fundamental data structure where a name (or key) is associated with a value. This is similar to a key-value pair in a hash or dictionary. NVPs are used to store and retrieve data in an easily accessible way, allowing developers to assign a unique identifier (the name) to a specific piece of information (the value).

    ### Publisher in Chief Architect:

    In Chief Architect, a publisher refers to any symbol, object, or element within a design that publishes Name-Value Pairs (NVPs). These NVPs can be used to store metadata or specific attributes related to the object. The published NVPs make it easier for users or other systems to reference, modify, or utilize that information during the design process. Publishers can be essential for streamlining workflows and ensuring consistent data usage across a project.

    #### Example of NVP:

    For example, consider a cabinet object in Chief Architect:

    - Name: `width`

    - Value: `36 inches`

    Here, the Name is `width`, which specifies the horizontal measurement of the cabinet, and the Value is `36 inches`, representing the actual size of the cabinet's width. This information is published by the cabinet object and can be used within the design to ensure proper dimensions and fit within the overall layout.

  • Chief Architect Ruby Environment Rules & Limitations Example

    Rule 1: Avoid Using 'puts' for Output

    In Chief Architect's Ruby environment, we do not use `puts` to output values. Instead, the final expression of the script should be the variable itself to show the result.

    Example:

    `length = 10.in` – Measurement object representing 10 inches

    Correct way to show the result:

    `length` – This will output the value of `length` in the Ruby environment.

    Incorrect way (do NOT use `puts`):

    `puts length`

    ---

    Rule 2: Using Measurement Class Correctly

    Chief Architect relies on the Measurement class for any dimensional variables. You can create a Measurement directly using the Measurement class or via the unit suffix methods (e.g., `.in`, `.ft`).

    Example:

    `width = Measurement.new(25.0, :in)` – Direct initialization of a Measurement in inches

    `height = 30.ft` – Using the unit suffix method to create a Measurement in feet

    ---

    Rule 3: Do Not Use Placeholder Values

    All publisher variables within the script are pre-defined and should not be manually instantiated. Use the publisher variables directly as they are provided by the environment.

    Example:

    If `publisher_length` is a pre-defined variable from the publisher:

    `total_length = publisher_length + 5.in`

    Do NOT manually create variables like this:

    `publisher_length = 10.in`

    ---

    Rule 4: Unit Conversions in the Measurement Class

    Measurements can be converted between units easily using the `convert_to` method.

    Example:

    `width_in_feet = width.convert_to(:ft)` – Converts the width from inches to feet

    ---

    Rule 5: Avoid Method Calls Not Supported by Chief Architect

    Only methods recognized by Chief Architect's Ruby environment should be used. Do not rely on unsupported or complex Ruby constructs.

    Example:

    Instead of using advanced Ruby enumerators, stick with basic loops that work within the environment:

    `array_of_lengths = [10.in, 20.in, 30.in]`

    `total_length = array_of_lengths.sum` – Simple addition using array and Measurement class

    ---

    Rule 6: Access Variables within Macros

    You can access variables from other macros using the `macros.macro_name[:variable_key]` syntax if they return a hash.

    Example:

    `macro_result = eval(macros.example_macro)`

    `calculated_length = macro_result[:length_value] + 5.in` – Accessing the `length_value` from a macro and adding 5 inches

    ---

    Rule 7: Formatting Numbers in Chief Architect

    Chief Architect uses a specific number formatter. Avoid adding trailing zeros and use up to six decimal places where needed.

    Example:

    Here, we create a formatted number with 6 decimal places (adjust formatting if needed):

    `formatted_length = length.to_f.round(6)`

    ---

    ### Key Points to Remember

    1. Do Not Use `puts` for Output: The last expression in your script serves as the result.

    2. Measurement Class: Always work with the `Measurement` class for dimensional values, including methods like `.convert_to`.

    3. Publisher Variables: Use variables provided by the publisher, without initializing them manually.

    4. Unit Conversions: Convert units using `.convert_to` and work with the correct unit types as necessary.

    5. Simple, Supported Methods: Stick to methods recognized in Chief Architect's scripting environment.

    6. Accessing Macros: Retrieve and use values from other macros using the structured `macros.macro_name[:variable_key]` format.

    7. Number Formatting: Use proper number formatting without unnecessary precision, adhering to Chief Architect's rules.


Want to skip the scripting and grab something pre-built?


Check out some of our pre-built Chief Architect products. The Pro Plan template is packed full of macro excellence. Check it out below

Elevate Your Design Skills with Expert Training! Unlock Chief Architect’s potential in tailored sessions for all experience levels.

Help support our efforts on improving our tools and resources. Consider a Donation!