Created
March 14, 2021 03:40
-
-
Save kargeor/8a7444b68ed164409fb5935d375f5a77 to your computer and use it in GitHub Desktop.
EasyEDA add wires for all pins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRandomId() { | |
return "gge" + Math.round(Math.random() * 10000000); | |
} | |
const ids = api('getSelectedIds'); | |
const result = api('getSource', {type:'json'}); | |
function addWire(x1, y1, x2, y2) { | |
gId = getRandomId(); | |
result.wire[gId] = { | |
gId, | |
pointArr: [{x:x1,y:y1}, {x:x2,y:y2}], | |
locked: '0', | |
strokeColor: '#008800', | |
strokeWidth: '1', | |
strokeStyle: '0', | |
fillColor: 'none', | |
}; | |
} | |
if (!(ids in result.schlib)) { | |
alert("Please select object"); | |
return; | |
} | |
const o = result.schlib[ids]; | |
const allX = Object | |
.keys(o.pin) | |
.map(p => o.pin[p].configure.x); | |
const minX = Math.min(...allX); | |
const maxX = Math.max(...allX); | |
Object.keys(o.pin).forEach(p => { | |
const x = o.pin[p].configure.x; | |
const y = o.pin[p].configure.y; | |
let xx = x; | |
if (x == minX) xx -= 50; | |
else if (x == maxX) xx += 50; | |
else return; | |
addWire(x, y, xx, y); | |
}); | |
api('applySource', {source: result, createNew: false}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The id generator is not accessible by scripts :/ But you can use the
createShape
API and just omit thegId
. EasyEDA will generate one for you:By using this, together with
api('getShape',{id: id})
you also don't need to edit/apply the source (which resets the editors view).Edit: Also, to iterate over multiple selected components use
api('getSelectedIds').split(',')