A method and system for batch exporting Allegro file packages based on Python
A batch export method written in Python, combined with a graphical interface and the Allegro command-line tool, automates the processing of Allegro PCB file packages, solving the problems of low efficiency and error-proneness in existing technologies, and achieving efficient and accurate multi-file processing.
Patent Information
- Application Number
- CN202510941457.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-09
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2045-07-09
AI Technical Summary
Existing technologies are inefficient, error-prone, and cumbersome when exporting Allegro PCB files in batches, and cannot automate the processing of multiple files.
The batch export method, written in Python, allows users to select files and configure paths through a graphical interface. It automatically loads pre-recorded Skill scripts, uses the Allegro command-line tool to export and package the files in batch mode, and avoids human error through automatic path configuration and exception handling mechanisms.
It enables efficient and automated processing of multiple files, reduces manual operations, avoids path configuration errors, and improves the accuracy and efficiency of operations.
Smart Images

Figure CN120449236B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of PCB design technology, and in particular to a method and system for batch exporting Allegro file packages based on Python. Background Technology
[0002] When you need to export footprints from multiple Allegro PCB project files, the following methods are currently available:
[0003] 1. Manual Export: When exporting component footprints using Allegro software, if a user needs to export component footprints from multiple PCB files, they need to open each PCB file individually and manually perform the export operation on each PCB file one by one.
[0004] 2. Record and call a script: By pre-recording preset export commands and export paths, multiple files can be opened and called one by one to export the footprints of multiple PCB files.
[0005] However, existing export and packaging methods have the following problems:
[0006] 1. Inefficient; manual repetitive operations cannot process multiple files in batches, resulting in significant time consumption.
[0007] 2. Prone to errors; manual export may result in incorrect path configuration or missing files.
[0008] 3. Recording script files is time-consuming and inflexible. When reusing recorded script files, you don't need to click the export operation repeatedly, but you still need to manually open the corresponding files one by one.
[0009] Therefore, there is an urgent need for a method to batch export Allegro file packages. Summary of the Invention
[0010] To address the problems in the existing technology, this invention provides a method and system for batch exporting Allegro files based on Python.
[0011] This invention is specifically achieved through the following technical solution:
[0012] A method for batch exporting Allegro files using Python, comprising the following steps:
[0013] Configure the Allegro executable file path and the pre-recorded Skill script path;
[0014] Select the target export directory through the graphical interface and update the export path parameter in the Skill script;
[0015] Batch select Allegro PCB files to be processed through a graphical interface;
[0016] Verify the file list and export path, and start batch processing after confirmation;
[0017] Traverse the file list and execute the following for each Allegro PCB file to be processed:
[0018] - Call the Allegro command-line tool to open the PCB file in batch mode;
[0019] - Automatically load a pre-recorded Skill script to perform the package export operation;
[0020] - Capture and feedback the command-line execution status.
[0021] As a further improvement of the present invention, the method further includes: before configuring the path, loading 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.
[0022] 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.
[0023] 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.
[0024] As a further improvement of the present invention, the instruction format for calling the Allegro command-line tool is:
[0025] allegro.exe -nx -batch -open <PCB file path> -s <Skill script path>,
[0026] where "-nx" means not to start the graphical interface, and "-batch" means batch mode.
[0027] On the other hand, the present invention also provides a system for implementing the above method, and the system includes:
[0028] Path configuration module: Initialize the Allegro execution path and Skill script path;
[0029] Interaction module: Provide a graphical interface to implement directory selection, file selection, and operation confirmation;
[0030] Script update module: Dynamically modify the export path in Skill scripts;
[0031] Batch processing engine: Iterates through the list of files and calls the command line to execute the export operation.
[0032] The beneficial effects of this invention are: the method and system for batch exporting Allegro files based on Python can improve efficiency, support automatic batch processing of multiple files, and reduce manual operation; it has a zero error rate, avoiding human error through automatic path configuration and exception capture mechanism; it is user-friendly, simplifying operation steps while lowering the operation threshold and making it easy to operate. Attached Figure Description
[0033] Figure 1 This is a flowchart of the method of the present invention;
[0034] Figure 2 This is a flowchart of the Python program that implements the method of this invention. Detailed Implementation
[0035] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0036] like Figure 1 As shown, the method for batch exporting Allegro files based on Python according to the present invention includes the following steps:
[0037] S1. Configure the Allegro executable file path and the pre-recorded Skill script path;
[0038] S2. Select the target export directory through the graphical interface and update the export path parameter in the Skill script;
[0039] S3. Select Allegro PCB files to be processed in batches through the graphical interface;
[0040] S4. Verify the file list and export path, and start batch processing after confirmation;
[0041] S5. Traverse the file list and execute the following for each Allegro PCB file to be processed: Invoke 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 report the command line execution status.
[0042] In step S2, a pop-up folder selection dialog box is used to remind the user to select the export directory, i.e., the export folder.
[0043] Figure 2 This is a flowchart of the Python program that implements the method of this invention. The following sections will introduce each functional module in turn.
[0044] 1. Load the necessary Python dependency libraries
[0045] import subprocess
[0046] import os
[0047] from pathlib import Path
[0048] import tkinter as tk
[0049] from tkinter import filedialog, messagebox
[0050] `subprocess` is used to call external command-line programs in Python and capture their output. `os` and `pathlib.Path` provide file system operations, including checking file existence and reading paths. `tkinter` provides a powerful GUI toolset for building graphical user interfaces (GUIs), such as file selection dialogs and message boxes. `tkinter.filedialog` is an interactive dialog for file and directory selection. `tkinter.messagebox` is used to display simple information or error messages.
[0051] II. main() function
[0052] As the main program entry point, it is responsible for coordinating the interactions between all secondary modules and providing complete flow control logic.
[0053] 1. Set the initial path:
[0054] The `allegro_executable_path=r"D:\Cadence\Cadence_SPB_17.4-2019\tools\bin\allegro.exe"` setting defines the startup path for the Allegro software program.
[0055] The `skill_script_path=r"D:\Cadence\Cadence_SPB_17.4-2019\share\local\pcb\skill\FanySkill\SKILL\export-lib.il"` directive defines the path to the Skill script file.
[0056] 2. Configure the export directory:
[0057] Call the select_folder() and update_skill_script_path() functions to set the export target folder and record it.
[0058] 3. Select the list of files to process:
[0059] while True:
[0060] select_files(files_to_process)
[0061] …
[0062] The main loop continuously prompts the user to enter a new PCB file and adds it to the list of files to be processed.
[0063] 4. Confirm and start batch processing:
[0064] if show_selected_files(files_to_process, export_folder):
[0065] break
[0066] else:
[0067] continue_choice = ...
[0068] After each file is selected, the `show_selected_files()` function is called to display the selected content and request user confirmation to continue. If the user agrees, the loop exits; otherwise, the user is asked whether they want to continue.
[0069] 5. Perform batch processing:
[0070] if files_to_process:
[0071] try:
[0072] batch_process_files(allegro_executable_path, files_to_process) ...
[0073] except Exception as e: ...
[0074] If the file list is not empty, `batch_process_files()` is called to begin the actual batch processing. If a problem occurs during the process, an error message is displayed; otherwise, a message indicating successful completion is displayed.
[0075] 6. Prompt the user: Use messagebox.showerror(), messagebox.askyesno(), and messagebox.showinfo() to pop up the corresponding information windows to inform them of the processing progress or result.
[0076] III. The select_folder() function
[0077] A pop-up directory selection dialog box allows the user to specify a target folder path to save the exported results. This provides a simple and intuitive way to specify the location of the exported files, enhancing the program's functionality and usability.
[0078] 1. Create a hidden main window:
[0079] root = tk.Tk()
[0080] root.withdraw() # Hides the main window
[0081] By using the tkinter module in Python, a graphical user interface can be created, and the root window can be hidden using the withdraw() function, so that subsequent operations can be performed in the background without affecting the user's visual experience.
[0082] 2. Open the directory selection dialog box:
[0083] folder_selected = filedialog.askdirectory(title="Select the folder to save the exported package"),
[0084] Calling filedialog.askdirectory() allows the user to specify a folder path.
[0085] 3. Verify the user's selection:
[0086] if folder_selected:
[0087] raise ValueError("No folder selected.")
[0088] If the user does not select any folder, an exception is thrown and the user is prompted to select again. This ensures that all operations have a valid output target.
[0089] 4. Return Selected Path: Returns the actual path string of the selected folder for later use.
[0090] IV. Record and specify the save location for the Skill script:
[0091] By recording the Allegro export process, the export instructions are obtained. These instructions are then saved to the export-lib.il file and placed in the specified directory.
[0092] The Skill script content is as follows:
[0093] dlib
[0094] setwindow form.dlib
[0095] FORM dlib compress_etch NO
[0096] FORM dlib nodepend YES
[0097] FORM dlib browse_export
[0098] fillin "C:\Users\ZFD\Desktop\lib"
[0099] FORM dlib execute
[0100] FORM dlib cancel
[0101] setwindow pcb
[0102] generaledit
[0103] exit
[0104] V. The update_skill_script_path() function
[0105] Used to update the output path parameter value defined in the Skill script. It provides support for Skill script configuration files, allowing users to easily update the export location.
[0106] 1. Read and parse the file:
[0107] with open(skill_script_path, 'r') as file:
[0108] lines = file.readlines()
[0109] Open the Skill script in the specified path to read all lines.
[0110] 2. Update specific parameter values:
[0111] for i, line in enumerate(lines):
[0112] if "fillin" is in line:
[0113] lines[i] = f'fillin "{new_export_path}"\n'
[0114] break
[0115] Iterate through each line, find the line containing the keyword "fillin", and replace the original content with the new export path.
[0116] 3. Write back the file:
[0117] with open(skill_script_path, 'w') as file:
[0118] file.writelines(lines)
[0119] Save the modified content back to the original Skill script file.
[0120] 4. Return the operation result:
[0121] Although the function does not return a direct value, it ensures that the Skill script can use the latest export path.
[0122] VI. The select_files() function
[0123] This dialog box pops up a file selection dialog, allowing users to select Allegro PCB files from their computer to be processed in batches and add these files to a given list. Making it easy for users to select the PCB files to be processed via this dialog box is a prerequisite for batch operations.
[0124] 1. Create a hidden main window:
[0125] root = tk.Tk()
[0126] root.withdraw() # Hides the main window
[0127] Similarly, use tk.Tk() and then use withdraw() to immediately hide the main window to avoid displaying unnecessary GUI.
[0128] 2. Display the file selection dialog box:
[0129] new_files = filedialog.askopenfilenames(
[0130] title="Select the Allegro file to export and package",
[0131] filetypes=[("Allegro Files", "*.brd"), ("All Files", "*.*")] )
[0133] Use filedialog.askopenfilenames() to let the user select multiple files and return a tuple containing all selected paths.
[0134] 3. Process the selected file:
[0135] if new_files:
[0136] file_list.extend(new_files)
[0137] print(f"Files selected: {new_files}")
[0138] If the user selects a file, add it to the list of existing files and print a confirmation message.
[0139] VII. The show_selected_files() function
[0140] This function displays a list of selected files and the specified export directory path, prompting the user for confirmation before proceeding with batch processing. `show_selected_files()` is another key part of the user interaction mechanism; 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 errors.
[0141] 1. Check the file list:
[0142] if not file_list: ...
[0143] return False
[0144] If file_list is empty, a dialog box will pop up to inform the user that no file has been selected.
[0145] 2. Construct the information string:
[0146] selected_files_msg = "\n".join([str(Path(f).name) for f in file_list])
[0147] The selected file is split line by line to form an easy-to-read information string.
[0148] 3. Display a dialog box and request confirmation:
[0149] response = messagebox.askokcancel(
[0150] "Selected Files", ... )
[0152] return response
[0153] A dialog box appears displaying all selected files and their target export paths, asking the user if they want to begin processing.
[0154] 4. Return to confirmation status:
[0155] Returns a boolean value indicating the user's confirmation. This information is used to decide whether to continue batch processing.
[0156] 8. The batch_process_files() function
[0157] Perform batch processing on a given set of multiple Allegro PCB files, that is, call the open_allegro_file() function sequentially to open each file.
[0158] 1. Traverse the file list:
[0159] for file_path in files_list:
[0160] try:
[0161] open_allegro_file(allegro_executable, file_path, skill_script)
[0162] except Exception as e:
[0163] print(f"An error occurred while processing file {file_path}: {e}")
[0164] Iterate through each path in files_list and pass them one by one to open_allegro_file().
[0165] 2. Error handling:
[0166] except Exception as e:
[0167] print(f"An error occurred while processing file {file_path}: {e}")
[0168] Capture and log any exceptions during each attempt to open a new file to prevent the entire batch processing process from being interrupted by a single failure.
[0169] 9. The open_allegro_file() function
[0170] Launch Cadence Allegro software, open the specified PCB file, and optionally execute the Skill script to further process the data.
[0171] 1. Check the file path:
[0172] if not os.path.isfile(allegro_executable):
[0173] raise FileNotFoundError(f"Invalid path to Allegro executable: {allegro_executable}")
[0174] if not os.path.isfile(file_path):
[0175] raise FileNotFoundError(f"Invalid path to the Allegro file to open: {file_path}")
[0176] Verify that allegro_executable and file_path exist.
[0177] 2. Construct command-line arguments:
[0178] command = [
[0179] allegro_executable,
[0180] "-nx",
[0181] "-batch",
[0182] "-open", file_path ]
[0184] if skill_script and os.path.isfile(skill_script):
[0185] command.extend(["-s", skill_script])
[0186] Combine the necessary command-line options into a list so that they can be executed via subprocess.run().
[0187] 3. Run the command and process the results:
[0188] result = subprocess.run(command, check=True, capture_output=True, text=True)
[0189] print(f"Successfully processed file: {file_path}")
[0190] print(f"Standard output: {result.stdout}")
[0191] print(f"Standard Error: {result.stderr}")
[0192] Use `subprocess.run()` to execute Allegro commands and capture standard output and errors.
[0193] 4. Exception Handling:
[0194] except subprocess.CalledProcessError as e: ...
[0195] except Exception as e: ...
[0196] If any exception occurs (such as command execution failure), print detailed error information and throw the corresponding exception.
[0197] 10. if __name__ == "__main__": main() module
[0198] This is the standard Python mode for executing the `main()` function when the script runs as a standalone program. If the current file is a directly imported module rather than being called by another script, the `main()` function will start immediately to begin batch processing. This ensures that the main program can be easily started from the command line or other environments without relying on external environment variables or passed parameters.
[0199] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.
Claims
1. A method for bulk exporting Allegro file encapsulation based on Python, characterized in that, The method comprises the following steps: Loading necessary Python dependency library files for user interface interaction, file operation, script invocation, error handling and feedback, batch processing execution control; Configuring Allegro executable file path and pre-recorded Skill script path; Selecting target export directory through graphical interface and updating export path parameters in Skill script; Batch selecting Allegro PCB files to be processed through graphical interface; Verifying file list and export path, and starting batch processing after confirmation; Iterating through the file list and performing the following operations on each Allegro PCB file to be processed: Invoking Allegro command line tool to open the PCB file in batch mode; Automatically loading pre-recorded Skill script to perform package export operation; Capturing and feeding back command line execution status, including successful completion and error occurrence.
2. The method of claim 1, wherein: The pre-recorded Skill script contains: setting package export parameter instructions; configuring placeholder for export directory path; instruction sequence for performing export and exit operation.
3. The method of claim 1, wherein: The update of export path parameters in Skill script includes: reading Skill script file content; locating key line containing path parameters; replacing path parameters with user-selected export directory path; writing modified content back to original script file.
4. The method of claim 1, wherein: The instruction format for invoking Allegro command line tool is: allegro.exe -nx -batch -open <PCB file path> -s <Skill script path>, Where "-nx" means not to start graphical interface, and "-batch" means batch mode.
5. A system for the method according to any one of claims 1 to 4, characterized in that The system comprises: Library file loading module: loading necessary Python dependency library files for user interface interaction, file operation, script invocation, error handling and feedback, batch processing execution control; Path configuration module: initializing Allegro execution path and Skill script path; Interaction module: providing graphical interface to realize directory selection, file selection and operation confirmation; Script update module: dynamically modifying export path in Skill script; Batch processing engine: iterating through file list and invoking command line to perform export operation.
6. A computer program product, characterised in that, The computer program product comprises a computer program stored in a non-transitory computer readable storage medium, and at least one processor of a computer reads and executes the computer program from the storage medium, so that the computer executes the steps of the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Method and device for exporting single packaging part based on Allegro software
CN117473923A