Skrócona instrukcja obsługi SDK Altium Designer
Altium Designer SDK umożliwia tworzenie własnych rozszerzeń zintegrowanych bezpośrednio z Altium Designer — dodawanie poleceń, automatyzowanie procesów i uzyskiwanie dostępu do danych projektowych za pośrednictwem zarządzanego interfejsu API platformy .NET.
Ten przewodnik przeprowadzi Cię przez instalację narzędzi programistycznych, tworzenie projektu rozszerzenia, dodawanie polecenia i uruchamianie go w Altium Designer.
Wymagania wstępne
-
Rejestracja w Altium Developer Center — wymagana do uzyskania dostępu do Altium Designer SDK i jego rozszerzeń
-
Altium Designer — zainstalowany i z aktywną licencją
-
Środowisko IDE zgodne z .NET (Visual Studio lub VS Code z obsługą języka C#)
Krok 1: Zainstaluj rozszerzenie Altium Developer
Rozszerzenie Altium Developer dodaje szablony projektów i narzędzia SDK bezpośrednio do Altium Designer.
-
W Altium Designer przejdź do Extensions and Updates → Available.
-
W sekcji Software Extensions wyszukaj Altium Developer.
-
Zainstaluj rozszerzenie, a następnie uruchom ponownie Altium Designer, gdy pojawi się odpowiedni monit.
Krok 2: Utwórz nowy projekt rozszerzenia
-
W Altium Designer przejdź do File → New → Other → Extension.
-
Extension ID:
ShowNetsExtension -
Extension Kind:
Altium Designer Server -
Development Language:
C# -
IDE Version:
latest -
SDK Version:
latest
-
-
Po utworzeniu rozszerzenia Altium Designer wyświetli jego szczegóły. Zwróć uwagę na Source Location — otwórz w swoim środowisku IDE plik
.csprojznajdujący się pod tą ścieżką.
Krok 3: Dodaj pierwsze polecenie
Otwórz Source Code\Commands.cs i dodaj następujące metody do klasy 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();
}
Użyte tutaj typy (IProject, IDocument i DXP.GlobalVars ) są opisane w dokumentacji referencyjnej Altium Designer SDK.
Otwórz Source Code\Main.cs i zarejestruj polecenie w klasie PluginServerModule:
protected override void InitializeCommands()
{
((CommandLauncher)CommandLauncher).RegisterCommand("ShowNets", Commands.Command_ShowNets, Commands.GetState_ShowNets);
}
Zbuduj projekt, aby zainstalować rozszerzenie.
Krok 4: Uruchom polecenie w Altium Designer
-
Uruchom Altium Designer.
-
Kliknij prawym przyciskiem myszy dowolny pasek narzędzi i wybierz Customize…
-
W sekcji Commands kliknij New… i skonfiguruj następujące ustawienia:
-
Process:
ShowNetsExtension:ShowNets -
Caption:
ShowNets
-
-
Przeciągnij nowe polecenie na pasek narzędzi.
-
Kliknij polecenie — powinno pojawić się okno dialogowe z listą sieci.
Kolejne kroki
-
Przejrzyj dokumentację referencyjną Altium Designer SDK — pełny opis interfejsu API platformy .NET dla przestrzeni nazw
SCH,PCB,EDP,DXP,ComponentLibiEmbedded. -
Przeczytaj Konwencje API, aby dowiedzieć się, jak zorganizowane są punkty wejścia, metody GetState/SetState i typy wyliczeniowe.
-
Zacznij tworzyć kolejne rozszerzenie na podstawie szablonu Altium Designer Extension Template, z możliwością przeładowywania zmian na bieżąco podczas działania Altium Designer.