OriginalCircuit.AltiumSharp 1.0.2

dotnet add package OriginalCircuit.AltiumSharp --version 1.0.2
NuGet\Install-Package OriginalCircuit.AltiumSharp -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OriginalCircuit.AltiumSharp" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OriginalCircuit.AltiumSharp --version 1.0.2
#r "nuget: OriginalCircuit.AltiumSharp, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OriginalCircuit.AltiumSharp as a Cake Addin
#addin nuget:?package=OriginalCircuit.AltiumSharp&version=1.0.2

// Install OriginalCircuit.AltiumSharp as a Cake Tool
#tool nuget:?package=OriginalCircuit.AltiumSharp&version=1.0.2

AltiumSharp

AltiumSharp is a .NET library that makes it easy to read and write Altium Designer library files using C# without requiring Altium to be installed on your system. With AltiumSharp, you can programmatically access and modify the schematics, PCBs, components and symbols created in Altium, making it a powerful tool for automating tasks. This library was specifically created to make it easier to automate library management tasks.

Altium Designer is a leading electronic design automation software used for creating printed circuit board (PCB) designs. It stores information in a proprietary file format, which can be difficult to work with using traditional methods. AltiumSharp simplifies this process, allowing you to easily manipulate these files without the need for Altium Designer to be installed on your system.

In addition to supporting PcbLib and SchLib files, AltiumSharp also supports SchDoc and PcbDoc files. With AltiumSharp, you can easily read, write, and render Altium files in your .NET projects. Whether you're looking to automate library management tasks or simply need a more convenient way to work with Altium files, AltiumSharp has you covered.

Many thanks to Tiago Trinidad (@Kronal on Discord) for his huge efforts on this library.

Usage

Before using AltiumSharp, you will need to add the following NuGet references to your project:

Once you have these references added, you can use the AltiumSharp library to read and write Altium library files and render components as images. Check out the examples in the readme for more information on how to use AltiumSharp in your projects.

Opening a PcbLib File

Here's an example of how you can use AltiumSharp to open a PcbLib file and iterate through its components:

	// Open a PcbLib file.
	using (var reader = new PcbLibReader(fileName))
	{
	    // Read the file.
	    reader.Read();

	    // Iterate through each component in the library.
	    foreach (var component in reader.Components)
	    {
	        // Print information about the component.
	        Console.WriteLine($"Name: {component.Name}");
	        Console.WriteLine($"Number of Pads: {component.Pads}");
	        Console.WriteLine($"Number of Primitives: {component.Primitives.Count()}");
	    }

	    // Retrieve settings from the header.
	    _displayUnit = reader.Header.DisplayUnit;
	    _snapGridSize = reader.Header.SnapGridSize;
	    _components = reader.Components.Cast<IComponent>().ToList();
	}

Reading and Writing a SchLib File

AltiumSharp also provides support for reading and writing SchLib files, as shown in this example:

	// Set the path to the directory containing the SchLib files.
	string path = @"C:\altium-library\symbols\ARM Cortex";

	// Array of filenames to process.
	string[] files = {
	    "SCH - ARM CORTEX - NXP LPC176X LQFP100.SCHLIB",
	    "SCH - ARM CORTEX - NXP LPC176X TFBGA100.SCHLIB",
	    "SCH - ARM CORTEX - NXP LPC176X WLCSP100.SCHLIB"
	};

	// Loop through each file.
	foreach (var file in files)
	{
	    // Read the SchLib file.
	    using (var reader = new AltiumSharp.SchLibReader())
	    {
	        var schLib = reader.Read(Path.Combine(path, file));

	        // Iterate through each component in the library.
	        foreach (var component in schLib.Items)
	        {
	            // Print the component name and comment.
	            Console.WriteLine($"Name: {((IComponent)component).Name}");
	            Console.WriteLine($"Comment: {component.Comment}");
	        }

	        // Write the SchLib file.
	        using (var writer = new SchLibWriter())
	        {
	            writer.Write(schLib, Path.Combine(path, file), true);
	        }
	    }
	}

Rendering a Component

AltiumSharp includes a renderer for PcbLib files that allows you to display components in your own application. Here's an example of how you can use the renderer to render a component:

	// Create a PcbLibRenderer.
	var renderer = new PcbLibRenderer();

	// Check if the renderer was created successfully.
	if (renderer != null)
	{
	    // Set the component to be rendered.
	    renderer.Component = _activeComponent;

	    // Create a Bitmap to hold the rendered image.
	    var image = new Bitmap(pictureBox.Width, pictureBox.Height);

	    // Use a Graphics object to draw on the Bitmap.
	    using (var g = Graphics.FromImage(image))
	    {
	        // Render the component to the Bitmap.
	        renderer.Render(g, pictureBox.Width, pictureBox.Height, _autoZoom, fastRendering);
	    }

	    // Update the picture box with the rendered image.
	    pictureBox.Image = image;

	    // Reset the auto zoom flag.
	    _autoZoom = false;
	}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 212 7/21/2023
1.0.1 125 7/21/2023
1.0.0 252 1/1/2023