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
-
Registrierung im Altium Developer Center – erforderlich, um den Zugriff auf das Altium Designer SDK und seine Erweiterungen freizuschalten
-
Altium Designer installiert und lizenziert
-
Eine mit .NET kompatible IDE (Visual Studio oder VS Code mit C#-Unterstützung)
Schritt 1: Installieren Sie die Altium Developer Extension
Die Altium Developer-Erweiterung fügt Projektvorlagen und SDK-Tools direkt in Altium Designer hinzu.
-
Gehen Sie in Altium Designer zu Extensions and Updates → Available.
-
Suchen Sie im Abschnitt Software Extensions nach Altium Developer.
-
Installieren Sie die Erweiterung und starten Sie anschließend Altium Designer neu, wenn Sie dazu aufgefordert werden.
Schritt 2: Erstellen Sie ein neues Erweiterungsprojekt
-
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
-
-
Sobald die Erweiterung erstellt wurde, zeigt Altium Designer deren Details an. Notieren Sie sich den Source Location — öffnen Sie die Datei
.csprojaus 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
-
Starten Sie Altium Designer.
-
Klicken Sie mit der rechten Maustaste auf eine beliebige Symbolleiste und wählen Sie Customize…
-
Unter Commands klicken Sie 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 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.