Schnellstartanleitung für das Altium Designer SDK
Mit dem Altium Designer SDK können Sie benutzerdefinierte Erweiterungen entwickeln, die direkt in Altium Designer integriert werden – um Befehle hinzuzufügen, Arbeitsabläufe zu automatisieren und über eine verwaltete .NET-API auf Designdaten zuzugreifen.
Diese Anleitung führt Sie durch die Installation der Entwicklungswerkzeuge, das Erstellen eines Erweiterungsprojekts, das Hinzufügen eines Befehls und dessen Ausführung in Altium Designer.
Voraussetzungen
-
Registrierung im Altium Developer Center – erforderlich, um Zugriff auf das Altium Designer SDK und seine Erweiterungen zu erhalten
-
Altium Designer installiert und lizenziert
-
Eine .NET-kompatible IDE (Visual Studio oder VS Code mit C#-Unterstützung)
Schritt 1: Altium Developer-Erweiterung installieren
Die Altium Developer-Erweiterung fügt Projektvorlagen und SDK-Werkzeuge direkt in Altium Designer hinzu.
-
Gehen Sie in Altium Designer zu Extensions and Updates → Available.
-
Suchen Sie im Bereich Software Extensions nach Altium Developer.
-
Installieren Sie die Erweiterung und starten Sie Altium Designer neu, wenn Sie dazu aufgefordert werden.
Schritt 2: Neues Erweiterungsprojekt erstellen
-
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 Version:
latest
-
-
Nach dem Erstellen der Erweiterung zeigt Altium Designer deren Details an. Notieren Sie sich Source Location — öffnen Sie die Datei
.csprojunter diesem Pfad in Ihrer IDE.
Schritt 3: Ihren ersten Befehl hinzufügen
Ö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();
}
Die hier verwendeten Typen (IProject, IDocument und DXP.GlobalVars ) sind in der Altium Designer SDK-Referenz dokumentiert.
Ö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);
}
Kompilieren Sie das Projekt, um die Erweiterung zu installieren.
Schritt 4: Ihren Befehl in Altium Designer ausführen
-
Starten Sie Altium Designer.
-
Klicken Sie mit der rechten Maustaste auf eine beliebige Symbolleiste und wählen Sie Customize…
-
Klicken Sie unter Commands auf New… und konfigurieren Sie Folgendes:
-
Process:
ShowNetsExtension:ShowNets -
Caption:
ShowNets
-
-
Ziehen Sie den neuen Befehl auf eine Symbolleiste.
-
Klicken Sie auf den Befehl – ein Dialog mit einer Liste der Netze sollte angezeigt werden.
Nächste Schritte
-
Durchsuchen Sie die Altium Designer SDK-Referenz – die vollständige .NET-API für die Namespaces
SCH,PCB,EDP,DXP,ComponentLibundEmbedded. -
Lesen Sie API-Konventionen, um zu erfahren, wie Einstiegspunkte, GetState/SetState-Methoden und Enumerationen organisiert sind.
-
Beginnen Sie Ihre nächste Erweiterung mit der Vorlage Altium Designer Extension Template, mit Hot Reload bei laufendem Altium Designer.