### Run Tests with KiPython (macOS) Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/index.md On macOS, after completing the specific setup steps, use kipython to install dependencies and run the tests. ```bash kipython -m pip install kipython -m pytest tests ``` -------------------------------- ### Run KiCad Gadgets Setup Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Execute the setup script for KiCad gadgets. This is the initial step for configuring the environment. ```bash python -m kigadgets ``` -------------------------------- ### Install Test Requirements Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/index.md Install the dependencies required for running the tests from the provided requirements file. ```bash pip install tests/requirements.txt pytest tests ``` -------------------------------- ### Manual Linking Example Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/linker_underthehood.md An example of the manual linking command, showing how to provide the `pcbnew.py` path and the user settings path. ```bash python -m kigadgets /usr/lib/python3/dist-packages/pcbnew.py /home/username/.config/kicad ``` -------------------------------- ### Install Python Packages with `--user` Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Use the `--user` flag with KiCad's bundled pip to install packages safely in a user-specific directory, preventing system corruption or KiCad installation issues. This is the recommended approach. ```bash $ kipython -m pip install --user numpy tensorflow $ kipython myscript.py ``` -------------------------------- ### Install KiCad Gadgets via PyPI Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/index.md Use pip to install the kigadgets package. The second command links necessary paths for headless scripts and GUI plugins. ```bash pip install kigadgets python -m kigadgets ``` -------------------------------- ### Incorrect Method: Install Packages with kipython Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Demonstrates an incorrect method of installing packages using 'kipython -m pip', which can lead to application-wide installations and potential issues. ```bash $ kipython -m pip install numpy tensorflow ``` -------------------------------- ### Install Dependencies for Script Execution Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Install necessary Python packages for a script that uses third-party libraries, typically done before running the script. ```bash $ python -m pip install numpy tensorflow ``` -------------------------------- ### Install Third-Party Packages for kipython Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Install Python packages for use with 'kipython', ensuring they are available in the KiCad environment. ```bash kipython -m pip install --user numpy ``` -------------------------------- ### Example Script with Third-Party Packages Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md A Python script demonstrating the use of KiCad's pcbnew module along with third-party libraries like numpy and tensorflow. ```python # myscript.py import kigadgets, pcbnew, numpy, tensorflow def do_some_pcb_AI(): ... ``` -------------------------------- ### Install Packages with Mamba and Set PYTHONPATH Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Use Mamba to create an isolated Python environment and install packages. Then, set the PYTHONPATH to include the environment's site-packages directory for kipython to use. ```bash $ kipython --version Python 3.9.13 $ mamba create -n pcbtf python=3.9.13 $ mamba activate pcbtf (pcbtf) $ pip install tensorflow (pcbtf) $ pip show tensorflow ... Location: /Users/username/micromamba/envs/pcbtf/lib/python3.9/site-packages ... $ $ export PYTHONPATH="/Users/username/micromamba/envs/pcbtf/lib/python3.9/site-packages:$PYTHONPATH" $ kipython my_script.py ``` -------------------------------- ### Example of kigadgets interoperability with legacy scripts Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/related_projects.md Demonstrates how kigadgets can be integrated into existing code using `wrap` and `native_obj` to handle version compatibility issues, such as modifying zone clearance. ```python # file: legacy_script.py ... my_zone = get_a_zone_somewhere() # my_zone.SetClearance(my_zone.GetClearance() * 2) # This existing line will not work >v5 ``` -------------------------------- ### Install Python Packages to Custom Path Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Install packages to a custom directory using the `--target` option with KiCad's bundled pip. This allows for creating encapsulated pseudo-environments for Python packages. ```bash $ mkdir -p ~/Documents/KiCad/python3rdparty/site-packages $ kipython -m pip install --target ~/Documents/KiCad/python3rdparty/site-packages numpy tensorflow ``` -------------------------------- ### Execute Script with Dependencies Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Run a Python script that has external dependencies, after ensuring those dependencies are installed. ```bash $ python myscript.py ``` -------------------------------- ### Verify kipython Interpreter Information Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Obtain version and executable path information for the 'kipython' interpreter to verify its setup. ```bash $ kipython --version $ kipython -c "import sys; print('Executable:', sys.executable)" $ kipython -m kigadgets ``` -------------------------------- ### List Indexing for Filtering Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/why_lists.md This example illustrates using list indexing after an initial iteration to filter elements based on a condition, leveraging the fixed order of lists. ```python all_tracks = pcb.tracks thin_tracks = all_tracks[t.width < 1 for t in all_tracks] ``` -------------------------------- ### Get pcbnew Paths Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/linker_underthehood.md Run this command within the pcbnew GUI terminal to retrieve the paths for `pcbnew.__file__` and `pcbnew.SETTINGS_MANAGER.GetUserSettingsPath()`. These paths are crucial for manual linking. ```python import pcbnew; print(pcbnew.__file__, pcbnew.SETTINGS_MANAGER.GetUserSettingsPath()) ``` -------------------------------- ### Access Board Tracks Information Source: https://github.com/atait/kicad-python/blob/main/docs/source/index.md Once a Board object is loaded or recovered, you can access its tracks. This example shows how to retrieve the layer and selected width of tracks, regardless of whether you are in the GUI or running headless. ```python >>> print([track.layer for track in pcb.tracks]) [F.Cu, B.Cu, B.Cu] ``` ```python >>> print([track.width for track in pcb.tracks if track.is_selected]) [0.8, 0.6] ``` -------------------------------- ### List Comprehension with Multiple Sequences Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/why_lists.md This example shows how to use list comprehensions with the `+` operator to combine elements from multiple sequences, a feature available in v5. ```python nets = [t.net_name for t in pcb.tracks + pcb.vias + pcb.zones] ``` -------------------------------- ### Get Single Selected Item (v4 Only) Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/why_lists.md This method of getting a single selected item using `next()` is specific to v4 and will not work in v5. ```python sel = next(pcb.selected_items) ``` -------------------------------- ### Procedural Layout for Track Width Testing Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/snippet_examples.md Generates tracks with varying widths and adds circles and text labels for testing track width resistances. This is an example of procedural layout generation. ```python y = 0 length = 50 widths = [.12, .24, .48, .96] r_contact = 5 for w in widths: pcb.add_track([(0, y), (length, y)], 'F.Cu', width=w) for lay in ['F.Cu', 'F.Mask']: for x in [0, length]: pcb.add_circle((x, y), r_contact / 2, lay, r_contact) pcb.add_text((length/2, y - 2), 'width = {:.2f}mm'.format(w), 'F.SilkS') y += 20 pcbnw.Refresh() ``` -------------------------------- ### Test KiCad Gadgets in GUI Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/index.md After installation, restart KiCad's pcbnew application. Open its terminal and run this Python code to add a circle to the silkscreen layer and refresh the view. ```python pcb.add_circle((100, 100), 20, 'F.Silkscreen'); pcbnew.Refresh() ``` -------------------------------- ### Get Single Selected Item (v5 Only) Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/why_lists.md In v5, you can directly access the first selected item using list indexing. ```python sel = pcb.selected_items[0] ``` -------------------------------- ### Geohash for Board Equivalence Testing Source: https://github.com/atait/kicad-python/blob/main/docs/source/ap_devs/developer_guide.md This example illustrates how the `geohash` method can be used to check for logical equivalence between two `Board` objects, even if their track definitions differ slightly in order. Note that `geohash` is not repeatable between interpreter sessions due to random seeding. ```python pcb1 = Board() pcb1.add_track([(1, 1), (1, 2)]) pcb2 = Board() pcb2.add_track([(1, 2), (1, 1)]) assert pcb1.geohash() == pcb2.geohash() # Succeeds ``` -------------------------------- ### Add Custom Path in Python Script Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Modify your Python script to insert the custom package directory into `sys.path`. This ensures that kipython can locate the installed packages. ```python # myscript.py - edited import sys sys.path.insert(0, '~/Documents/KiCad/python3rdparty/site-packages') import kigadgets, pcbnew, numpy, tensorflow ``` -------------------------------- ### Recover Current Board Object in pcbnew Source: https://github.com/atait/kicad-python/blob/main/docs/source/index.md Use this snippet to get the current Board object when working inside the KiCad pcbnew editor. Ensure the kigadgets.board module is imported. ```python from kigadgets.board import Board pc = Board.from_editor() ``` -------------------------------- ### Add Custom Path to PYTHONPATH Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Set the PYTHONPATH environment variable to include your custom package directory. This allows kipython to find installed packages when running scripts. ```bash $ export PYTHONPATH="~/Documents/KiCad/python3rdparty/site-packages:$PYTHONPATH" $ kipython my_script.py ``` -------------------------------- ### Headless CLI Entry Point for Python Script Source: https://github.com/atait/kicad-python/blob/main/docs/source/ap_devs/developer_guide.md This demonstrates how to execute a Python script directly from the command line in headless mode. The script expects a .kicad_pcb file as an argument. ```bash python my_lib.py some_file.kicad_pcb ``` -------------------------------- ### Track Live Editor State with Kigadgets Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/snippet_examples.md Demonstrates how to add and interact with graphical objects in the PCB editor using kigadgets. It shows how the object's state is synchronized with the native C++ objects and how to capture user input interactively. ```python from kigadgets.drawing import Rectangle my_rect = Rectangle((0,0), (60, 40)) pcb.add(my_rect) pcbnw.Refresh() print(my_rect.x, my_rect.contains((1,1))) # 30 True input('Go move that rectangle. When done, refocus in this terminal and press enter.') # Go move the new rectangle in the editor print(my_rect.x, my_rect.contains((1,1))) # 15.2 False pcb.remove(my_rect) pcbnw.Refresh() ``` -------------------------------- ### Python Script with Multiple Entry Points Source: https://github.com/atait/kicad-python/blob/main/docs/source/ap_devs/developer_guide.md This script demonstrates how to create a Python file that can be run from the command line or imported into the KiCad GUI. It uses a standard `if __name__ == '__main__':` block for headless execution and can be imported for GUI use. ```python # ~/.config/kicad/scripting/my_lib.py (Linux) # ~/Library/Preferences/kicad/scripting/my_lib.py (MacOS) from kigadgets.board import Board import sys import os def do_something(pcb): ... if __name__ == '__main__': pcb = Board.load(sys.argv[1]) do_something(pcb) newname = os.path.splitext(pcb.filename)[0] + '-proc.kicad_pcb' # Prevent overwrite of source file pcb.save(newname) ``` -------------------------------- ### Run Mousebite Plugin via CLI Source: https://github.com/atait/kicad-python/blob/main/docs/source/ap_devs/mousebite_readme.md Execute the mousebite_script.py from the command line, providing the input KiCad PCB file. Use the -h flag for options. The second command shows how to view the processed output. ```bash cd examples/action_plugins python mousebite_kigadget/mousebite_script.py tests/src_layouts/mousebite_api.kicad_pcb ``` ```bash pcbnew tests/src_layouts/mousebite_api-proc.kicad_pcb ``` -------------------------------- ### Print Track Layers and Selected Track Widths Source: https://github.com/atait/kicad-python/blob/main/README.md This excerpt demonstrates basic access to track properties like layer and width, filtering for selected tracks. It showcases the simplified, pythonic access to PCB data. ```python print([track.layer for track in pcb.tracks]) print([track.width for track in pcb.tracks if track.is_selected]) ``` -------------------------------- ### Initialize KiCad GUI Terminal Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/linker_underthehood.md This script is written to the pcbnew GUI's application terminal and runs automatically on shell open. It adds the KiCad Python path to sys.path, allowing `kigadgets` features to be used directly in the GUI terminal. ```python # File (for example): /home/myself/.config/kicad/PyShell_pcbnew_startup.py import sys sys.path.append("/path/to/kicad-python") from kigadgets.board import Board pc b = Board.from_editor() # pcb is now a global variable in the terminal ``` -------------------------------- ### Manual Linking Command Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/linker_underthehood.md Execute this command in your external command line or terminal shell, providing the paths obtained from the pcbnew GUI. This manually links `kigadgets` to the `pcbnew` module. ```bash python -m kigadgets [paste here] ``` -------------------------------- ### Create Symbolic Link for Scripting Directory Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/troubleshooting.md When upgrading KiCad, manage third-party script code by keeping it in a central location and creating symbolic links to the specific version directories. This avoids duplicating script code across different KiCad versions. ```bash ln -s ~/.config/kicad/scripting ~/.config/kicad/7.0/scripting ``` -------------------------------- ### Verify kipython Import Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Test if the 'kipython' executable can successfully import the 'pcbnew' module. ```bash kipython -c "import pcbnew; print('pcbnew import OK')" ``` -------------------------------- ### Activate Mamba Environment and Run Script Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Activate a Mamba environment and run kipython. If the environment's activation script includes the necessary PYTHONPATH export, kipython will find the packages without manual export. ```bash $ mamba activate pcbtf (pcbtf) $ kipython my_script.py ``` -------------------------------- ### List Comprehension with itertools.chain (v4 Equivalent) Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/why_lists.md This demonstrates the v4 approach using `itertools.chain` for combining multiple sequences within a list comprehension. ```python nets = [t.net_name for t in itertools.chain(pcb.tracks, pcb.vias, pcb.zones)] ``` -------------------------------- ### Common Pattern: Filtering Tracks (Works in Both Versions) Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/why_lists.md This common pattern for filtering elements works in both v4 and v5, demonstrating how to collect items that meet a specific condition. ```python thin_tracks = [] for track in pcb.tracks: if track.width < 1: thin_tracks.append(track) ``` -------------------------------- ### Symlink Plugin Directory to Kicad Scripting Path Source: https://github.com/atait/kicad-python/blob/main/docs/source/ap_devs/mousebite_readme.md Use this command to link the plugin directory to your Kicad scripting path for GUI access. Reload external plugins or restart pcbnew afterwards. ```bash ln -s /the/full/path/to/examples/action_plugins/mousebite_kigadget ~/.config/kicad/scripting/plugins ``` -------------------------------- ### Select Similar Vias Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/snippet_examples.md Selects all vias that have the same diameter and drill size as the initially selected via. Deselects the original via after selection. ```python og_via = pcb.selected_items[0] for via2 in pcb.vias: if via2.diameter != og_via.diameter: continue if via2.drill != og_via.drill: continue via2.select() og_via.select(False) pcbnw.Refresh() ``` -------------------------------- ### Add and Manipulate Rectangle with User Input Source: https://github.com/atait/kicad-python/blob/main/README.md Creates a rectangle, adds it to the PCB, prints its properties, prompts the user to move it in the editor, and then removes it after user confirmation. Demonstrates drawing, interaction, and removal of objects. ```python from kigadgets.drawing import Rectangle my_rect = Rectangle((0,0), (60, 40)) pc.add(my_rect) pcnew.Refresh() print(my_rect.x, my_rect.contains((1,1))) # 30 True input('Go move that rectangle. When done, refocus in this terminal and press enter.') # Go move the new rectangle in the editor print(my_rect.x, my_rect.contains((1,1))) # 15.2 False pc.remove(my_rect) pcnew.Refresh() ``` -------------------------------- ### macOS: Create kipython Symlink Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Create a symbolic link on macOS to alias KiCad's Python 3 executable as 'kipython' in the system's PATH. ```bash ln -s "/Applications/KiCad/KiCad.app/Contents/Frameworks/Python.framework/Versions/Current/bin/python3" /usr/local/bin/kipython ``` -------------------------------- ### Behavior in v5: Static Iteration Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/why_lists.md In v5, once a list is created from `pcb.tracks`, subsequent iterations will not reflect additions or deletions to the underlying collection. To account for such changes, a fresh list must be obtained. ```python all_tracks = pcb.tracks # additions or deletions for x in all_tracks: pass # Reflects item changes, but not adds/deletes # additions or deletions for x in all_tracks: pass # Iterates again ``` -------------------------------- ### Iterate Selected Items (Works in Both Versions) Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/why_lists.md This pattern works in both v4 and v5 for iterating over selected items when only one item is expected. ```python for sel in pcb.selected_items: break ``` -------------------------------- ### Load KiCad Board File Externally Source: https://github.com/atait/kicad-python/blob/main/docs/source/index.md This snippet demonstrates how to load a KiCad board file from outside the editor using the Board.load method. This is useful for scripting and batch processing. ```python from kigadgets.board import Board pc = Board.load('my_board.kicad_pcb') ``` -------------------------------- ### Forward and Backward Compatible Zone Handling in KiCad Python Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/related_projects.md Use this pattern to ensure your code works with different versions of KiCad's zone objects. It wraps the zone, allows modifications, and then outlets to the native object for the correct version. ```python from kigadgets.zone import Zone zone_tmp = Zone.wrap(my_zone) # Intake from any version zone_tmp.clearance *= 2 # Version independent my_zone = zone_tmp.native_obj # Outlet to correct version ``` -------------------------------- ### Updating Legacy KiCad Plugins with kigadgets Source: https://github.com/atait/kicad-python/blob/main/docs/source/ap_devs/developer_guide.md This code demonstrates how to update legacy KiCad pcbnew code to be version-independent using `kigadgets`. The `Zone.wrap` and `zone_tmp.native_obj` pattern allows for seamless integration and modification of objects across different KiCad versions. ```python from kigadgets.zone import Zone ... my_zone = get_a_zone_somewhere() ### Begin insertion zone_tmp = Zone.wrap(my_zone) # Intake from any version zone_tmp.clearance *= 2 # Version independent my_zone = zone_tmp.native_obj # Outlet to correct version ### end insertion do_something_else_to(my_zone) ``` -------------------------------- ### Symlink OnePush Plugin Directory to KiCad Scripting Path Source: https://github.com/atait/kicad-python/blob/main/docs/source/ap_devs/onepush_readme.md Use this bash command to symlink the OnePush plugin directory into your KiCad scripting path. This makes the plugin available in the KiCad GUI. ```bash ln -s /the/full/path/to/examples/action_plugins/onepush ~/.config/kicad/9.0/scripting/plugins ``` -------------------------------- ### Set PCBNEW_PATH Environment Variable Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/troubleshooting.md If you encounter permission errors when writing to the package directory, set the PCBNEW_PATH environment variable to the correct path. This is useful for directing KiCad to the correct Python modules. ```bash # In general: export PCBNEW_PATH="[Path A]" export PCBNEW_PATH=/usr/lib/python3/dist-packages/pcbnew.py # For example ``` -------------------------------- ### Select Footprints Connected to Selected Footprint's Nets Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/snippet_examples.md Selects all footprints that share nets with the currently selected footprint, excluding 'GND' and '+5V' nets. ```python footprint = pcb.selected_items[0] nets = {pad.net_name for pad in footprint.pads} nets -= {'GND', '+5V'} # because these are connected to everything for mod in pcb.footprints: if any(pad.net_name in nets for pad in mod.pads): mod.select() ``` -------------------------------- ### GUI Terminal Entry Point for Python Script Source: https://github.com/atait/kicad-python/blob/main/docs/source/ap_devs/developer_guide.md This snippet shows how to call a function from an imported Python script within the KiCad GUI terminal. It assumes the script `my_lib` has already been imported. ```python from my_lib import do_something do_something(pcb) pcbnew.Refresh() ``` -------------------------------- ### macOS: Verify kipython Symlink Location Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Check the location of the 'kipython' executable after creating the symbolic link. ```bash $ which kipython /Applications/KiCad/KiCad.app/Contents/Frameworks/Python.framework/Versions/Current/bin/python3 ``` -------------------------------- ### Behavior in v4: Dynamic Iteration Source: https://github.com/atait/kicad-python/blob/main/docs/source/design/why_lists.md In v4, iterating over a collection like `pcb.tracks` would reflect additions or deletions made during the iteration process. A second iteration after changes could lead to errors. ```python all_tracks = pcb.tracks # additions or deletions for x in all_tracks: pass # Reflects the changes made in between # additions or deletions for x in all_tracks: pass # Errors. We should get a fresh one after all ``` -------------------------------- ### Move Silkscreen Labels to Fab Layers Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/snippet_examples.md Moves silkscreen reference labels to their corresponding fabrication layers. This helps in keeping labels visible during the PCB design process. ```python for m in pcb.footprints: ref = m.reference_label.layer.split('.') # Gives tuple like ('B', 'Silkscreen') if len(ref) > 1 and ref[1].startswith('Silk'): ref.layer = ref[0] + '.Fab' pcbnw.Refresh() ``` -------------------------------- ### Place Silkscreen Over Tracks Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/snippet_examples.md Creates silkscreen lines over existing tracks, slightly increasing their width. This can be used for aesthetic purposes. ```python for t in pcb.tracks: new_width = t.width * 1.1 pcb.add_line(t.start, t.end, 'F.SilkS' if t.layer == 'F.Cu' else 'B.SilkS', new_width) pcbnw.Refresh() ``` -------------------------------- ### Hide Silkscreen Labels of Selected Footprints Source: https://github.com/atait/kicad-python/blob/main/README.md Iterates through footprints, hides the reference label for any selected footprint, and refreshes the PCB view. Useful for cleaning up silkscreen layers. ```python for fp in pcb.footprints: if fp.is_selected: fp.reference_label.visible = False pcnew.Refresh() ``` -------------------------------- ### Hide Silkscreen Labels of Selected Footprints Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/snippet_examples.md Hides the reference labels of selected footprints. Ensure footprints are selected before running. ```python for fp in pcb.footprints: if fp.is_selected: fp.reference_label.visible = False pcbnw.Refresh() ``` -------------------------------- ### Change Drill Diameters Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/snippet_examples.md Modifies the drill diameters of vias within a specific range (0.4mm to 0.6mm) to 0.5mm. Useful for standardizing drill sizes. ```python for v in pcb.vias: if v.drill > 0.4 and v.drill < 0.6: v.drill = 0.5 pcbnw.Refresh() ``` -------------------------------- ### Windows: Define kipython PowerShell Function Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/macos_workaround.md Define a PowerShell function to alias KiCad's Python executable as 'kipython'. This is a common method for persistent aliases on Windows. ```powershell function kipython { & 'C:\\Program Files\\KiCad\\8.0\\bin\\python.exe' @args } ``` -------------------------------- ### Determine KiCad Python Version Source: https://github.com/atait/kicad-python/blob/main/docs/source/getting_started/troubleshooting.md To resolve Python version errors, especially those related to compiled code like '_pcbnew.so', determine the exact Python version KiCad is using. This helps in creating a compatible conda environment. ```python >>> import sys; sys.version_info sys.version_info(major=3, minor=10, ...) ``` -------------------------------- ### Change Drill Diameters for Vias Source: https://github.com/atait/kicad-python/blob/main/README.md Modifies the drill diameter of vias within a specific range (0.4 to 0.6) to 0.5. This is useful for standardizing drill sizes. ```python for v in pcb.vias: if v.drill > 0.4 and v.drill < 0.6: v.drill = 0.5 pcnew.Refresh() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.