In this example a component library containing two devices is created. The library also includes the corresponding graphical symbols and footprints.
Example
Copy code | |
---|---|
<<filedescription>>
In this example a component library containing two devices is created.
The library also includes the corresponding graphical symbols and footprints.
The library is saved in the file "Example Lib.clxjob".
<<filedescription>>
function DrawAndShape(layer, Y, bDot)
{
// Draw And shape
var andShape = layer.DrawShape();
var figure = andShape.GetFigure();
figure.BeginShape();
figure.AddPoint(new DlxPoint(95,Y+53.75));
figure.AddPoint(new DlxPoint(101.25,Y+53.75));
figure.AddPoint(new DlxPoint(101.25,Y+46.25), -180);
figure.AddPoint(new DlxPoint(95,Y+46.25));
figure.EndShape(true);
// Add Pins
var pinstyle = new DlxPinStyle(DlxApp.PINSTYLE_LINE);
var pinFlags = DlxApp.PINFLAGS_SHOWLINE|DlxApp.PINFLAGS_SHOWNUM|DlxApp.PINFLAGS_VNUM|DlxApp.PINFLAGS_VNAME|DlxApp.PINFLAGS_UPDATETEXT;
layer.DrawPin(new DlxPoint(95, Y+52.5), 5, 180, "1", "A", "", DlxApp.PINTYPE_INPUT, pinstyle, pinFlags);
layer.DrawPin(new DlxPoint(95, Y+47.5), 5, 180, "2", "B", "", DlxApp.PINTYPE_INPUT, pinstyle, pinFlags);
layer.DrawPin(new DlxPoint(105, Y+50), 5, 0, "3", "Y", "", DlxApp.PINTYPE_OUTPUT, pinstyle, pinFlags, 0, 0, bDot ? DlxApp.IEEESYMBOLOUTSIDEEDGE_DOT : 0);
pinFlags = DlxApp.PINFLAGS_SHOWLINE|DlxApp.PINFLAGS_SHOWNUM|DlxApp.PINFLAGS_HIDDEN|DlxApp.PINFLAGS_UPDATETEXT;
layer.DrawPin(new DlxPoint(100, Y+46.25), 5, 270, "4", "GND", "", DlxApp.PINTYPE_POWER, pinstyle, pinFlags);
layer.DrawPin(new DlxPoint(100, Y+53.75), 5, 90, "5", "VCC", "", DlxApp.PINTYPE_POWER, pinstyle, pinFlags);
// Add Reference and Value
layer.DrawValue(new DlxPoint(95,Y+46.25), "NAND2", 0, DlxApp.TEXTALIGN_TOPLEFT);
layer.DrawReference(new DlxPoint(95,Y+53.75), "U?", 0, DlxApp.TEXTALIGN_BOTTOMLEFT);
}
function BuildSymbols(prj)
{
var symDoc = prj.NewDocument("Examples Symbols", DlxApp.DOCTYPE_SCHEMATIC);
if (symDoc.IsValid() && symDoc.Activate())
{
// Initialize the document
symDoc.SetPageFormat("A4", true);
var page = symDoc.GetPage(1);
page.SetName("Symbols");
page.LoadLayerStack("symbols library layer stack.clxlys");
page.SelectView("Default View");
var layerFrame = page.GetLayerFromType(DlxApp.LAYERTYPE_LIBRARYFRAMES);
var layerSymbol = page.GetLayerFromType(DlxApp.LAYERTYPE_DRAWING);
if (!layerFrame.IsValid() || !layerSymbol.IsValid())
return;
// Turn off undo registrations.
page.EnableUndo(false);
// Draw the frame
layerFrame.DrawFrame(new DlxRect(10,200,200,290), 1, "NAND2", "2 Input NAND gate.");
layerFrame.DrawFrame(new DlxRect(10,100,200,190), 2, "AND2", "2 Input AND gate.");
// Set pen style to Symbol Body Outline
symDoc.SetStyle(new DlxPenStyle("#0000000000000000812FZZZZZZ"));
// Set brush style to Symbol Body
symDoc.SetStyle(new DlxBrushStyle("#0000000000000000G10ZZZZZZZ"));
// Set text style to Attribute Text
symDoc.SetStyle(new DlxTextStyle("#0000000000000001810KZZZZZZ"));
DrawAndShape(layerSymbol, 200, true);
DrawAndShape(layerSymbol, 100, false);
// Turn on undo registrations.
page.EnableUndo(true);
}
}
function BuildFootprints(prj)
{
var pcbDoc = prj.NewDocument("Examples Footprints", DlxApp.DOCTYPE_PCB);
if (pcbDoc.IsValid() && pcbDoc.Activate())
{
// Initialize the document
pcbDoc.SetPageFormat("A4", true);
var page = pcbDoc.GetPage(1);
page.SetName("DIP14");
if (!page.LoadLayerStack("footprints library layer stack.clxlys"))
return;
// get layers
var layerSilk = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPSILK);
var layerCourtyard = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPCOURTYARD);
var layerAssembly = page.GetLayerFromType(DlxApp.LAYERTYPE_TOPASSEMBLY);
// Turn off undo registrations.
page.EnableUndo(false);
// Draw the frame
var hotspotPoint = new DlxPoint(105, 150);
page.DrawFrame(new DlxRect(10,10,200,290), 1, "DIP14", "Dual-in-line 14 leads.");
page.DrawHotspot(hotspotPoint);
// Init pad style
var padstyle = new DlxPadStyle();
padstyle.SetShape(DlxApp.LAYERTYPE_ALLPCBLAYERS, DlxApp.PADSHAPE_ROUNDED, 1.6, 2.4, 1);
padstyle.SetHole(0.8);
// Init style for pad n.1
var padstyle1 = new DlxPadStyle();
padstyle1.SetShape(DlxApp.LAYERTYPE_ALLPCBLAYERS, DlxApp.PADSHAPE_SQUARE, 1.6, 2.4);
padstyle1.SetHole(0.8);
var rows = 7;
var width = 7.62;
var pitch = 2.54;
var pinHWidth = 0.5;
var hwidth = width / 2;
var notchwidth = 1.5;
// draw pads
var y = hotspotPoint.y + (rows - 1) * pitch / 2;
for (var i = 1; i <= rows; i++)
{
page.DrawTHPad(new DlxPoint(hotspotPoint.x - hwidth, y), i == 1 ? padstyle1 : padstyle, i.toString());
page.DrawTHPad(new DlxPoint(hotspotPoint.x + hwidth, y), padstyle, (15 - i).toString());
y -= pitch;
}
// Set pen style by layer
pcbDoc.SetStyle(new DlxPenStyle(DlxApp.STYLE_BYLAYER));
// Set brush style to Null
pcbDoc.SetStyle(new DlxBrushStyle(DlxApp.STYLE_NULL));
// Set ref and value style to PCB legend level B
pcbDoc.SetValueStyle(new DlxTextStyle("#0000000000000001810FZZZZZZ"));
pcbDoc.SetReferenceStyle(new DlxTextStyle("#0000000000000001810FZZZZZZ"));
// draw silk
var body = new DlxRect();
body.SetCentered(hotspotPoint, 4.5, 18);
layerSilk.DrawRectangle(body, 0, 0, 0, 0, -40);
layerSilk.DrawReference(body.TopLeft(), "U?", 0, DlxApp.TEXTALIGN_BOTTOMLEFT);
layerSilk.DrawValue(body.BottomLeft(), "Value", 0, DlxApp.TEXTALIGN_TOPLEFT);
// draw courtyard
body.SetCentered(hotspotPoint, 10.55, 18.35);
layerCourtyard.DrawCourtyard(body);
// draw assembly
body.SetCentered(hotspotPoint, 6.35, 18);
var shape = layerAssembly.DrawShape();
var fig = shape.GetFigure();
fig.BeginShape();
fig.AddPoint(body.TopLeft());
fig.AddPoint(body.BottomLeft());
fig.AddPoint(body.BottomRight());
fig.AddPoint(body.TopRight());
fig.AddPoint(new DlxPoint(body.right - (body.Width() - notchwidth) / 2, body.top));
fig.AddPoint(new DlxPoint(body.left + (body.Width() - notchwidth) / 2, body.top), -180);
fig.EndShape(true);
y = hotspotPoint.y + (rows - 1) * pitch / 2;
for (i = 1; i <= rows; i++)
{
layerAssembly.DrawLine(new DlxPoint(hotspotPoint.x - hwidth, y + pinHWidth), new DlxPoint(body.left, y + pinHWidth));
layerAssembly.DrawLine(new DlxPoint(hotspotPoint.x - hwidth, y - pinHWidth), new DlxPoint(body.left, y - pinHWidth));
layerAssembly.DrawLine(new DlxPoint(hotspotPoint.x - hwidth, y - pinHWidth), new DlxPoint(hotspotPoint.x - width / 2, y + pinHWidth));
layerAssembly.DrawLine(new DlxPoint(hotspotPoint.x + hwidth, y + pinHWidth), new DlxPoint(body.right, y + pinHWidth));
layerAssembly.DrawLine(new DlxPoint(hotspotPoint.x + hwidth, y - pinHWidth), new DlxPoint(body.right, y - pinHWidth));
layerAssembly.DrawLine(new DlxPoint(hotspotPoint.x + hwidth, y - pinHWidth), new DlxPoint(hotspotPoint.x + width / 2, y + pinHWidth));
y -= pitch;
}
// Turn on undo registrations.
page.EnableUndo(true);
}
}
function BuildDevice00(folder)
{
var device = folder.AddDevice("SN74HC00N");
device.SetDeviceName("SN74HC00N");
device.SetReferencePrefix("U");
device.SetDeviceClass("Gates", "NAND Gate");
device.SetManufacturer("Texas Instruments");
device.SetDescription("Quad 2-Input Positive-NAND Gates");
device.SetDatasheetLink("https://www.ti.com");
device.BeginSymbolDefinition("NANDGATE");
device.AddSymbolSection("NAND2");
device.AddSymbolSectionPin("1", "1,4,9,12", "1A,2A,3A,4A", DlxApp.PINTYPE_INPUT);
device.AddSymbolSectionPin("2", "2,5,10,13", "1B,2B,3B,4B", DlxApp.PINTYPE_INPUT);
device.AddSymbolSectionPin("3", "3,6,8,11", "1Y,2Y,3Y,4Y", DlxApp.PINTYPE_OUTPUT);
device.AddSymbolSectionPin("4", "7", "GND", DlxApp.PINTYPE_POWER);
device.AddSymbolSectionPin("5", "14", "VCC", DlxApp.PINTYPE_POWER);
device.EndSymbolDefinition();
device.AddFootprint("DIP14");
}
function BuildDevice08(folder)
{
var device = folder.AddDevice("SN74HC08N");
device.SetDeviceName("SN74HC08N");
device.SetReferencePrefix("U");
device.SetDeviceClass("Gates", "AND Gate");
device.SetManufacturer("Texas Instruments");
device.SetDescription("Quadruple 2-input positive-AND gates");
device.SetDatasheetLink("https://www.ti.com");
device.BeginSymbolDefinition("ANDGATE");
device.AddSymbolSection("AND2");
device.AddSymbolSectionPin("1", "1,4,9,12", "1A,2A,3A,4A", DlxApp.PINTYPE_INPUT);
device.AddSymbolSectionPin("2", "2,5,10,13", "1B,2B,3B,4B", DlxApp.PINTYPE_INPUT);
device.AddSymbolSectionPin("3", "3,6,8,11", "1Y,2Y,3Y,4Y", DlxApp.PINTYPE_OUTPUT);
device.AddSymbolSectionPin("4", "7", "GND", DlxApp.PINTYPE_POWER);
device.AddSymbolSectionPin("5", "14", "VCC", DlxApp.PINTYPE_POWER);
device.EndSymbolDefinition();
device.AddFootprint("DIP14");
}
function BuildDevices(prj)
{
var libDoc = prj.NewDocument("Examples Lib", DlxApp.DOCTYPE_LIBRARY);
if (libDoc.IsValid() && libDoc.Activate())
{
var folderGates = libDoc.AddFolder("Gates");
BuildDevice00(folderGates);
BuildDevice08(folderGates);
}
}
// Create the job
DlxApp.NewJob("Example Lib");
var libPrj = DlxApp.GetJob().NewProject("Example Lib");
BuildSymbols(libPrj);
BuildFootprints(libPrj);
BuildDevices(libPrj);
// Save job in library folder
var jobFileName = DlxApp.GetFolder(DlxApp.FOLDERID_USERLIBRARY) + "Example Lib.clxjob";
DlxApp.GetJob().SaveAs(jobFileName);
|