Method and system for exporting Allegro file packages in batches based on Python

Through the combination of Python scripts and graphical interfaces, batch export of Allegro file encapsulation is realized, solving the problems of inefficiency and error-prone in the existing technology, and improving processing efficiency and accuracy.

CN120449236AActive Publication Date: 2025-08-08SHENZHEN COLORFUL YUGONG TECH DEV CO LTD

Patent Information

Application Number
CN202510941457.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-09
Publication Date
2025-08-08
Estimated Expiration
2045-07-09

AI Technical Summary

Technical Problem

The prior art is inefficient when exporting Allegro PCB file encapsulation, error prone and inflexible enough to achieve batch processing of multiple files.

Method used

Through the combination of Python scripts and graphical interface, the Allegro executable file path and the pre-recorded Skill script path are configured to batch select files and automatically perform encapsulation and export operations. Use the Allegro command line tool to open files in batch mode and load pre-recorded Skill scripts to capture and feedback the execution status.

Benefits of technology

It realizes efficient and automatic processing of multiple files, avoids human errors, simplifies operation steps, and improves operation convenience and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120449236A_ABST
    Figure CN120449236A_ABST
Patent Text Reader

Abstract

The invention provides a method and a system for exporting Allegro file packages in batches based on Python. The method comprises the following steps: configuring an Allegro executable file path and a pre-recorded Skill script path; selecting a target export directory through a graphical interface, and updating export path parameters in the Skill script; selecting Allegro PCB files to be processed in batches through a graphical interface; verifying the file list and the export path, and starting batch processing after confirmation; traversing the file list, and executing the following steps on each Allegro PCB file to be processed: calling an Allegro command line tool, and opening the PCB file in a batch processing mode; automatically loading a pre-recorded Skill script to execute a packaging and exporting operation; and capturing and feeding back a command line execution state. The efficiency can be improved, multi-file batch automatic processing is supported, and manual operation is reduced; human errors are avoided through automatic path configuration and an exception capture mechanism; the interaction is friendly, and the operation threshold is reduced while the operation steps are simplified.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of PCB design, and in particular to a method and system for batch exporting Allegro file packages based on Python. Background Art

[0002] When you need to export footprints from multiple Allegro PCB project files, you can currently use the following methods: 1. Manually export one by one: When using Allegro software to export file packages, when the user needs to export component packages from multiple PCB files, it is necessary to open multiple PCB files one by one and manually perform the export operation on each PCB file one by one.

[0003] 2. Call after recording the script: By recording the preset export instructions and export path in advance, open multiple files and call them one by one to realize the package of exporting multiple PCB files. However, the existing export package method has the following problems: 1. Low efficiency. Manual repetitive operations cannot process multiple files in batches and are very time-consuming.

[0004] 2. Error-prone. Manual export may result in incorrect path configuration or missing files.

[0005] 3. Recording script files is time-consuming and inflexible. When reusing recorded script files, you do not need to repeatedly click the export operation, but you still need to manually open the corresponding files one by one.

[0006] Therefore, there is an urgent need for a method to batch export Allegro file packages. Summary of the Invention

[0007] In order to solve the problems in the prior art, the present invention provides a method and system for batch exporting Allegro file packages based on Python.

[0008] The present invention is specifically implemented through the following technical solutions: A method for batch exporting Allegro file packages based on Python, comprising the following steps: Configure the Allegro executable file path and the pre-recorded Skill script path; Select the target export directory through the graphical interface and update the export path parameters in the Skill script; Batch select Allegro PCB files to be processed through the graphical interface; Verify the file list and export path, and start batch processing after confirmation; Traverse the file list and perform the following operations on each Allegro PCB file to be processed: - Call the Allegro command-line tool to open the PCB file in batch mode; - Automatically load the pre-recorded Skill script to perform the package export operation; - Capture and feedback the command-line execution status.

[0009] As a further improvement of the present invention, the method further includes: before configuring the path, load the necessary Python dependency library files, which are used for user interface interaction, file operation, script call, error handling and feedback, and batch execution control.

[0010] As a further improvement of the present invention, the pre-recorded Skill script includes: instructions for setting package export parameters; placeholders for configuring the export directory path; and an instruction sequence for performing export and exit operations.

[0011] As a further improvement of the present invention, updating the export path parameter in the Skill script includes: reading the content of the Skill script file; locating the key line containing the path parameter; replacing the path parameter with the export directory path selected by the user; and writing the modified content back to the original script file.

[0012] As a further improvement of the present invention, the instruction format for calling the Allegro command-line tool is: allegro.exe -nx -batch -open <PCB file path> -s <Skill script path>, where "-nx" means not to start the graphical interface, and "-batch" means batch mode.

[0013] On the other hand, the present invention also provides a system for implementing the above method, and the system includes: Path configuration module: Initialize the Allegro execution path and the Skill script path; Interaction module: Provide a graphical interface to implement directory selection, file selection, and operation confirmation; Script update module: Dynamically modify the export path in the Skill script; Batch processing engine: Traverse the file list and call the command line to perform the export operation.

[0014] The beneficial effects of the present invention are as follows: the method and system for batch exporting Allegro file encapsulation based on Python can improve efficiency, support automatic batch processing of multiple files, and reduce manual operations; have a zero error rate, avoid human errors through automatic path configuration and exception capture mechanisms; are interactive and friendly, simplify operating steps while lowering the operating threshold, and are easy to operate. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 is a flow chart of the method of the present invention; Figure 2 It is a logical flow chart of a Python program for implementing the method of the present invention. DETAILED DESCRIPTION

[0016] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.

[0017] like Figure 1 As shown, the method for exporting Allegro file encapsulation in batches based on Python of the present invention comprises the following steps: S1. Configure the Allegro executable file path and the pre-recorded Skill script path; S2. Select the target export directory through the graphical interface and update the export path parameters in the Skill script; S3. Batch select Allegro PCB files to be processed through the graphical interface; S4. Verify the file list and export path, and start batch processing after confirmation; S5. Traverse the file list and execute for each Allegro PCB file to be processed: call the Allegro command line tool to open the PCB file in batch mode; automatically load the pre-recorded Skill script to perform the package export operation; capture and feedback the command line execution status.

[0018] Among them, in step S2, a folder selection dialog box is popped up to remind the user to select an export directory, that is, an export folder.

[0019] Figure 2 It is a logical flow chart of the Python program for realizing the method of the present invention. Below we will start with each functional module of the program and introduce each functional module one by one.

[0020] 1. Loading Python's necessary dependency libraries import subprocess import os from pathlib import Path import tkinter as tk from tkinter import filedialog, messagebox Among them, subprocess: Used to call external command-line programs in Python and capture their output. os and pathlib.Path: Provide functions for file system operations, including checking whether a file exists and reading the path. tkinter: Provides a powerful GUI toolkit for building graphical user interfaces (GUIs), such as file selection dialogs and message boxes. tkinter.filedialog: Interactive dialog boxes for selecting files and directories. tkinter.messagebox: Used to display simple information or error prompt windows.

[0021] 2. main() function As the main program entry point, it is responsible for coordinating the interactions between all secondary modules and providing complete process control logic.

[0022] 1. Set the initial path: allegro_executable_path=r"D:\Cadence\Cadence_SPB_17.4-2019\tools\bin\allegro.exe" is used to define the Allegro software program startup path.

[0023] skill_script_path=r"D:\Cadence\Cadence_SPB_17.4-2019\share\local\pcb\skill\FanySkill\SKILL\export-lib.il" is used to define the path of the Skill script file.

[0024] 2. Configure the export directory: Call the select_folder() function and update_skill_script_path() function to set the export target folder and record it.

[0025] 3. Select the processing file list: while True: select_files(files_to_process) … In the main loop, the user is continuously prompted to enter a new PCB file and added to the list of files to be processed.

[0026] 4. Confirm and start batch processing: if show_selected_files(files_to_process, export_folder): break else: continue_choice = ... After each file is selected, the show_selected_files() function is called to display the selected content and ask the user to confirm whether to continue. If the user agrees, the loop is exited; otherwise, it is asked whether to continue.

[0027] 5. Perform batch processing: if files_to_process: try: batch_process_files(allegro_executable_path, files_to_process) ... except Exception as e: ... If the file list is not empty, batch_process_files() is called to start the actual batch processing process. If there is a problem during the process, an error message will be popped up; otherwise, a message indicating successful completion will be displayed.

[0028] 6. Prompt the user: Use messagebox.showerror(), messagebox.askyesno(), and messagebox.showinfo() to pop up the corresponding information window to inform the processing progress or results.

[0029] 3. select_folder() function A directory selection dialog pops up, allowing the user to specify a target folder path for the exported results. This provides a simple and intuitive way to specify the location of the exported files, enhancing the program's functionality and practicality.

[0030] 1. Create a hidden main window: root = tk.Tk() root.withdraw() # Hide the main window A graphical user interface is created using the tkinter module in Python, and the root window is hidden using withdraw() so that subsequent operations can be performed in the background without affecting the user's visual experience.

[0031] 2. Open the directory selection dialog box: folder_selected = filedialog.askdirectory(title="Select the folder to save the exported package"), Call filedialog.askdirectory() to let the user specify a folder path.

[0032] 3. Verify the user's choice: if not folder_selected: raise ValueError("No folder selected.") If the user does not select any folder, an exception is thrown and the user is asked to reselect. This ensures that all operations have a valid output destination.

[0033] 4. Return the selected path: Return the actual path string of the selected folder for subsequent use.

[0034] 4. Record and save the Skill script: By recording the steps of exporting the package using Allegro, you can obtain the export package instructions. Then, save the exported package instructions to the export-lib.il file and store it in the specified directory.

[0035] The Skill script content is as follows: dlib setwindow form.dlib FORM dlib compress_etch NO FORM dlib nodepend YES FORM dlib browse_export fillin "C:\Users\ZFD\Desktop\lib" FORM dlib execute FORM dlib cancel setwindowpcb generaledit exit 5. update_skill_script_path() function Used to update the output path parameter value defined in the skill script. Support for skill script configuration files is provided, allowing users to easily update the export location.

[0036] 1. Read and parse the file: with open(skill_script_path, 'r') as file: lines = file.readlines() Open the Skill script in the specified path to read all lines.

[0037] 2. Update specific parameter values: for i, line in enumerate(lines): if "fillin" in line: lines[i] = f'fillin "{new_export_path}"\n' break Iterate over each line, look for the one containing the "fillin" keyword, and replace the original content with the new export path.

[0038] 3. Write back the file: with open(skill_script_path, 'w') as file: file.writelines(lines) Save the modified content back to the original Skill script file.

[0039] 4. Return the operation result: Although this function does not directly return a value, it ensures that the Skill script can use the latest export path.

[0040] 6. select_files() function This pops up a file selection dialog box, allowing the user to select Allegro PCB files to be batch processed from their computer and add them to the given list. This pop-up dialog box allows the user to easily select the PCB files to be processed, which is also a prerequisite for batch operation.

[0041] 1. Create a hidden main window: root = tk.Tk() root.withdraw() # Hide the main window Also use tk.Tk() and use withdraw() to immediately hide the main window to avoid showing unnecessary GUI.

[0042] 2. Display the file selection dialog box: new_files = filedialog.askopenfilenames( Title="Select the Allegro file to export the package", filetypes=[("Allegro Files", "*.brd"), ("All Files", "*.*")] ) Use filedialog.askopenfilenames() to let the user select multiple files and return a tuple containing all the selected paths.

[0043] 3. Process the selected files: if new_files: file_list.extend(new_files) print(f"Selected files: {new_files}") If the user selects a file, it is added to the existing file list and a confirmation message is printed.

[0044] 7. show_selected_files() function Used to display the selected file list and the specified export directory path, and request the user to confirm whether to continue batch processing. show_selected_files() is another key part of implementing user interaction. It provides a preview of the selected files and allows the user to make a final confirmation before starting processing. This improves the user experience and reduces the possibility of accidental operation.

[0045] 1. Check the file list: if not file_list: ... return False If file_list is empty, a dialog box pops up to inform the user that no file has been selected.

[0046] 2. Build the information string: selected_files_msg = "\n".join([str(Path(f).name) for f in file_list]) Separate the selected files into lines to form a human-readable string of information.

[0047] 3. Display a dialog box and request confirmation: response = messagebox.askokcancel( "Selected Files", ... ) return response Displays a dialog box containing all selected files and their export destinations, and asks the user if they want to start processing.

[0048] 4. Return to confirmation status: Returns a Boolean value indicating the user's confirmation. This information is used to decide whether to continue batch processing.

[0049] 8. batch_process_files() function Perform batch processing on multiple given Allegro PCB files, that is, call the open_allegro_file() function in turn to open each file.

[0050] 1. Traverse the file list: for file_path in files_list: try: open_allegro_file(allegro_executable, file_path, skill_script) except Exception as e: print(f"An error occurred while processing file {file_path}: {e}") Traverse each path in files_list and pass them to open_allegro_file() one by one.

[0051] 2. Error handling: except Exception as e: print(f"An error occurred while processing file {file_path}: {e}") Catch and log any exceptions during each attempt to open a new file to prevent the entire batch process from being interrupted by a single failure.

[0052] 9. open_allegro_file() function Launches the Cadence Allegro software, opens the specified PCB file, and optionally executes a Skill script to further process the data.

[0053] 1. Check the file path: if not os.path.isfile(allegro_executable): raise FileNotFoundError(f"Invalid Allegro executable path: {allegro_executable}") if not os.path.isfile(file_path): raise FileNotFoundError(f"The Allegro file path to be opened is invalid: {file_path}") Verify that allegro_executable and file_path exist.

[0054] 2. Build command line parameters: command = [ allegro_executable, "-nx", "-batch", "-open", file_path ] if skill_script and os.path.isfile(skill_script): command.extend(["-s", skill_script]) Assembles the necessary command-line options into a list for execution via subprocess.run().

[0055] 3. Run the command and process the results: result = subprocess.run(command, check=True, capture_output=True, text=True) print(f"Successfully processed file: {file_path}") print(f"Standard output: {result.stdout}") print(f"Standard error: {result.stderr}") Use subprocess.run() to execute Allegro commands and capture standard output and error.

[0056] 4. Exception handling: except subprocess.CalledProcessError as e: ... except Exception as e: ... If any exception occurs (such as command execution failure), detailed error information is printed and the corresponding exception is thrown.

[0057] 10. if __name__ == "__main__": main() module This is the standard Python mode for executing the main() function when running a script as a standalone program. If the current file is a module that is directly imported rather than called by another script, the main() function is immediately launched to begin batch processing. This ensures that the main program can be easily launched from the command line or other environments without relying on external environment variables or parameter passing.

[0058] The above is a further detailed description of the present invention in conjunction with specific preferred embodiments, and the specific implementation of the present invention should not be considered to be limited to these descriptions. For those skilled in the art of the present invention, without departing from the concept of the present invention, several simple deductions or substitutions can be made, which should be considered to fall within the scope of protection of the present invention.

Claims

1. A method for batch exporting Allegro file packages based on Python, characterized in that: The method includes the following steps: Configure the path of the Allegro executable file and the path of the pre-recorded Skill script; Select the target export directory through the graphical interface and update the export path parameter in the Skill script; Batch select the Allegro PCB files to be processed through the graphical interface; Verify the file list and the export path, and start batch processing after confirmation; Traverse the file list and execute for each Allegro PCB file to be processed: - Call the Allegro command-line tool to open the PCB file in batch mode; - Automatically load the pre-recorded Skill script to execute the package export operation; - Capture and feedback the command-line execution status.

2. The method according to claim 1, wherein: The method further includes: before configuring the path, load the necessary Python dependency library files, which are used for user interface interaction, file operation, script call, error handling and feedback, and batch processing execution control.

3. The method according to claim 1, wherein: The pre-recorded Skill script includes: instructions for setting package export parameters; placeholders for configuring the export directory path; and an instruction sequence for executing export and exit operations.

4. The method according to claim 1, wherein: The updating of the export path parameter in the Skill script includes: reading the content of the Skill script file; locating the key line containing the path parameter; replacing the path parameter with the export directory path selected by the user; and writing the modified content back to the original script file.

5. The method according to claim 1, wherein: The instruction format for calling the Allegro command-line tool is: allegro.exe -nx -batch -open <PCB file path> -s <Skill script path>, where "-nx" means not to start the graphical interface, and "-batch" means batch mode.

6. A system according to any one of claims 1 to 5, characterized in that: The system includes: Path configuration module: Initialize the Allegro execution path and the Skill script path; Interaction module: Provide a graphical interface to implement directory selection, file selection, and operation confirmation; Script update module: Dynamically modify the export path in the Skill script; Batch processing engine: Traverse the file list and call the command line to execute the export operation.

7. A computer program product, characterized in that The computer program product includes a computer program, which is stored in a non-transitory computer-readable storage medium. At least one processor of the computer reads and executes the computer program, so that the computer executes the steps of the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Data processing method and device, storage medium and electronic equipment

    CN113468836A

  • Python-based EDA software secondary development system

    CN115113860A

  • Method and device for exporting single packaging part based on Allegro software

    CN117473923A

Cited By

  • PCB light painting file rapid output method based on rule engine

    CN120670389A

  • A method for fast output of PCB photoplot files based on a rule engine

    CN120670389B