Altium Designer SDK-Schnellstartanleitung

Mit dem Altium Designer SDK können Sie benutzerdefinierte Erweiterungen erstellen, die sich direkt in Altium Designer integrieren – indem sie Befehle hinzufügen, Workflows automatisieren und über eine verwaltete .NET-API auf Designdaten zugreifen.

Diese Anleitung führt Sie durch die Installation der Entwicklungstools, das Erstellen eines Erweiterungsprojekts, das Hinzufügen eines Befehls und dessen Ausführung innerhalb von Altium Designer.

Voraussetzungen

Schritt 1: Installieren Sie die Altium Developer Extension

Die Altium Developer-Erweiterung fügt Projektvorlagen und SDK-Tools direkt in Altium Designer hinzu.

  1. Gehen Sie in Altium Designer zu Extensions and Updates → Available.

  2. Suchen Sie im Abschnitt Software Extensions nach Altium Developer.

  3. Installieren Sie die Erweiterung und starten Sie anschließend Altium Designer neu, wenn Sie dazu aufgefordert werden.

Schritt 2: Erstellen Sie ein neues Erweiterungsprojekt

  1. Gehen Sie in Altium Designer zu File → New → Other → Extension.

    • Extension ID: ShowNetsExtension

    • Extension Kind: Altium Designer Server

    • Development Language: C#

    • IDE Version: latest

    • SDK Versionlatest

  2. Sobald die Erweiterung erstellt wurde, zeigt Altium Designer deren Details an. Notieren Sie sich den Source Location — öffnen Sie die Datei .csproj aus diesem Pfad in Ihrer IDE.

Schritt 3: Fügen Sie Ihren ersten Befehl hinzu

Öffnen Sie Source Code\Commands.cs und fügen Sie der Klasse Commands die folgenden Methoden hinzu:

    /// <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();
    }

Öffnen Sie Source Code\Main.cs und registrieren Sie den Befehl in der Klasse PluginServerModule:

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

Erstellen Sie das Projekt, um die Erweiterung zu installieren.

Schritt 4: Führen Sie Ihren Befehl in Altium Designer aus

  1. Starten Sie Altium Designer.

  2. Klicken Sie mit der rechten Maustaste auf eine beliebige Symbolleiste und wählen Sie Customize…

  3. Unter Commands klicken Sie auf New… und konfigurieren Sie Folgendes:

    • Process: ShowNetsExtension:ShowNets

    • Caption: ShowNets

  4. Ziehen Sie den neuen Befehl auf eine Symbolleiste.

  5. Klicken Sie auf den Befehl – ein Dialogfeld mit einer Liste der Netze sollte erscheinen.

Nächste Schritte

  • Durchsuchen Sie die Dokumentation zum Altium Designer SDK nach Schnittstellen für Schaltpläne, PCB-Layout, Komponenten und mehr.

  • Sehen Sie sich Beispielerweiterungen und Demos in der GitHub-Organisation AltiumDeveloper an.

AI-LocalizedAI-localized
Wenn Sie ein Problem feststellen, wählen Sie den Text/das Bild aus und drücken SieStrg + Eingabe, um uns Ihr Feedback zu senden.
Inhalt