Guide de démarrage rapide du SDK d’Altium Designer

Le SDK d’Altium Designer vous permet de créer des extensions personnalisées qui s’intègrent directement dans Altium Designer, en ajoutant des commandes, en automatisant les flux de travail et en accédant aux données de conception via une API .NET managée.

Ce guide vous accompagne dans l’installation des outils de développement, la création d’un projet d’extension, l’ajout d’une commande et son exécution dans Altium Designer.

Prérequis

Étape 1 : Installer l’extension Altium Developer

L’extension Altium Developer ajoute directement dans Altium Designer des modèles de projet et les outils du SDK.

  1. Dans Altium Designer, accédez à Extensions and Updates → Available.

  2. Dans la section Software Extensions , recherchez Altium Developer.

  3. Installez l’extension, puis redémarrez Altium Designer lorsque cela vous est demandé.

Étape 2 : Créer un nouveau projet d’extension

  1. Dans Altium Designer, accédez à File → New → Other → Extension.

    • Extension ID: ShowNetsExtension

    • Extension Kind: Altium Designer Server

    • Development Language: C#

    • IDE Version: latest

    • SDK Versionlatest

  2. Une fois l’extension créée, Altium Designer affiche ses détails. Notez le Source Location — ouvrez le fichier .csproj à cet emplacement dans votre IDE.

Étape 3 : Ajouter votre première commande

Ouvrez Source Code\Commands.cs et ajoutez les méthodes suivantes à la 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();
    }

Ouvrez Source Code\Main.cs et enregistrez la commande dans la classe PluginServerModule :

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

Compilez le projet pour installer l’extension.

Étape 4 : Exécuter votre commande dans Altium Designer

  1. Démarrez Altium Designer.

  2. Cliquez avec le bouton droit sur n’importe quelle barre d’outils et sélectionnez Customize…

  3. Dans Commands, cliquez sur New… et configurez les éléments suivants :

    • Process: ShowNetsExtension:ShowNets

    • Caption: ShowNets

  4. Faites glisser la nouvelle commande sur une barre d’outils.

  5. Cliquez sur la commande – une boîte de dialogue contenant la liste des nets doit apparaître.

Étapes suivantes

  • Consultez la documentation du SDK d’Altium Designer pour découvrir les interfaces couvrant les schémas, le routage PCB, les composants, etc.

  • Explorez les exemples d’extensions et les démonstrations dans l’organisation GitHub AltiumDeveloper.

AI-LocalizedLocalisé par IA
Si vous trouvez un problème, sélectionnez le texte/l’image et appuyez surCtrl + Entréepour nous envoyer vos commentaires.
Contenu