EasyEDA API Plug

Before reading this capture, please check EasyEDA Document Format first.

Why Need API

After route the PCB, you found out that you need to enlarge all tracks size a bit little, How?
After route the PCB, you found out that all Vias’ hole size is too small, How to fix this?
How to create a board outline using code?
EasyEDA API will let you control your designs in an easy way.

How to use API

How to find the plug entrance

You can click Config Icon > Extensions Setting on the top toolbar image as below.

Extensions Setting

You can enable or disable the default extensions, after enable, please reload the EasyEDA editor. We will give you a file about how to create an extensions soon.

If you enable the Theme Colors Extension, you will find a button on the tool bar like bellow image:

If you click the Black On White, you will find your schematic changes like bellow image, this is useful when you would like to print your design on a paper.

You can check our github codes of this API via https://github.com/dillonHe/EasyEDA-Documents/tree/master/API/example/theme, check the manifest.json and main.js out, you will find out how to create an extension.

How to install an extension

  1. Click the Load Extension button
  2. Click the select file button
  3. Select All the files.
  4. Type a name
  5. Click the load button.
  6. Close EasyEDA editor and open it again.

Scripts

If you just need some simple functions, you don’t need to create an extension. You just need to create a single Javascipt file and keep it in this list.

  1. You can select the Hello World, then click the Run button, the response as below image.
  2. You can select some items, then try Move Selected Objects.
  3. You can install your own scripts, then they will show on User Scripts.

Run Script code

In some case, you just need to run the function one time, such as create a user define board outline in codes, changing the Track width, change the hole size etc. You can use this way.

example 1 Art
You can open an empty schematic and copy this example javascript codes to the text box to run a test. After clicking the Run button, you will see bellow art image.

testInsertShape();
function testInsertShape(){
api('insertShape', [
{
shapeTypeName: "path",
fillColor: "none",
pathString: "M520 500 C480 460 550 430 480 410",
strokeColor: "#000000",
strokeStyle: 0,
strokeWidth: "1"
}
]);
api('insertShape', [
{
shapeTypeName: "path",
fillColor: "none",
pathString: shapeLotusFlower(500,550,3,80,40),
strokeColor: "#000000",
strokeStyle: 0,
strokeWidth: "1"
},
{
shapeTypeName: "path",
fillColor: "none",
pathString: shapeLotusFlower(700,500,6,70,30),
strokeColor: "#ff00ff",
strokeStyle: 0,
strokeWidth: "1"
},
{
shapeTypeName: "path",
fillColor: "none",
pathString: shapeFlower2(660,670,4, 14,-Math.PI/4, 63.246,-0.32175, 84.85,Math.PI/4),
strokeColor: "#cccc00",
strokeStyle: 0,
strokeWidth: "2"
}
]);
}
/** Lotus shape path */
function shapeLotusFlower(cx,cy,n,r,r2){
var pathD = '', angle, angle2, x, y, x2, y2;
function p(x,y){
return (x+cx)+' '+(y+cy);
}
for(var i=0; i<n; i++){
angle = i * Math.PI / n;
angle2 = (i / n + 0.5) * Math.PI;
x = r * Math.cos(angle);
y = r * Math.sin(angle);
x2 = r2 * Math.cos(angle2);
y2 = r2 * Math.sin(angle2);
pathD += 'M'+p(x,y)
+'C'+p(x2,y2)+' '+p(-x2,-y2)+' '+p(-x,-y)
+'C'+p(x2,y2)+' '+p(-x2,-y2)+' '+p(x,y);
}
return pathD;
}
/** Petal shape path */
function shapeFlower2(cx,cy,n,r1,a1,r2,a2,r3,a3){
var pathD = '', angle, angle2, angle3, angle4, x, y, x2, y2;
function p(r,thi){
return (r * Math.cos(thi) + cx)+' '+(r * Math.sin(thi) + cy);
}
function polar(r,thi){
return {r:r,thi:thi};
}
for(var i=0; i<n; i++){
angle = i>0 ? angle4 : a1 + i * 2 * Math.PI / n;
angle2 = a2 + i * 2 * Math.PI / n;
angle3 = a3 + i * 2 * Math.PI / n;
angle4 = a1 + (i+1) * 2 * Math.PI / n;
pathD += (i>0 ? '' : 'M'+p(r1,angle))
+'C'+p(r2,angle2)+' '+p(r3,angle3)+' '+p(r1,angle4);
}
return pathD;
}

example 2 Change track width and via hole size
You can open a PCB and copy this example javascript codes to the text box to run a test. After that, All tracks will be 10mil.

//you can get the EasyEDA json objects like https://gist.github.com/071d4680dcdbf6bf9dd6.git
//try to pen a pcb, then run bellow codes.

var json = api('getSource', {type: "json"}),
id;

for(id in json.TRACK){
if(json.TRACK.hasOwnProperty(id)){
json.TRACK[id].strokeWidth = api('edit.unitConvert', {type:'mil2pixel',value:10}); // 10mil
}
}

for(id in json.VIA){
if(json.VIA.hasOwnProperty(id)){
json.VIA[id].holeR = api('edit.unitConvert', {type:'mil2pixel',value:10}); // 10mil
}
}
api('applySource', {source: json, createNew: true});

goToTop