API列表 
API List 
获取 EasyEDA 源 
- 获取 EasyEDA JSON 对象,类型为 
json,您可以查看 PCB Json 对象 了解更多信息。 
var result = api('getSource', {type:'json'});
- 获取 EasyEDA 压缩字符串,EasyEDA 将此字符串保存到我们的数据库中,它有点难以阅读和理解,但大小很小。EasyEDA 将此字符串保存到我们的数据库中。
 
var result = api('getSource', {type:'compress'});
- 获取 SVG 字符串
 
var result = api('getSource', {type:'svg'});
查看 获取 EasyEDA 源示例代码。
应用源 
使用代码破解 EasyEDA 源后,您需要将源应用到 EasyEDA 编辑器。您可以
- 应用为压缩字符串
 
//将打开一个新的编辑器并将 compressStr 转换为 EasyEDA 文件。
api('applySource', {source:'compressStr', createNew: true});- Apply as Json object.
 
//将修改活动文件并将 json 对象转换为 EasyEDA 文件。
api('applySource', {source: json, createNew: !true});查看应用源示例代码。
获取形状 
如果您想通过id获取 EasyEDA json 对象,您可以尝试使用以下代码。
var obj = api('getShape', {id:'gge13'})
删除形状 
通过以下代码删除形状
更新形状 
如果您想修改 EasyEDA 对象,您可以使用此 API。
将网络更改为 GND,将形状更改为 ELLIPSE:
 api('updateShape', {
          "shapeType": "PAD",
         "jsonCache": {
         "gId": "gge5",
         "net": "GND"
         "shape": "ELLIPSE"
        });2
3
4
5
6
7
shapeType 和 gId 必须提供.
- 原理图 
shapeType,schlib,rect,polyline,polygon,wire,bus,image,circle,ellipse,line,path,arc,annotation,junction,netlabel,busentry,arrowhead,noconnectflag,pin,netflag - PCB 
shapeType,FOOTPRINT,TRACK,COPPERAREA,SOLIDREGION,RECT,CIRCLE,TEXT,ARC,DIMENSION,PAD,VIA,HOLE 
创建形状 
如果您想通过代码创建 EasyEDA 形状,您可以尝试一下。我们将很快提供有关此 API 的更多信息,现在我们仅提供示例。您将了解如何操作。
使用 shortUrl: @example
api('createShape', {shapeType:'schlib', shortUrl:'nxlVIGgQO', from:'system', title:'556_DIL14', x:400, y:300});
api('createShape', {shapeType:'FOOTPRINT', shortUrl:'RrkewO60i', from:'system', title:'ARDUINO_PRO_MINI', x:400, y:300});2
在 jsonCache 里面的 object:
@example
api('createShape', {
  "shapeType": "PAD",
  "jsonCache": {
    "gId": "gge5",
    "layerid": "11",
    "shape": "ELLIPSE",
    "x": 382,
    "y": 208,
    "net": "",
    "width": 6,
    "height": 6,
    "number": "1",
    "holeR": 1.8,
    "pointArr": [],
    "rotation": "0"
  }
});2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@example
api('createShape', {
    "shapeType": "polygon",
    "stroke": "#000000",
    "stroke-width": "1",
    "stroke-style": "dashed",
    "fill": "none",
    "points": [
        {"x": 390, "y": 580},
        {"x": 450, "y": 450},
        {"x": 520, "y": 580},
        {"x": 610, "y": 490}
    ]
});2
3
4
5
6
7
8
9
10
11
12
13
@example
api('createShape', {
    "shapeType": "arrowhead",
    "x": 300,
    "y": 300,
    "color": "#339933",
    "size": "3",
    "rotation": 0
});2
3
4
5
6
7
8
@example
var ts = ["no_connect_flag", "arrowhead", "busentry", "netLabel_GNd", "netLabel_GnD", "netLabel_gnD", "netLabel_Bar", "netLabel_VEE", "netLabel_-5V", "netLabel_+5V", "netLabel_VCC", "netLabel_volProbe", "netLabel_netPort", "netLabel_text", "pin", "annotation"];
for(var i=0;i<ts.length;i++){
    api('createShape', {
        "shapeType": ts[i],
        "x": 300 + i%5*50,
        "y": 300 + (i/5|0)*50
    });
}2
3
4
5
6
7
8
使用缓存或预定义的库: @example
api('createShape', {"shapeType": "pcblib", from:'GeneralPackages', title:'C0402', x:400, y:300});
@example
api('createShape', {"shapeType": "schlib", from:'EasyEDALibs', title:'HDR2X2', x:400, y:300});2
3
@example 4
api('createShape', {
    "shapeType": "schlib",
    "gId": "gge6",
    "head": {},
    "itemOrder": [],
    "annotation": {
        "gge8": api('createShape', 'annotation', {}),
        "gge9": api('createShape', 'annotation', {})
    },
    "pin": {
        "gge11": api('createShape', 'pin', {}),
        "gge14": api('createShape', 'pin', {})
    },
    "polyline": {
        "gge10": api('createShape', 'polyline', {}),
        "gge12": api('createShape', 'polyline', {})
    }
});2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@example 5
api('createShape', {
    "shapeType": "schlib",
    "gId": "gge6",
    "head": {},
    "children": [
        api('createShape', 'polyline', {}),
        api('createShape', 'polyline', {}),
        api('createShape', 'pin', {}),
        api('createShape', 'pin', {}),
        api('createShape', 'annotation', {}),
        api('createShape', 'annotation', {})
    ]
});2
3
4
5
6
7
8
9
10
11
12
13
@example 6
api('createShape', {
    "shapeType": "schlib",
    "gId": "gge6",
    "head": {},
    "children": api('createShape', [
        ['polyline', {}],
        ['polyline', {}],
        ['pin', {}],
        ['pin', {}],
        ['annotation', {}],
        ['annotation', {}]
    ])
});2
3
4
5
6
7
8
9
10
11
12
13
UI 
如果您想创建一个扩展,而不仅仅是运行一次脚本,可能需要工具栏按钮。阅读之前,您可以查看示例。
创建工具栏按钮 
@example 创建一个按钮:
 api('createToolbarButton', {
      icon:'extensions/theme/icon.svg',
      title:'Theme Colors...',
      fordoctype:'sch,schlib',
      cmd:"extension-theme-setting"
     });2
3
4
5
6
@example 工具栏和菜单:
api('createToolbarButton', {
 icon:'extensions/theme/icon.svg',
 title:'Theme Colors...',
 fordoctype:'sch,schlib',
 "menu" : [
     {"text":"White on Black", "cmd":"extension-theme-WhiteOnBlack"},
     {"text":"Black on White", "cmd":"extension-theme-BlackOnWhite"},
     {"text":"Custom Colors...", "cmd":"extension-theme-setting"}
 ]
});2
3
4
5
6
7
8
9
10
创建扩展菜单 
@example
api('createExtensionMenu', [
 {
     "text":"Theme Colors...",
     "fordoctype": "sch,schlib",
     "cmd": "extension-theme-white"
 }
]);2
3
4
5
6
7
创建对话框 
查看示例
命令列表 
克隆 
// 克隆 gge2 gge3 并返回它们的新 ID。
      var newIds = api('clone', {ids:["gge2","gge3"]})
  api('delete', {ids:["gge2","gge3"]});Rotate 
// rotate ids to 90 degree
    api('rotate', {ids:["gge2","gge3"],degree:90});Rotate Left 
//anticlockwise
    api('rotate_left', {ids:["gge2","gge3"]});Rotate Right 
//clockwise
    api('rotate_right', {ids:["gge2","gge3"]});Fliph 
    api('fliph', {ids:["gge2","gge3"]});Flipv 
    api('flipv', {ids:["gge2","gge3"]});Align Left 
api('align_left', {ids:["gge2","gge3"]});
Align Right 
api('align_right', {ids:["gge2","gge3"]});
Align Top 
api('align_top', {ids:["gge2","gge3"]});
Align Bottom 
api('align_bottom', {ids:["gge2","gge3"]});
Selection 
Change or get selection states of EasyEDA objects in editor.
Select 
// gge2 and gge3 will be marked as selected.
      api('select', {ids:["gge2","gge3"]});Select None 
//no objects will be selected.
      api('selectNone');Get Selected Ids 
 var ids = api('getSelectedIds');
移动 
您可以使用 更新形状 来更改形状的位置,但在这种情况下,移动方法更好。
移动对象 
在相对坐标中移动形状,例如使用箭头键移动形状。
//以 20 像素或 200mil 的步长从左向右移动 gge2 和 gge3 //以 20 像素或 200mil 的步长从上向下移动。
api('moveObjs', {objs:[{gId:"gge2"},{gId:"gge3"}], addX: 20, addY: 20});//Move gge2 and gge3 from right to left in 20pixel or 200mil step
api('moveObjs', {objs:["gge2","gge3"], addX:-20});//Move selected objects from left to right in 20pixel or 200mil step
api('moveObjs', {addX:20});移动对象到 
如何将 VIA 或 junction 移动到位置 {x:'10mil', y:'10mil'} ?, 将形状移动到绝对坐标。 //将 gge2 和 gge3 移动到画布位置 20,20,实际坐标取决于原点。
 api('moveObjsTo', {objs:[{gId:"gge2"},{gId:"gge3"}], x:20, y:20});//将 gge2 和 gge3 移动到 10mm、10mm 坐标
 api('moveObjsTo', {objs:["gge2","gge3"], x: api('coordConvert', {type:'real2canvas',x: '10mm'}), y: api('coordConvert', {type:'real2canvas',y: '10mm'})});//将选中的对象移动到画布20,20的位置,真实坐标取决于原点。
 api('moveObjsTo', {x:20, y:20});将 PAD、VIA、Junction 移动到绝对坐标很容易理解。但是将 TRACK、FOOTPRINT、netlabel 移动到某个位置会有什么影响呢?只需尝试运行代码,您就会发现规律。
SetOriginXY 
EasyEDA 的画布原点是 0,0,您无法更改它。但实际坐标可以映射到任何地方。
//将实际原点设置为画布 x = 400,y = 300。X、Y 始终为像素。
    var result = api('setOriginXY', {x:400,y:300});坐标转换 
您可以使用 mm 或 mil 或 inch 作为单位,但当您将参数应用于 SVG 图形时,您必须使用坐标转换。
//将画布 x 400 转换为实际位置,该值取决于您的单位和原点。
    var result = api('coordConvert', {type:'canvas2real',x:400})//默认单位是你的画布单位,但你可以添加像 300mm 这样的单位。 //如果你的 PCB 的单位是 mil,那么你将得到画布坐标 400mil,300mm。
     var result = api('coordConvert', {type:'real2canvas',x:400,y:'300mm'});如果你将原点设置为0,0。你很容易在脑海中映射坐标,不需要使用API进行转换。画布坐标100,100等于实际坐标1000mil,1000mil或1inch,1inch或393.7mm,393.7mm
值转换 
如何将焊盘的孔尺寸设置为20mm?如何将轨道宽度设置为20mil?
//默认单位是你的画布单位,但你可以添加毫米、密耳、英寸甚至像素等单位。
 var result = api('valConvert', {type:'real2canvas',val:400});
     result = api('valConvert', {type:'real2canvas',val:'400mm'})2
//将 400 像素转换为真实值,该值取决于你的单位,如果单位是 mil,则结果应该是 4000
result = api('valConvert', {type:'canvas2real',val:400})如果您能记住画布上的 1 像素等于 10mil,那么您就不需要此 API,您可以以原始方式执行此操作。例如, 如果您想将轨道大小更新为 20mil,您可以这样做。
 api('updateShape', {
          "shapeType": "TRACK",
         "jsonCache": {
             "gId": "gge5",
             "strokeWidth": 2
        }
        });2
3
4
5
6
7
或
 api('updateShape', {
          "shapeType": "TRACK",
         "jsonCache": {
             "gId": "gge5",
             "strokeWidth":  api('valConvert', {type:'real2canvas',val:'20mil'})
        }
     });2
3
4
5
6
7
获取 SVG 弧形路径 
SVG 弧形路径参数 非常复杂,我们提供了一个 API 将人类可读的 ARC 参数转换为 SVG 路径。
 var result = api('getSvgArcPathByCRA', {cx:0, cy:0, rx:90, ry:90, startAngle:0.1, endAngle:0.7, sweepFlag:1});运行的结果是: M89.55037487502231 8.985007498214534A90 90 0 0 1 68.83579685560396 57.97959185139219