Guida rapida all'SDK di Altium Designer

L'SDK di Altium Designer è attualmente in beta chiusa ed è disponibile solo per pochi clienti selezionati con accesso anticipato.

L'SDK di Altium Designer consente di creare estensioni personalizzate che si integrano direttamente in Altium Designer, aggiungendo comandi, automatizzando i flussi di lavoro e accedendo ai dati di progettazione tramite un'API .NET gestita.

Questa guida illustra come installare gli strumenti di sviluppo, creare un progetto di estensione, aggiungere un comando ed eseguirlo all'interno di Altium Designer.

Prefer the command line? Il modello di estensione per Altium Designer crea un'estensione C# completa con un comando, senza utilizzare la procedura guidata integrata nell'applicazione né Visual Studio, e 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"

richiede Altium Designer 24 o versioni successive e .NET SDK 8 o versioni successive (.NET SDK 10 per Altium Designer 26.12 e versioni successive). Il codice del comando in Step 3 riportato di seguito funziona allo stesso modo in un progetto basato sul modello.

Prerequisiti

Passaggio 1: installare l'estensione Altium Developer

L'estensione Altium Developer aggiunge modelli di progetto e strumenti SDK direttamente in Altium Designer.

  1. In Altium Designer, vai a Extensions and Updates → Available.

  2. Nella sezione Software Extensions , cerca Altium Developer.

  3. Installa l'estensione, quindi riavvia Altium Designer quando richiesto.

Passaggio 2: creare un nuovo progetto di estensione

  1. In Altium Designer, vai a File → New → Other → Extension.

    • Extension ID: ShowNetsExtension

    • Extension Kind: Altium Designer Server

    • Development Language: C#

    • IDE Version: latest

    • SDK Version: latest

  2. Una volta creata l'estensione, Altium Designer ne visualizza i dettagli. Prendi nota di Source Location — apri il file .csproj da quel percorso nel tuo IDE.

Passaggio 3: aggiungere il primo comando

Apri Source Code\Commands.cs e aggiungi i seguenti metodi alla classe 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();
    }

I tipi utilizzati qui (IProject, IDocument  e DXP.GlobalVars ) sono documentati nella guida di riferimento dell'SDK di Altium Designer.

Apri Source Code\Main.cs e registra il comando nella classe PluginServerModule:

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

Compila il progetto per installare l'estensione.

Passaggio 4: eseguire il comando in Altium Designer

  1. Avvia Altium Designer.

  2. Fai clic con il pulsante destro del mouse su una barra degli strumenti e seleziona Customize…

  3. In Commands, fai clic su New… e configura quanto segue:

    • Process: ShowNetsExtension:ShowNets

    • Caption: ShowNets

  4. Trascina il nuovo comando su una barra degli strumenti.

  5. Fai clic sul comando: dovrebbe apparire una finestra di dialogo con l'elenco delle net.

Passaggi successivi

AI-LocalizedLocalizzato tramite A
Se trovi un problema, seleziona il testo/l’immagine e premi Ctrl + Enter per inviarci il tuo feedback.
Contents
Contents