### Get Processing Code Example Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/release_notes.md Demonstrates how to retrieve the code of a processing for a given element and processing ID. This example iterates through BTL processings and fetches their codes. ```python def get_processing_code(reference_element_id: int, processing_id: int) -> str: """Get the code of a processing. Parameters: reference_element_id: The reference element ID. processing_id: The processing ID. Examples: >>> import cadwork >>> import element_controller as ec >>> import machine_controller as mc >>> element: int = 123456789 >>> processings = mc.get_element_btl_processings(element, cadwork.btl_version.btlx_2_1.value) >>> for processing in processings: >>> code = mc.get_processing_code(element, processing) Returns: The processing code. """ ``` -------------------------------- ### Get Processing Points Example Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/release_notes.md Demonstrates how to retrieve the geometric points of a processing for a given element and processing ID. This example iterates through BTL processings and fetches their points. ```python def get_processing_points(reference_element_id: int, processing_id: int) -> vertex_list: """Get the points of a processing. Parameters: reference_element_id: The reference element ID. processing_id: The processing ID. Examples: >>> import cadwork >>> import element_controller as ec >>> import machine_controller as mc >>> element: int = 123456789 >>> processings = mc.get_element_btl_processings(element, cadwork.btl_version.btlx_2_1.value) >>> for processing in processings: >>> points = mc.get_processing_points(element, processing) Returns: A vertex_list of points. """ ``` -------------------------------- ### Element Controller Example Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/element_controller.md Demonstrates the basic structure and usage of the Element Controller. ```python from cw_api.element_controller import ElementController # Assuming you have an initialized API client # api_client = CWAPIClient() # Initialize the Element Controller # element_controller = ElementController(api_client) # Example usage (replace with actual methods) # elements = element_controller.get_elements() # print(elements) ``` -------------------------------- ### Get Processing BTL Parameter Set Example Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/release_notes.md Demonstrates how to retrieve the BTL parameter set for a processing, given the element and processing ID. This example iterates through BTL processings and fetches their parameters. ```python def get_processing_btl_parameter_set(reference_element_id: int, processing_id: int) -> List[str]: """Get the BTL parameter set for a processing. Parameters: reference_element_id: The reference element ID. processing_id: The processing ID. Examples: >>> import cadwork >>> import element_controller as ec >>> import machine_controller as mc >>> element: int = 123456789 >>> processings = mc.get_element_btl_processings(element, cadwork.btl_version.btlx_2_1.value) >>> for processing in processings: >>> parameters = mc.get_processing_btl_parameter_set(element, processing) Returns: List of BTL parameter strings. """ ``` -------------------------------- ### Get Processing Name Example Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/release_notes.md Demonstrates how to retrieve the name of a processing for a given element and processing ID. This example iterates through BTL processings and fetches their names. ```python def get_processing_name(reference_element_id: int, processing_id: int) -> str: """Get the name of a processing. Parameters: reference_element_id: The reference element ID. processing_id: The processing ID. Examples: >>> import cadwork >>> import element_controller as ec >>> import machine_controller as mc >>> element: int = 123456789 >>> processings = mc.get_element_btl_processings(element, cadwork.btl_version.btlx_2_1.value) >>> for processing in processings: >>> name = mc.get_processing_name(element, processing) Returns: The processing name. """ ``` -------------------------------- ### Dimension Controller Example Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/dimension_controller.md Demonstrates how to use the Dimension Controller to interact with dimensions. This snippet requires the DimensionController class to be imported. ```python from cw_api.dimension_controller import DimensionController dc = DimensionController() # Example usage (replace with actual methods) dc.get_dimensions() dc.set_dimension("width", 100) dc.get_dimension("height") ``` -------------------------------- ### Multi Layer Cover Controller Example Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/multi_layer_cover_controller.md Demonstrates the basic usage of the Multi Layer Cover Controller. This snippet is intended for general understanding and integration. ```python from cw_api.cwapi3d.controllers.multi_layer_cover_controller import MultiLayerCoverController # Assuming 'api' is an initialized CWAPI3D instance controller = MultiLayerCoverController(api=api) # Example usage (replace with actual parameters) # result = controller.some_method(param1, param2) # print(result) print("MultiLayerCoverController initialized and ready.") ``` -------------------------------- ### BIMteam Upload Result Code Examples Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/bim_team_upload_result.md Provides code examples for interacting with BIMteam upload results. These snippets demonstrate how to use the upload result objects in Python. ```python from cadwork import bim_team_upload_result_code # Assuming 'upload_result_code' is an instance of bim_team_upload_result_code # Example usage: # print(upload_result_code.id) # print(upload_result_code.status) # print(upload_result_code.message) # print(upload_result_code.data) ``` -------------------------------- ### Install PyDevD-PyCharm Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/debug.md Install the required package for remote debugging on the machine running the script. ```bash pip install pydevd-pycharm~= ``` -------------------------------- ### Manage output types Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/cadwork.md Examples for modifying panel output types and checking element types for active elements. ```python import element_controller as ec import attribute_controller as ac import cadwork element_ids = ec.get_active_identifiable_element_ids() for element in element_ids: if ac.is_panel(element): get_output_tpye = ac.get_output_type(element) get_output_tpye.set_panel_2() ac.set_output_type([element], get_output_tpye) ``` ```python import element_controller as ec import attribute_controller as ac import cadwork element_ids = ec.get_active_identifiable_element_ids() for element in element_ids: element_type = ac.get_element_type(element) print(cadwork.element_type.isWall(element_type)) ``` -------------------------------- ### Install Specific Version of CWAPI3D Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/get_started.md Install a specific version of the CWAPI3D package by specifying the package name and version. ```bash pip install == ``` -------------------------------- ### Install CwAPI3D via pip Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/README.md Use this command to install the CwAPI3D package in your Python environment. ```bash pip install cwapi3d ``` -------------------------------- ### Get user attributes Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/attribute_example.md Retrieve attribute values, names, and element GUIDs for active elements. ```python import attribute_controller as ac # import module import element_controller as ec # get active element_ids element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: user_attr = ac.get_user_attribute(element_id, 20) # 20 = attribute number user_attr_name = ac.get_user_attribute_name(20) element_guid = ec.get_element_cadwork_guid(element_id) print(user_a_name, user_a, element_guid) ``` -------------------------------- ### Create a square beam using vectors Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/element_example.md Generates a square beam defined by dimensions, a starting point, and orientation vectors. ```python import cadwork # import module import element_controller as ec point = cadwork.point_3d(100, 200, 300) # create a cadwork Point vector_x = cadwork.point_3d(1.0, 0.0, 0.0) # x vector length direction vector_z = cadwork.point_3d(0.0, 0.0, 1.0) # z vecotr height orientation width = 200.0 # width/heigth of beam section length = 2600.0 # beam length beam = ec.create_square_beam_vectors(width, length, point, vector_x, vector_z) # returns element_id ``` -------------------------------- ### Importing the 3D Point Module Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/point_3d.md Import the `point_3d` module from the `cadwork` library to start working with 3D points. ```python from cadwork import point_3d ``` -------------------------------- ### Get Building and Storey information Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/bim_example.md Retrieves the building and storey names associated with active elements. ```python import cadwork import bim_controller as bc import element_controller as ec # get active element_ids element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: bc.get_building(element_id) storey_name = bc.get_storey(element_id) ``` -------------------------------- ### Hello Cadwork API Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/index.md A simple Python script to print a greeting message. This is a basic starting point for interacting with the Cadwork API. ```python print("Hello Cadwork! Let's get started!") ``` -------------------------------- ### Get GlobalId (IfcGuid) for active elements Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/bim_example.md Retrieves and prints the IFC GUID for all currently selected elements. ```python import cadwork import bim_controller as bc import element_controller as ec # get active element_ids element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: guid = bc.get_ifc_guid(element_id) print(guid) ``` -------------------------------- ### Get Storey height Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/bim_example.md Calculates and prints the height of the storey for active elements based on their building and storey names. ```python import cadwork import bim_controller as bc import element_controller as ec # get active element_ids element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: building_name = bc.get_building(element_id) storey_name = bc.get_storey(element_id) storey_height = bc.get_storey_height(building_name, storey_name) print(storey_height) ``` -------------------------------- ### Get BTL Processing IDs for an Element Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/release_notes.md Retrieves a list of BTL processing IDs associated with a specific element. Requires the element ID and the BTL version. ```python def get_element_btl_processings(element_id: int, btl_version: int) -> List[int]: """Get BTL processing IDs for an element. Parameters: element_id: The element ID. btl_version: The BTL version. Returns: List of processing IDs. """ ``` -------------------------------- ### Run Plugin from Console Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/get_started.md Use the /PLUGIN= flag with ci_start.exe to launch a specific plugin. Replace 'test' with the actual plugin name you wish to run. ```cmd ...\cadwork.dir\ci_start.exe "C:\...\myFile.3d" /PLUGIN=test ``` -------------------------------- ### Create a Window with PyQt5 Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/tk_gui.md Initializes a basic window using the PyQt5 framework with a button widget. ```python from PyQt5.QtWidgets import QWidget, QToolTip, QPushButton, QApplication, QLabel class MyWindow(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): btn = QPushButton('Button', self) btn.resize(btn.sizeHint()) btn.move(50, 50) self.setGeometry(300, 300, 300, 200) self.setWindowTitle('Qt5 Button') if __name__ == '__main__': window = MyWindow() window.show() ``` -------------------------------- ### Batch print and export .2d files via command line Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/command_line.md Use ci_start.exe with /P or /L flags to print plotter or laser frames from .2d files. ```cmd ci_start.exe "C:\path\plan.2d" /P A :: print all plotter frames to the default plotter ci_start.exe "C:\path\plan.2d" /P 1-2;5;7 :: print plotter frames 1, 2, 5, 7 (and following) ci_start.exe "C:\path\plan.2d" /L A :: print all laser frames to the default laser ci_start.exe "C:\path\plan.2d" /L PDF :: print all laser frames to the default PDF driver ``` -------------------------------- ### Locating ci_start.exe and version folders Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/command_line.md Shows the typical directory structure for the cadwork launcher and version-specific executable folders. ```text ...\cadwork.dir\ci_start.exe ``` ```text ...\cadwork.dir\exe_2026 ...\cadwork.dir\exe_2027 ``` -------------------------------- ### Create a Hello World Application with tkinter Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/tk_gui.md Demonstrates a basic class-based structure for a tkinter application with buttons and event handling. ```python import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): super().__init__(master) self.master = master self.pack() self.create_widgets() def create_widgets(self): self.hi_there = tk.Button(self) self.hi_there['text'] = 'Hello cadwork World\n(click me)' self.hi_there['command'] = self.say_hi self.hi_there.pack(side='top') self.quit = tk.Button(self, text='QUIT', fg='blue', command=self.master.destroy) self.quit.pack(side='bottom') def say_hi(self): print('hi there, everyone!') root = tk.Tk() app = Application(master=root) app.mainloop() ``` -------------------------------- ### Get endtype name at element start point Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/endtype_example.md Retrieves the endtype name for all currently active elements and prints them to the console. ```python import cadwork # import module import endtype_controller as etc import element_controller as ec element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: endtype_name = etc.get_endtype_name_start(element_id) print(endtype_name) ``` -------------------------------- ### Run a plugin from any directory with /RUNPROGRAM Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/command_line.md Executes a plugin from a specified path, bypassing the requirement to be registered in the API.x64 directory. ```cmd ...\cadwork.dir\ci_start.exe "C:\path\to\myFile.3d" /RUNPROGRAM="C:\my_plugins\export.py" ``` ```cmd ci_start.exe "C:\path\to\myFile.3d" /RUNPROGRAM="D:\tools\my_plugin.py" :: run a Python plugin ci_start.exe "C:\path\to\myFile.3d" /RUNPROGRAM="D:\tools\my_plugin.dll" :: run a compiled C++ plugin ``` -------------------------------- ### Opening a file with a specific version Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/command_line.md Demonstrates launching a .3d file using a specific cadwork version path via the /EXE argument. ```powershell D:\cadwork.dir\ci_start.exe "C:\Users\Me\Downloads\timber-framed-elements.3d" /EXE=D:\cadwork.dir\exe_2026 ``` ```powershell Start-Process "C:\Users\Me\Downloads\timber-framed-elements_2027.3d" -ArgumentList '/EXE=D:\cadwork.dir\exe_2027' ``` -------------------------------- ### Batch process .3d files with PowerShell Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/command_line.md Iterate through a directory of .3d files and execute a plugin for each using Start-Process with the -Wait flag. ```powershell $exe = 'D:\cadwork.dir\ci_start.exe' $exeDir = 'D:\cadwork.dir\exe_2026' $files = Get-ChildItem 'C:\Projects\Batch' -Filter *.3d foreach ($file in $files) { Write-Host "Processing $($file.Name)" Start-Process -FilePath $exe ` -ArgumentList "`"$($file.FullName)`"", "/EXE=$exeDir", '/PLUGIN=MyExportScript' ` -Wait } ``` -------------------------------- ### Run headless with /NO-GUI Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/command_line.md Executes a plugin without the graphical user interface, suitable for server-side automation. ```cmd ci_start.exe "C:\path\to\myFile.3d" /RUNPROGRAM="C:\my_plugins\export.py" /NO-GUI ``` -------------------------------- ### Assign color to beam using visualization_controller Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/visualization_example.md Demonstrates creating a square beam and applying a color using the visualization_controller module. ```python import cadwork # import module import element_controller as ec import visualization_controller as vc point = cadwork.point_3d(100, 200, 300) # create a cadwork Point vector_x = cadwork.point_3d(1.0, 0.0, 0.0) # x vector length direction vector_z = cadwork.point_3d(0.0, 0.0, 1.0) # z vecotr height orientation width = 200.0 # width/heigth of beam section length = 2600.0 # beam length color = 3 # color number as an int beam = ec.create_square_beam_vectors(width, length, point, vector_x, vector_z) # returns element_id add_beam_color = vc.set_color([beam], color) # input beam id (list), color (int) ``` -------------------------------- ### Create a node Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/element_example.md Initializes a new node at a specified 3D point. ```python import cadwork # import module import element_controller as ec point = cadwork.point_3d(100, 200, 300) # create a cadwork Point node = ec.create_node(point) ``` -------------------------------- ### Retrieve user input via dialogs Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/utility_example.md Demonstrates how to prompt the user for boolean, point, and numeric input to drive script logic. ```python import cadwork import utility_controller as uc import element_controller as ec drill_bool = uc.get_user_bool('Do u want to create a drilling ?', True) if drill_bool: pt = uc.get_user_point() length = uc.get_user_double('Enter the drilling length') drilling = ec.create_drilling_vectors(40, length, pt, cadwork.point_3d(0.0, 0.0, -1.0)) ``` -------------------------------- ### Create a simple cadwork menu Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/menu_example.md Displays a menu with selectable options and handles user input in a loop. ```python import menu_controller as mec import utility_controller as uc import cadwork menu_options = 'Foo', 'Bar', 'Baz', '', 'Return' while True: menu = mec.display_simple_menu(menu_options) if menu == 'Foo': uc.print_error('You pressed Foo') elif menu == 'Bar': uc.print_error('You pressed Bar') elif menu == 'Baz': uc.print_error('You pressed Baz') elif menu == 'Return': break ``` -------------------------------- ### Get Hundegger Processing IDs for an Element Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/release_notes.md Retrieves a list of Hundegger processing IDs associated with a specific element. Requires the element ID and the Hundegger type. ```python def get_element_hundegger_processings(element_id: int, hundeggertype: int) -> List[int]: """Get Hundegger processing IDs for an element. Parameters: element_id: The element ID. hundeggertype: The Hundegger type. Returns: List of processing IDs. """ ``` -------------------------------- ### Replace endtype name at element start point Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/endtype_example.md Replaces the endtype name of active elements if they match a specific target name, using a user-provided string. ```python import cadwork # import module import endtype_controller as etc import element_controller as ec import utility_controller as uc element_ids = ec.get_active_identifiable_element_ids() new_endtype = uc.get_user_string('name of the new end-type') i = 0 for element_id in element_ids: endtype_name = etc.get_endtype_name_start(element_id) if endtype_name == 'V_8': # V_8 = name of an endtpye etc.set_endtype_name_start(element_id, new_endtype) i += 1 uc.print_error('Number of end-type replaced:%d' % i) ``` -------------------------------- ### Compare strings in Python Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/compare.md Demonstrates standard string comparison operators including case-sensitive equality and lexicographical ordering. ```python if __name__ == '__main__': print('cadwork' == 'cadwork') print('Cadwork' < 'cadwork') print('Cadwork' > 'cadwork') print('cadwork' != 'cadwork') # output # True # True # False # False ``` -------------------------------- ### Create and add elements to a scene Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/scene_example.md Initializes a new scene and populates it with currently active elements. Requires the element_controller and scene_controller modules. ```python import element_controller as ec import cadwork import scene_controller as sc element_ids = ec.get_active_identifiable_element_ids() new_scene = sc.add_scene('NewScene') if new_scene: sc.add_elements_to_scene('NewScene', element_ids) sc.activate_scene('NewScene') ``` -------------------------------- ### Main Execution Logic Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/menu_example.md Retrieves active elements, processes their types, and updates the output type based on user menu selection. ```python def main(): active_elements = ec.get_active_identifiable_element_ids() if len(active_elements) > 0: for element in active_elements: ele_type = ac.get_element_type(element) l_ele_types = list_ele_types(ele_type) process_type = ac.get_output_type(element) l_process_types = list_process_types_is(process_type) for p_type in l_process_types: if p_type[0]: for e_type in l_ele_types: if e_type[0]: vc.hide_all_elements() vc.set_visible([element]) vc.zoom_all_elements() uc.print_error(f'Elementyp = {e_type[1]} / Ausgabeart = {p_type[1]}') n_process_type = list_process_types_set(menu_output_type(), process_type) ac.set_output_type([element], n_process_type) l_process_types = list_process_types_is(process_type) for p_type_n in l_process_types: if p_type_n[0]: uc.print_error(f'Ausgabeart neu = {p_type_n[1]}') if __name__ == '__main__': main() ``` -------------------------------- ### Auto-run a Python plugin with /PLUGIN Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/command_line.md Executes a registered Python plugin automatically upon opening a 3D file. ```cmd ...\cadwork.dir\ci_start.exe "C:\path\to\myFile.3d" /PLUGIN=MyScript ``` -------------------------------- ### Import STEP File Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/file_example.md Imports a STEP file selected via a user dialog with specified scaling and message options. ```python import file_controller as fc # import module import element_controller as ec import_file = uc.get_new_user_file_from_dialog('*.stp') # str: aFilePath, float: aScale, bool: aMesageOption fc.import_step_file_with_message_option(import_file, 0.0001, True) ``` -------------------------------- ### Export Rhino File with Directory Creation Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/file_example.md Handles directory creation before exporting elements to a Rhino file. ```python import file_controller as fc import element_controller as ec import os target_path = 'C:\\Users\\YourUsername\\Downloads\\RhinoExports\\' try: create_direction = os.mkdir(target_path) # replace YourUsername with your username on your PC or add another directory # mkdir will create a folder with the Name RhinoExports except FileExistsError: # excepiton handling - if folder exists print('Folder already exists!') # path to the new file file_name = target_path + 'TestExport.3dm' element_ids = ec.get_active_identifiable_element_ids() fc.export_rhino_file(element_ids, file_name, 6, True, True) ``` -------------------------------- ### Import cadwork.extended_settings Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/extended_settings.md Import the extended_settings module from the cadwork library. This is typically the first step before using any of its functionalities. ```python from cadwork import extended_settings ``` -------------------------------- ### Import Attribute Display Settings Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/attribute_display_settings.md Import the attribute_display_settings module from the cadwork library. ```python from cadwork import attribute_display_settings ``` -------------------------------- ### Create and categorize a new material Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/material_example.md Creates a new material and assigns it to a specific group category. ```python import material_controller as mc material_id = mc.create_material('Cross-Laminated-Timber') # the new created material is stored in the category "No groups" mc.set_group(material_id, 'Plattenwerkstoffe') # the new created material is now shifted in the category "Plattenwerkstoffe" ``` -------------------------------- ### Verify Gemini CLI MCP Connection Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/mcp.md List the currently configured MCP servers in the Gemini CLI to verify the connection. ```bash gemini mcp list ``` -------------------------------- ### Display Menu for Output Type Selection Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/menu_example.md Displays a menu of available output types and returns the index of the user's selection. ```python def menu_output_type(): menu_items = [ 'hip_valley', 'jack_rafter', 'log', 'none', 'panel_1', 'panel_2', 'panel_3', 'panel_4', 'panel_5', 'purlin', 'rafter', 'rough_volume_framed_wall', 'rough_volume_log_home', 'rough_volume_solid_wood_wall', 'stud', 'tread', 'truss', 'user_1', 'user_2', 'user_3', 'user_4', 'user_5', ] menu_select = mc.display_simple_menu(menu_items) menu_i = menu_items.index(menu_select) return menu_i + 1 ``` -------------------------------- ### Available point_3d methods and operators Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/geometry.md Lists the supported arithmetic operators and geometric methods available for point_3d objects. ```python point_3d + point_3d point_3d - point_3d point_3d * float point_3d / float point_3d += point_3d point_3d -= point_3d point_3d *= float point_3d /= float -point_3d point_3d == point_3d point_3d != point_3d point_3d.dot(point_3d) # dot product or scalar product point_3d.cross(point_3d) # cross product or vector product point_3d.magnitude() # vector magnitude or length point_3d.normalized() # a normalized vector maintains its direction but its length becomes 1 point_3d.distance(point_3d) # distance between two points ``` -------------------------------- ### Export part list Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/list_example.md Exports a list of active identifiable elements to a specified file path. ```python import cadwork import list_controller as lc import utility_controller as uc import visualization_controller as vc element_ids = ec.get_active_identifiable_element_ids() lc.export_part_list(element_ids, 'C:\\Downloads\\api_list.cwlm') ``` -------------------------------- ### Create a cadwork point Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/cadwork.md Initializes a 3D point structure using x, y, and z coordinates. ```python import cadwork # import module point = cadwork.point_3d(100, 200, 300) # create a cadwork Point ``` -------------------------------- ### Export BTL file using machine_controller Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/machine_example.md Exports a BTL file to a specified path using the machine export enumeration. ```python import machine_controller as mac import cadwork btl_enum = 5 # VERSION: "BTL V10.6" # The enumeration is done according to the machine export listing in the export menu. file_path = 'C:\\Downloads\\api_btl.btl' mac.export_btl(btl_enum, file_path) ``` -------------------------------- ### Import 3DC Options Module Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/import_3dc_options.md Import the `import_3dc_options` module from the `cadwork` library. This is the primary entry point for using 3DC import functionalities. ```python import cadwork.import_3dc_options ``` -------------------------------- ### Configure Remote Debugging Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/debug.md Inject the pydevd-pycharm trace configuration into the source code to connect to a remote debug server. ```python import math # ==============this code added==================================================================: import pydevd_pycharm pydevd_pycharm.settrace('172.20.208.95', port=12345, stdoutToServer=True, stderrToServer=True) # ================================================================================================ class Solver: def demo(self, a, b, c): d = b**2 - 4 * a * c if d > 0: disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 elif d == 0: return -b / (2 * a) else: return 'This equation has no roots' if __name__ == '__main__': solver = Solver() while True: a = int(input('a: ')) b = int(input('b: ')) c = int(input('c: ')) result = solver.demo(a, b, c) print(result) ``` -------------------------------- ### Accessing point_3d coordinates via index Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/geometry.md Demonstrates accessing x, y, and z coordinates of a point_3d object using list-like indexing. ```python import cadwork # import module point = cadwork.point_3d(100, 200, 300) # create a cadwork Point print(point[0]) # prints x coordinate print(point[1]) # prints y coordinate print(point[2]) # prints z coordinate ``` -------------------------------- ### Importing the cadwork module Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/modules.md The cadwork module must be loaded into the namespace to enable core processes. ```python import cadwork ``` -------------------------------- ### Check element conditions Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/attribute_example.md Use these snippets to verify element types or properties before performing operations. ```python import attribute_controller as ac # import module import element_controller as ec # get active element_ids element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: if ac.is_panel(element_id): # returns boolean print(True) else: print(False) ``` ```python import attribute_controller as ac # import module import element_controller as ec import cadwork # get active element_ids element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: element_type = ac.get_element_type(element_id) if element_type.is_rectangular_beam(): # do something ``` -------------------------------- ### Compare custom objects in Python Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/compare.md Implements __eq__ for value and entity classes to define custom equality logic based on specific attributes. ```python import dataclasses # value class @dataclasses.dataclass() class Address: street: str number: int zipcode: int def __eq__(self, other): if not isinstance(other, Address): return False return self.street == other.street and self.number == other.number and self.zipcode == other.zipcode # entity class class Person: def __init__(self, name, passport_id, address): self.name: str = name self.address: Address = address self.passport_id: int = passport_id def __eq__(self, other): if not isinstance(other, Person): return False return self.passport_id == other.passport_id def __hash__(self): return hash(self.passport_id) if __name__ == '__main__': address1 = Address(street='ThisStreet', number=20, zipcode=8084) address2 = Address(street='OtherStreet', number=204, zipcode=9000) print(address1 == address2) person1 = Person(name='John', passport_id=123456, address=address1) person2 = Person(name='John', passport_id=123456, address=address2) print(person1 == person2) print(person1.__hash__() == person2.__hash__()) ``` -------------------------------- ### Retrieve material IDs and names Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/material_example.md Iterates through all available materials to map their names to their respective IDs. ```python import cadwork import material_controller as mc material_ids_by_name = {} for material_id in mc.get_all_materials(): mat_name = mc.get_name(material_id) material_ids_by_name[mat_name] = material_id ``` -------------------------------- ### Importing standard Python modules Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/modules.md Standard Python modules can be integrated using standard import statements. ```python # import modules import cadwork import math import csv import tkinter ... ... ``` -------------------------------- ### Import Element Module Properties Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/element_module_properties.md Import the element_module_properties module to access its functionalities. ```python from cadwork.element_module_properties import * ``` -------------------------------- ### Implement a Button in tkinter Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/tk_gui.md Shows how to define a button widget with a custom click handler within a tkinter frame. ```python import tkinter as tk class MyApp(tk.Frame): def __init__(self, master=None): super().__init__(master) self.pack() self.ok = tk.Button(self) self.ok['text'] = 'cadwork' self.ok['command'] = self.handler self.ok.pack() def handler(self): print('Button clicked') if __name__ == '__main__': root = tk.Tk() root.geometry('500x300') app = MyApp(root) app.mainloop() ``` -------------------------------- ### Run Python Script in cadwork Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/get_started.md This script demonstrates how to import necessary cadwork modules, retrieve active element IDs, and print their subgroups. Ensure you have the cadwork, element_controller, and attribute_controller modules available. ```python # import modules import cadwork import element_controller as ec import attribute_controller as ac # get active element_ids element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: subgroup = ac.get_subgroup(element_id) # get subgroup name of active element_ids print(subgroup) # print the subgroup names ``` -------------------------------- ### Add MCP Server to Gemini CLI Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/mcp.md Configure the Gemini CLI to connect to the Cadwork Python MCP server. ```bash npm install -g @google/gemini-cli@latest ``` ```bash gemini mcp add --transport http cadwork-pyapi https://pyapi.mcp.cadwork.dev/mcp ``` -------------------------------- ### point_3d Methods and Operators Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/geometry.md Supported arithmetic operators and geometric methods for point_3d objects. ```APIDOC ## point_3d Operations ### Arithmetic Operators - `+`, `-`, `*`, `/` (with float) - `+=`, `-=`, `*=`, `/=` - `-` (unary negation) - `==`, `!=` (comparison) ### Geometric Methods - `dot(other: point_3d) -> float`: Returns the dot product. - `cross(other: point_3d) -> point_3d`: Returns the cross product. - `magnitude() -> float`: Returns the vector length. - `normalized() -> point_3d`: Returns a normalized vector. - `distance(other: point_3d) -> float`: Returns the distance between two points. ``` -------------------------------- ### Configure MCP Server for VS Code (GitHub Copilot) Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/mcp.md Add the Cadwork Python MCP server configuration to your VS Code settings file. ```json { "servers": { "cadwork-pyapi": { "type": "http", "url": "https://pyapi.mcp.cadwork.dev/mcp" } } } ``` -------------------------------- ### Export Hundegger file using machine_controller Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/machine_example.md Exports machine data for a Hundegger K2 system using the corresponding machine enumeration. ```python import machine_controller as mac import cadwork hundegger_enum = 3 # Hundegger K2 # The enumeration is done according to the machine export listing in the export menu. mac.export_hundegger(hundegger_enum) ``` -------------------------------- ### Create surfaces from element boundaries Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/element_example.md Iterates through active elements to create surfaces based on their facets. ```python import cadwork import geometry_controller as gc import element_controller as ec element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: facets = gc.get_element_facets(element_id) for facet in facets: ec.create_surface(facet) # create surface ``` -------------------------------- ### Compare floating-point numbers in Python Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/compare.md Uses an epsilon threshold to determine equality between floats, avoiding precision issues. ```python if __name__ == '__main__': a: float = 1.23 b: float = 1.230000000001 print('numbers are equal') if (a == b) else print('numbers are different') result: bool = abs(a - b) < 1e-4 print(result) ``` -------------------------------- ### Set Building and Storey for elements Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/bim_example.md Assigns a specific building and storey name to a list of element IDs. ```python import cadwork import bim_controller as bc import element_controller as ec # get active element_ids element_ids = ec.get_active_identifiable_element_ids() bc.set_building_and_storey([element_ids], 'BuildingName', 'Level_1') ``` -------------------------------- ### Concatenate material and storey in Python Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/auto_attributes.md Combines the building storey and element material into a formatted string. ```python import cadwork import attribute_controller as ac import bim_controller as bc element_ids = cadwork.get_auto_attribute_elements() for element_id in element_ids: storey = bc.get_storey(element_id) material = ac.get_element_material_name(element_id) cadwork.set_auto_attribute([element_id], f'{material} - {storey}') ``` -------------------------------- ### Set user attributes Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/attribute_example.md Assign custom attribute names and values to a list of element IDs. ```python import attribute_controller as ac # import module import element_controller as ec element_ids = ec.get_active_identifiable_element_ids() ac.set_user_attribute_name(11, 'ExampleAttribute') ac.set_user_attribute(element_ids, 11, 'Hello World!') ``` -------------------------------- ### Check production list discrepancies Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/list_example.md Validates position numbers in the production list and highlights elements with discrepancies. ```python import cadwork import list_controller as lc import utility_controller as uc import visualization_controller as vc checked_element_ids = lc.check_position_numbers_production_list() if not checked_element_ids: uc.print_error('No discrepancies in production list') else: vc.set_active(checked_element_ids) uc.print_error('Active elements have discrepancies in the production list !') ``` -------------------------------- ### BREP Vertex List Structure Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/brep_data.md Displays the structure of the vertex_list for BREP data. This is useful for understanding vertex representations and their coordinates. ```python from typing import List, Optional from pydantic import BaseModel class Vertex(BaseModel): coordinates: List[float] class VertexList(BaseModel): vertices: List[Vertex] parent_face: Optional[int] = None ``` -------------------------------- ### Accessing point_3d coordinates via attributes Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/geometry.md Demonstrates accessing x, y, and z coordinates of a point_3d object using named attributes. ```python import cadwork # import module point = cadwork.point_3d(100, 200, 300) # create a cadwork Point print(point.x) # prints x coordinate print(point.y) # prints y coordinate print(point.z) # prints z coordinate ``` -------------------------------- ### BREP Facet List Structure Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/documentation/brep_data.md Displays the structure of the facet_list for BREP data. This is useful for understanding how facets are represented. ```python from typing import List, Optional from pydantic import BaseModel class Facet(BaseModel): normal: List[float] vertices: List[int] edges: List[int] class FacetList(BaseModel): facets: List[Facet] parent_face: Optional[int] = None ``` -------------------------------- ### Add vertical wall section Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/shop_drawing_example.md Generates a vertical wall section for a selected element at a calculated position. Requires a single wall element selection. ```python import attribute_controller as ac import cadwork import geometry_controller as gc import element_controller as ec import shop_drawing_controller as sdc element_id = ec.get_user_element_ids() if len(element_id) != 1: uc.print_error('Please select just one wall element') exit() if not ac.is_wall(*element_id): uc.print_error('Please select a wall element') exit() position_vector = gc.get_p1(*element_id) position_vector += gc.get_xl(*element_id) * 500.0 sdc.add_wall_section_vertical(*element_id, position_vector) ``` -------------------------------- ### Retrieve beam points and vectors Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/geometry_example.md Accesses local vectors and Cartesian points for active elements. Requires the cadwork, element_controller, and geometry_controller modules. ```python import cadwork # import module import element_controller as ec import geometry_controller as gc # get active element_ids element_ids = ec.get_active_identifiable_element_ids() for element_id in element_ids: vector_x = gc.get_xl(element_id) # returns local vector vector_y = gc.get_yl(element_id) # returns local vector vector_z = gc.get_zl(element_id) # returns local vector get_p1 = gc.get_p1(element_id) # returns cartesian point get_p2 = gc.get_p2(element_id) # returns cartesian point get_p3 = gc.get_p3(element_id) # returns cartesian point print(f"""the elements local vecotr z is: {vector_z} \n' the coordinates of the point_3 are {get_p3}""") ``` -------------------------------- ### Export 2D wireframe drawing Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/shop_drawing_example.md Exports the current view as a 2D wireframe drawing using a specified clipboard number and layout toggle. ```python import cadwork import shop_drawing_controller as sdc clipboard_number = 3 with_layout = False # boolean to export with or without layout sdc.export_2d_wireframe_with_clipboard(clipboard_number, with_layout) ``` -------------------------------- ### Plugin Info XML Structure Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/get_started.md This XML file defines metadata for Cadwork plugins, including version, date, author, name, and description. It supports multiple languages for text fields. ```xml 1.0.0.0 2022-04-12 your Name Plugin Title - foo bar baz Plugin Title - foo bar baz Plugin Title - foo bar baz ``` -------------------------------- ### Configuring sys.path for external modules Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/modules.md Append the directory path of external modules to sys.path to allow the interpreter to locate them. ```python # import modules import sys import utility_controller as uc # get userprofil path USERPROFIL = uc.get_3d_userprofil_path() # appending a path sys.path.append(USERPROFIL + '\\api.x64\\FolderName\\PackageFolder') # printing all paths print(sys.path) # import external modules import PackageFolder ``` -------------------------------- ### Assign attributes to a new beam Source: https://github.com/cwapi3d/cwapi3dpython/blob/main/docs/examples/attribute_example.md Create a square beam and assign a name attribute to it. ```python import cadwork # import module import attribute_controller as ac import element_controller as ec point = cadwork.point_3d(100, 200, 300) # create a cadwork Point vector_x = cadwork.point_3d(1.0, 0.0, 0.0) # x vector length direction vector_z = cadwork.point_3d(0.0, 0.0, 1.0) # z vecotr height orientation width = 200.0 # width/heigth of beam section length = 2600.0 # beam length name = 'My first beam :)' # name as a string beam = ec.create_square_beam_vectors(width, length, point, vector_x, vector_z) # returns element_id add_beam_name = ac.set_name([beam], name) # input beam id (list), name (string) ```