Scripting - Set component positions
90 1
g3gg0.de 1 week ago
Hi all, assuming i have a list of all component names and their (center) X/Y position in mil from the PCB origin as well as their origins. Now I want to programmatically position all components in the PCB layout at the given positions w/ their rotation. (as if I trained a monkey selecting manually a component by its name and enter the X/Y values) So i have a bunch of hurdles and questions, I hope some can be answered by you :) I tried fetching the source using api('getSource', {type: "json"}); -> result: got all important information. but... every single drawable entity with their subentities and texts and arcs and stuff etc has its absolute position in there. I would have to fully understand the mechanics of what is a LINE and an ARC and TEXT and PAD and must not forget a single unexpected item there. [Bug?] Tried to get the real position like in the examples using api('coordConvert', {type:'canvas2real',x: 10}) -> result: i was not able to convert "mil" or "mm" units into the "real" coordinates, as the API call is crashing:     message: "getPCBUnit is not defined"     stack: "[email protected][https://easyeda.com/editor/6.4.7/js/main.min.js:18:19407](https://easyeda.com/editor/6.4.7/js/main.min.js:18:19407%5Cna/) **edit:** Oh no! Most of the post vanished. It was cut right in the middle of the stackdump. darn. Questions: 1\. how to set the rotation \*absolute\* ? 2\. how to get the current X/Y/rotation? 3\. how to select a component by its name \(like "R12"\)? 4\. what would be your preferred approach to set component positions? Thats my current test code: `api('moveObjsTo', { objs:["gge5d7d37af6db8001c"], x:4000, y:3000}); // manually set position to origin` `api('rotation', {ids:["gge5d7d37af6db8001c"], degree:90});`
Comments
g3gg0.de 1 week ago
my current approach for storing positions and applying positions: `// store component positions` `var result = api('getSource', {type: "json"});` `var ids = [];``for (id in result.FOOTPRINT)` `{` `    var head  = result.FOOTPRINT[id].head;` `    var texts = result.FOOTPRINT[id].TEXT;` `    for (subObject in texts)` `    {` `        if(texts[subObject].type == "P")` `        {` `            ids.push( { id: id, name: texts[subObject].text, x: head.x, y: head.y, rotation: head.rotation } );` `        }` `    }` `}``document.storedPositions = ids;``-------------------------------------------------------------------------``// restore component positions - rotation does not work yet` `var dump = api('getSource', {type: "json"});``for (id in dump.FOOTPRINT)` `{` `    var head  = dump.FOOTPRINT[id].head;` `    var texts = dump.FOOTPRINT[id].TEXT;` `    for (subObject in texts)` `    {` `        if(texts[subObject].type == "P")` `        {` `            var name = texts[subObject].text;` `            var found = document.storedPositions.find(e => e.name == name);` `            if(found != undefined)` `            {` `                api('moveObjsTo', { objs: [ id ], x: found.x, y: found.y });` `                api('rotation',   { ids: [ id ],  degree: (found.rotation - head.rotation) });` `            }` `        }` `    }` `}`
Reply
Login or Register to add a comment
goToTop
你现在访问的是EasyEDA海外版,使用建立访问速度更快的国内版 https://lceda.cn(需要重新注册)
如果需要转移工程请在个人中心 - 工程 - 工程高级设置 - 下载工程,下载后在https://lceda.cn/editor 打开保存即可。
有问题联系QQ 3001956291 不再提醒
svg-battery svg-battery-wifi svg-books svg-more svg-paste svg-pencil svg-plant svg-ruler svg-share svg-user svg-logo-cn svg-double-arrow
We use cookies to offer you a better experience. Detailed information on the use of cookies on this website is provided in our Privacy Policy. By using this site, you consent to the use of our cookies.