Краткое руководство по началу работы с SDK Altium Designer
SDK для Altium Designer позволяет создавать пользовательские расширения, которые интегрируются непосредственно в Altium Designer, — добавлять команды, автоматизировать рабочие процессы и получать доступ к данным проекта через управляемый .NET API.
В этом руководстве описаны установка инструментов разработки, создание проекта расширения, добавление команды и ее запуск внутри Altium Designer.
Предварительные требования
-
Регистрация в Altium Developer Center — требуется для получения доступа к SDK Altium Designer и его расширениям
-
Установленный и лицензированный Altium Designer
-
IDE с поддержкой .NET (Visual Studio или VS Code с поддержкой C#)
Шаг 1. Установите расширение Altium Developer
Расширение Altium Developer добавляет шаблоны проектов и инструменты SDK непосредственно в Altium Designer.
-
В Altium Designer перейдите в Extensions and Updates → Available.
-
В разделе Software Extensions найдите Altium Developer.
-
Установите расширение, затем перезапустите Altium Designer, когда появится соответствующий запрос.
Шаг 2. Создайте новый проект расширения
-
В Altium Designer перейдите в File → New → Other → Extension.
-
Extension ID:
ShowNetsExtension -
Extension Kind:
Altium Designer Server -
Development Language:
C# -
IDE Version:
latest -
SDK Version:
latest
-
-
После создания расширения Altium Designer отобразит сведения о нем. Обратите внимание на Source Location — откройте файл
.csprojпо этому пути в своей IDE.
Шаг 3. Добавьте свою первую команду
Откройте Source Code\Commands.cs и добавьте следующие методы в класс 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();
}
Откройте Source Code\Main.cs и зарегистрируйте команду в классе PluginServerModule:
protected override void InitializeCommands()
{
((CommandLauncher)CommandLauncher).RegisterCommand("ShowNets", Commands.Command_ShowNets, Commands.GetState_ShowNets);
}
Соберите проект, чтобы установить расширение.
Шаг 4. Запустите команду в Altium Designer
-
Запустите Altium Designer.
-
Щелкните правой кнопкой мыши по любой панели инструментов и выберите Customize…
-
В разделе Commands нажмите New… и задайте следующие параметры:
-
Process:
ShowNetsExtension:ShowNets -
Caption:
ShowNets
-
-
Перетащите новую команду на панель инструментов.
-
Нажмите команду — должно появиться диалоговое окно со списком цепей.
Следующие шаги
-
Ознакомьтесь с документацией Altium Designer SDK по интерфейсам для схем, трассировки PCB, компонентов и многого другого.
-
Изучите примеры расширений и демонстрационные проекты в GitHub-организации AltiumDeveloper.