Hướng dẫn bắt đầu nhanh với SDK Altium Designer

Sơ lược

Xây dựng tiện ích mở rộng tùy chỉnh đầu tiên cho Altium Designer với hướng dẫn SDK từng bước này. Làm theo quy trình từ thiết lập công cụ phát triển và tạo dự án C# đến thêm và chạy lệnh hiển thị tên các net trong sơ đồ nguyên lý hoặc dự án. Bạn cũng sẽ tìm thấy tùy chọn mẫu dòng lệnh có hỗ trợ tải lại nóng (hot reload). Hãy đọc tiếp để bắt đầu những bước đầu tiên trong việc mở rộng chức năng của Altium Designer.

- Nắm rõ các điều kiện tiên quyết và các bước thiết lập để phát triển tiện ích mở rộng bằng SDK.
- Tìm hiểu cách triển khai, đăng ký và chạy lệnh “Show Nets” trong Altium Designer.
- Tìm mẫu dòng lệnh và các tài liệu tham khảo cho tiện ích mở rộng tiếp theo của bạn.
Tìm hiểu sâu hơn với AI:

Altium Designer SDK hiện đang trong giai đoạn Beta kín và chỉ dành cho một số ít khách hàng được chọn để truy cập sớm.

Altium Designer SDK cho phép bạn xây dựng các tiện ích mở rộng tùy chỉnh tích hợp trực tiếp vào Altium Designer – bổ sung lệnh, tự động hóa quy trình làm việc và truy cập dữ liệu thiết kế thông qua API .NET được quản lý.

Hướng dẫn này sẽ giúp bạn cài đặt các công cụ phát triển, tạo dự án tiện ích mở rộng, thêm lệnh và chạy lệnh đó trong Altium Designer.

Prefer the command line? Mẫu tiện ích mở rộng Altium Designer tạo một tiện ích mở rộng C# hoàn chỉnh với một lệnh mà không cần trình hướng dẫn trong ứng dụng hay Visual Studio, và hot-reloads your code while Altium Designer keeps running.

dotnet new install Altium.Designer.Extension.Templates
dotnet new ad-extension -n MyTools --altium-system-dir "C:\Program Files\Altium\AD26\System"

yêu cầu Altium Designer 24 trở lên cùng .NET SDK 8 trở lên (.NET SDK 10 cho Altium Designer 26.12 trở lên). Mã lệnh trong Step 3 bên dưới hoạt động tương tự trong dự án được tạo từ mẫu.

Điều kiện tiên quyết

  • Đăng ký tham gia Altium Developer Center – bắt buộc để có quyền truy cập Altium Designer SDK và các tiện ích mở rộng của SDK

  • Altium Designer đã được cài đặt và cấp phép

  • Một IDE tương thích với .NET (Visual Studio hoặc VS Code có hỗ trợ C#)

Bước 1: Cài đặt tiện ích mở rộng Altium Developer

Tiện ích mở rộng Altium Developer bổ sung các mẫu dự án và công cụ SDK trực tiếp vào Altium Designer.

  1. Trong Altium Designer, vào Extensions and Updates → Available.

  2. Trong phần Software Extensions, tìm Altium Developer.

  3. Cài đặt tiện ích mở rộng, sau đó khởi động lại Altium Designer khi được nhắc.

Bước 2: Tạo dự án tiện ích mở rộng mới

  1. Trong Altium Designer, vào File → New → Other → Extension.

    • Extension ID: ShowNetsExtension

    • Extension Kind: Altium Designer Server

    • Development Language: C#

    • IDE Version: latest

    • SDK Version: latest

  2. Sau khi tiện ích mở rộng được tạo, Altium Designer sẽ hiển thị thông tin chi tiết của tiện ích. Ghi lại Source Location — mở tệp .csproj từ đường dẫn đó trong IDE của bạn.

Bước 3: Thêm lệnh đầu tiên

Mở Source Code\Commands.cs và thêm các phương thức sau vào lớp Commands:

    /// <summary>
    /// Determines the enabled/visible state for the "Show Nets" command in Altium Designer.
    /// </summary>
    /// <param name="argContext">The current server document view context.</param>
    /// <param name="argParameters">Command parameters (unused).</param>
    /// <param name="argEnabled">Set to true if the command should be enabled.</param>
    /// <param name="argChecked">Set to true if the command should appear checked (unused).</param>
    /// <param name="argVisible">Set to true if the command should be visible (unused).</param>
    /// <param name="argCaption">Command caption (unused).</param>
    /// <param name="argImageFile">Command image file (unused).</param>
    public static void GetState_ShowNets(IServerDocumentView argContext, ref string argParameters, ref bool argEnabled,
        ref bool argChecked, ref bool argVisible, ref string argCaption, ref string argImageFile)
    {
        // Retrieve the currently focused project from Altium Designer's workspace.
        var project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject;

        // If the project needs to be compiled (e.g., netlist out of date), compile it.
        if (project?.DM_NeedsCompile() == true)
            project.DM_Compile();

        // Enable the command only if a valid project is focused and it's not the "Free Documents" project.
        argEnabled = project != null && !IsFreeDocumentsProject(project);
    }

    /// <summary>
    /// Command handler to display all net names in the current schematic document or project.
    /// </summary>
    /// <param name="view">The current server document view.</param>
    /// <param name="parameters">Command parameters (unused).</param>
    public static void Command_ShowNets(IServerDocumentView view, ref string parameters)
    {
        // Get the currently focused project from Altium Designer.
        var project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject;
        if (project == null || IsFreeDocumentsProject(project))
            return;

        string documentName;
        // Get the currently focused document (e.g., schematic sheet).
        var document = DXP.GlobalVars.DXPWorkSpace.DM_FocusedDocument() as IDocument;
        if (document == null)
        {
            // If no document is focused, ensure the project is compiled and use the flattened project document.
            if (project.DM_NeedsCompile()) project.DM_Compile();
            document = project.DM_DocumentFlattened();
            documentName = "Project";
        }
        else
        {
            // Only proceed if the focused document is a schematic (DocKindSch).
            if (document.DM_DocumentKind() != EDPConstant.DocKindSch) return;
            documentName = document.DM_FileName();
        }

        // Enumerate all nets in the document, retrieve their full names, and sort them alphabetically.
        var netNames = Enumerable.Range(0, document.DM_NetCount())
            .Select(document.DM_Nets)
            .Select(net => net.DM_FullNetName())
            .OrderBy(name => name);

        // Display the list of net names in an information dialog within Altium Designer.
        DXP.Utils.ShowInfo(string.Join(Environment.NewLine, netNames), $"Nets [{documentName}]");
    }

    /// <summary>
    /// Checks if the given project is the special "Free Documents" project in Altium Designer.
    /// </summary>
    /// <param name="project">The project to check.</param>
    /// <returns>True if the project is the Free Documents project; otherwise, false.</returns>
    private static bool IsFreeDocumentsProject(IProject project)
    {
        return project == DXP.GlobalVars.DXPWorkSpace.DM_FreeDocumentsProject();
    }

Các kiểu được sử dụng ở đây (IProject, IDocument và DXP.GlobalVars ) được mô tả trong Tài liệu tham khảo Altium Designer SDK.

Mở Source Code\Main.cs và đăng ký lệnh trong lớp PluginServerModule:

protected override void InitializeCommands()
{
    ((CommandLauncher)CommandLauncher).RegisterCommand("ShowNets", Commands.Command_ShowNets, Commands.GetState_ShowNets);
}

Biên dịch dự án để cài đặt tiện ích mở rộng.

Bước 4: Chạy lệnh trong Altium Designer

  1. Khởi động Altium Designer.

  2. Nhấp chuột phải vào thanh công cụ bất kỳ và chọn Customize…

  3. Trong Commands, nhấp vào New… và cấu hình như sau:

    • Process: ShowNetsExtension:ShowNets

    • Caption: ShowNets

  4. Kéo lệnh mới vào một thanh công cụ.

  5. Nhấp vào lệnh – một hộp thoại chứa danh sách các net sẽ xuất hiện.

Các bước tiếp theo

AI-LocalizedBản địa hóa bằng AI
Nếu bạn phát hiện vấn đề, hãy chọn văn bản/hình ảnh và nhấnCtrl + Enterđể gửi phản hồi cho chúng tôi.
Contents
Contents