You need to use EasyEDA editor to create some projects before publishing
Arranging parts in PBC using API javascript code
435 4
Yariv Hashai 3 years ago
Hello, I'm having a board with some components, leds and capacitors. all the leds has a prefix with running numbers 1-200 and related capacitors with prefix of c1-c200 I searched for the API code for rotating and moving parts: `api('rotate', {ids:["gge2","gge3"],degree:90});` And for moving: `api('moveObjsTo', {objs:["gge2","gge3"], x: api('coordConvert', {type:'real2canvas',x: '10mm'}), y: api('coordConvert', {type:'real2canvas',y: '10mm'})});`<br> <br> <br> The issue is that I don't know how to get the mapping between the IDs into the prefix, I was trying to rotate and move it via prefix without any success. Does anyone familiar with how I can get the mapping between all my parts prefix to IDs? or moving parts via prefix?
Comments
andreasbernhofer 3 years ago
Hey, you do know about "Format" -> "Distribute array"? You can use it to distribute the components in a regular pattern. Or do you really need some arbitrary function based on the prefix? You can select e.g. all caps using the find function and the execute this: ``` js api('getSelectedIds').split(',').forEach((id)=>{ shape = api('getShape',{id: id}); console.log(shape); prefix = Object.entries(shape.TEXT).filter(t=>t[1].type=='P')[0][1].text; // do your stuff with prefix and id }) ``` Footprints are complex shapes. You can find the prefix via `Object.entries(shape.TEXT).filter(t=>t[1].type=='P')[0][1].text` which finds the TEXT of the footprint of type `P`. I'm sure there is a better function to get the prefix, but this is what came to my mind first ;)
Reply
andreasbernhofer 3 years ago
Okay\, sure\, there is a better way\.\.\. the find function ;\) \`console\.log\( api\('editorCall'\,\{cmd: 'findComponent'\, args: \['U1'\,'prefix'\]\}\)\.id \);\` Better use this to iterate over your components.
Reply
andreasbernhofer 3 years ago
Sorry, correct syntax: `console.log( api('editorCall',{cmd: 'findComponent', args: ['U1','prefix']}).id );`
Reply
Yariv Hashai 3 years ago
Amazing guys! thanks for the help!
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 -mockplus- -mockplus- -mockplus- -mockplus- -mockplus- -mockplus- -mockplus- -mockplus-@1x -mockplus-

Cookie Notice

Our website uses essential cookies to help us ensure that it is working as expected, and uses optional analytics cookies to offer you a better browsing experience. To find out more, read our Cookie Notice