Using the Scripting Interface with C#: Examples
Examples are provided below of using the Scripting Interface with C# in eCADSTAR Library Editor, eCADSTAR Schematic Editor and eCADSTAR PCB Editor. An example is also provided on how to convert properties to the dictionary. To download scripting examples, click: Scripting Examples. For a specified design, these provide a list of components and their associated parts. Browse to the C# folder in the downloaded data.
To Display All Part Properties in a Library
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var app = new eCSLECOM.LEApplication();
app.OpenDesign(args[0]);
foreach(eCSLECOM.LEPart part in app.Library.Parts)
{
foreach (eCSLECOM.IProperty property in part.Properties)
{
Console.WriteLine(property.Name + " : " + property.Value);
}
}
app.Quit();
}
}
}
To Display All Sheet Properties in a Schematic Design
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var app = new eCSSCHCOM.SchApplication();
app.OpenDesign(args[0]);
foreach(eCSSCHCOM.ISchSheet sheet in app.Design.Sheets)
{
Console.WriteLine(property.Name + " : " + property.Value);
sheet.Open();
foreach (eCSSCHCOM.IProperty property in sheet.Properties)
{
Console.WriteLine(property.Name + " : " + property.Value);
}
sheet.Close();
}
app.Quit();
}
}
}
To Display All Component Properties in a PCB Design
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var app = new eCSPCBCOM.PCBApplication();
app.OpenDesign(args[0]);
foreach(eCSPCBCOM.PCBComponent component in app.CurrentDesign.Components)
{
foreach (eCSPCBCOM.IProperty property in component.Properties)
{
Console.WriteLine(property.Name + " : " + property.Value);
}
}
app.Quit();
}
}
}
Converting Properties to a Dictionary
var properties = component.Properties.Cast<eCSSCHCOM.IProperty>().ToDictionary(x => x.Name, x => x.Value);
Console.WriteLine(properties["Part Name"]);