Skip to content

Instantly share code, notes, and snippets.

@RigoLigoRLC
Last active July 9, 2020 04:52
Show Gist options
  • Save RigoLigoRLC/1de67a4a6d15aefdddf522d7d4d0f8fb to your computer and use it in GitHub Desktop.
Save RigoLigoRLC/1de67a4a6d15aefdddf522d7d4d0f8fb to your computer and use it in GitHub Desktop.
EasyEDA 6.4.0 scripting log
//Test code with footprint, cause the coordinates of {4000,3000} is used
//to give a proper position on footprint editor.
//Create text.
api('createShape', {"shapeType": "TEXT",jsonCache:{text:"HELLO", height:50, layerid:1, "line-width":12, x: 4200, y:3000}});
//Create pad. Very practical. tested on footprint.
api('createShape', {"shapeType": "PAD", jsonCache:{
number:1,
shape:"ELLIPSE",
layerid:11,
net:"",
width:20,
height:20,
holeCenter: {x:4000, y:3000},
holeR:5,
x: 4000,
y:3000,
gId:5555
}})
{
"head": {
"docType": "4",
"editorVersion": "6.4.0",
"newgId": true,
"c_para": {
"package": "",
"pre": "U?",
"Contributor": "RigoLigo"
},
"hasIdFlag": true,
"x": 4000,
"y": 3000
},
"canvas": "CA~1000~1000~#000000~yes~#FFFFFF~10~1000~1000~line~2~mil~1~45~~0.5~4000~3000~0~none",
"shape": [
"TEXT~L~4130~2964~0.8~0~0~12~~8~eRPADGen\nNAMING RULE\nLAYER\nPAD SHAPE\nPAD SIZE\nDRILL SHAPE\nDRILL SIZE\nROTATION\nPLATED\nMASK EXPAND\nUNIT~~~gge1~~0~pinpart",
"TEXT~L~4232~2976~0.8~0~0~12~~8~P,A-B,0-15~~~gge10~~0~pinpart",
"TEXT~L~4232~2988~0.8~0~0~12~~8~THROUGH~~~gge11~~0~pinpart",
"TEXT~L~4232~3000~0.8~0~0~12~~8~CIRCLE~~~gge12~~0~pinpart",
"TEXT~L~4232~3012~0.8~0~0~12~~8~15*10~~~gge13~~0~pinpart",
"TEXT~L~4232~3024~0.8~0~0~12~~8~SLOT~~~gge14~~0~pinpart",
"TEXT~L~4232~3036~0.8~0~0~12~~8~10*5~~~gge15~~0~pinpart",
"TEXT~L~4232~3048~0.8~0~0~12~~8~0~~~gge16~~0~pinpart",
"TEXT~L~4232~3060~0.8~0~0~12~~8~YES~~~gge17~~0~pinpart",
"TEXT~L~4232~3072~0.8~0~0~12~~8~2~~~gge18~~0~pinpart",
"TEXT~L~4232~3084~0.8~0~0~12~~8~MIL~~~gge19~~0~pinpart"
],
"layers": [
"1~TopLayer~#FF0000~true~false~true~",
"2~BottomLayer~#0000FF~true~false~true~",
"3~TopSilkLayer~#FFCC00~true~false~true~",
"4~BottomSilkLayer~#66CC33~true~false~true~",
"5~TopPasteMaskLayer~#808080~true~false~true~",
"6~BottomPasteMaskLayer~#800000~true~false~true~",
"7~TopSolderMaskLayer~#800080~true~false~true~0.3",
"8~BottomSolderMaskLayer~#AA00FF~true~false~true~0.3",
"9~Ratlines~#6464FF~false~false~true~",
"10~BoardOutLine~#FF00FF~true~false~true~",
"11~Multi-Layer~#C0C0C0~true~false~true~",
"12~Document~#FFFFFF~true~true~true~",
"13~TopAssembly~#33CC99~false~false~false~",
"14~BottomAssembly~#5555FF~false~false~false~",
"15~Mechanical~#F022F0~false~false~false~",
"19~3DModel~#66CCFF~false~false~false~",
"21~Inner1~#999966~false~false~false~~",
"22~Inner2~#008000~false~false~false~~",
"23~Inner3~#00FF00~false~false~false~~",
"24~Inner4~#BC8E00~false~false~false~~",
"25~Inner5~#70DBFA~false~false~false~~",
"26~Inner6~#00CC66~false~false~false~~",
"27~Inner7~#9966FF~false~false~false~~",
"28~Inner8~#800080~false~false~false~~",
"29~Inner9~#008080~false~false~false~~",
"30~Inner10~#15935F~false~false~false~~",
"31~Inner11~#000080~false~false~false~~",
"32~Inner12~#00B400~false~false~false~~",
"33~Inner13~#2E4756~false~false~false~~",
"34~Inner14~#99842F~false~false~false~~",
"35~Inner15~#FFFFAA~false~false~false~~",
"36~Inner16~#99842F~false~false~false~~",
"37~Inner17~#2E4756~false~false~false~~",
"38~Inner18~#3535FF~false~false~false~~",
"39~Inner19~#8000BC~false~false~false~~",
"40~Inner20~#43AE5F~false~false~false~~",
"41~Inner21~#C3ECCE~false~false~false~~",
"42~Inner22~#728978~false~false~false~~",
"43~Inner23~#39503F~false~false~false~~",
"44~Inner24~#0C715D~false~false~false~~",
"45~Inner25~#5A8A80~false~false~false~~",
"46~Inner26~#2B937E~false~false~false~~",
"47~Inner27~#23999D~false~false~false~~",
"48~Inner28~#45B4E3~false~false~false~~",
"49~Inner29~#215DA1~false~false~false~~",
"50~Inner30~#4564D7~false~false~false~~",
"51~Inner31~#6969E9~false~false~false~~",
"52~Inner32~#9069E9~false~false~false~~",
"99~ComponentShapeLayer~#00CCCC~false~false~false~",
"100~LeadShapeLayer~#CC9999~false~false~false~",
"Hole~Hole~#222222~~false~true~",
"DRCError~DRCError~#FAD609~~false~true~"
],
"objects": [
"All~true~false",
"Component~true~true",
"Prefix~true~true",
"Name~true~false",
"Track~true~true",
"Pad~true~true",
"Via~true~true",
"Hole~true~true",
"Copper_Area~true~true",
"Circle~true~true",
"Arc~true~true",
"Solid_Region~true~true",
"Text~true~true",
"Image~true~true",
"Rect~true~true",
"Dimension~true~true",
"Protractor~true~true"
],
"BBox": {
"x": 4130,
"y": 2955.9,
"width": 174.6,
"height": 55.6
},
"netColors": {}
}
//eRGENPAD testing
// This script is used with its associated EasyEDA document for batch pad generation.
// Add the script to EasyEDA editor to run it properly.
var gidObj = { name: 'gge10', layer:'gge11', padshape: 'gge12', padsize: 'gge13', drillshape: 'gge14', drillsize: 'gge15', rotation: 'gge16', plated: 'gge17', maskexpand: 'gge18', unit: 'gge19' };
var infoText = {};
try
{
for(var i in gidObj)
{
infoText[i] = api('getShape', { id: gidObj[i] }).text;
if(infoText[i] == undefined) // Check if we obtained valid string
throw 'Error reading parameter ' + i;
}
var padSize = { x:0, y:0 }, drillSize = { x:0, y:0 }, drillShape, padShape, Rotation, Plated, maskExpand, Unit, layerID;
if(infoText.padsize.indexOf('*') != -1) // Parse pad size
{
var padSizeS = infoText.padsize.split('*');
padSize.x = parseFloat(padSizeS[0]) / 10;
padSize.y = parseFloat(padSizeS[1]) / 10;
}
else
throw "Invalid pad size; expected FLOAT*FLOAT";
switch(infoText.layer) // Parse layer
{
case 'THROUGH':
if(infoText.drillsize.indexOf('*') != -1) // Parse drill size
{
var drillSizeS = infoText.drillsize.split('*');
drillSize.x = parseFloat(drillSizeS[0]) / 10;
drillSize.y = parseFloat(drillSizeS[1]) / 10;
switch(infoText.drillshape) // Parse drill shape
{
case 'CIRCLE':
if(drillSize.x != drillSize.y)
throw "Slot drill size doesn't match circle drill shape.";
else
drillShape = 'CIRCLE';
case 'SLOT':
if(drillSize.x == drillSize.y)
{
console.warn("Slot drill shape doesn't match circle drill size. Will use circle instead.");
drillShape = 'CIRCLE';
}
else
drillShape = 'SLOT';
}
}
else
throw "Invalid drill size; expected FLOAT*FLOAT";
layerID = 11;
break;
case 'TOP':
layerID = 1;
break;
case 'BOTTOM':
layerID = 2;
break;
default:
throw "Invalid layer; expected THROUGH, TOP or BOTTOM";
}
switch(infoText.padshape) // Parse pad shape
{
case 'ELLIPSE':
case 'OVAL':
case 'RECT':
padShape = infoText.padshape;
break;
case 'POLYGON':
throw "Invalid pad shape: polygon is not supported";
break;
default:
throw "Invalid pad shape; expected ELLIPSE, OVAL or RECT";
}
Rotation = parseFloat(infoText.rotation);
switch(infoText.plated)
{
case 'YES':
Plated = true;
break;
case 'NO':
Plated = false;
break;
default:
throw "Invalid plating option; expected YES or NO";
}
maskExpand = parseFloat(infoText.maskexpand) / 10;
switch(infoText.unit)
{
case 'MIL':
case 'MM':
case 'INCH':
Unit = infoText.unit;
break;
default:
throw "Invalid unit; expected MIL, MM or INCH";
}
var NamingRule=[], IndexWithRule=[];
namingruleS = infoText.name.split(',');
for(var i = 0; i < namingruleS.length; i++)
{
if(namingruleS[i].indexOf('-') == -1)
NamingRule[i] = [namingruleS[i], ''];
else
{
t = namingruleS[i].split('-');
if(t.length > 2)
throw "Invalid rule " + namingruleS[i];
else if(t.length == 2)
{
if(t[0] == '' && t[1] == '') // Single dash
NamingRule[i] = ['-',''];
else if(isNaN(parseInt(t[0])) || isNaN(parseInt(t[1]))) // T:
if(t[0].length > 1 || t[1].length > 1)
throw "Invalid rule " + namingruleS[i];
else if(t[0] == t[1])
{
console.warn("Rule " + namingruleS[i] + " have no effect.");
NamingRule[i] = [namingruleS[i], ''];
}
else if(t[0].charCodeAt(0) > t[1].charCodeAt(0))
throw "Invalid rule " + namingruleS[i];
else
{
NamingRule[i] = [t[0], t[1]];
IndexWithRule.push(i);
}
else
{
var t0 = parseInt(t[0]), t1 = parseInt(t[1]);
if(t0 > t1)
throw "Invalid rule " + namingruleS[i];
else if(t0 == t1)
{
console.warn('Rule ' + namingruleS[i] + ' has no effect.');
NamingRule[i] = [namingruleS[i], ''];
}
else
{
NamingRule[i] = [t0, t1];
IndexWithRule.push(i);
}
}
}
else
NamingRule[i] = [namingruleS[i], ""];
}
}
var loopList = [];
for(var i = 0; i < IndexWithRule.length; i++)
loopList.push[ NamingRule[IndexWithRule[i]].charCodeAt(0) - 1];
while(!alltrue(IndexWithRule, loopList, NamingRule))
{
increment(IndexWithRule, loopList, NamingRule, IndexWithRule[IndexWithRule.length - 1]);
}
api('createShape', {"shapeType": "PAD", jsonCache:{
number: 1,
shape: padShape,
layerid: layerID,
net:"",
width: padSize.x,
height: padSize.y,
holeCenter: { x:4000, y:3000 },
holeR: drillSize.x / 2,
holeLength: drillShape == 'SLOT' ? padSize.y : 0,
solderexpansion: maskExpand,
plated: Plated == true ? 'Y' : '',
x: 4000,
y: 3000,
gId:5555
}})
}
catch(e)
{
if(typeof e == 'object Object')
alert('Error: ' + e.message);
else if(typeof e == 'string')
alert('Error: ' + e.message);
else
alert('Unknown kind of error occured.');
}
function alltrue(a, b, c)
{
for(var i = 0; i < a.length; i++)
if(b[a[i]] != c[a[i]][1])
return false;
return true;
}
function increment(a, b, c, d)
{
if(d == -1)
return; // Carried to the first digit
b[a[d]] = fromCharCode(b[a[d]].charCodeAt(0) + 1); // Increment
if(b[a[d]] == c[a[d]][1])
{ // Carry
b[a[d]] = c[a[d]][0];
increment(a, b, c, d - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment