You need to use EasyEDA editor to create some projects before publishing
Create a track in API
763 8
BillyBuerger 5 years ago
I have some very specific tracks I'm trying to create on my PCB.  Placing by hand is slow and difficult to get right.  I already have some scripts I created to place my footprints automatically based on my known coordinates.  So I'm trying to figure out how to place some tracks around the footprints with my known coordinates as well.  But I'm not seeing anything in the API reference for doing that.  I see examples of createShape and insertShape using the shapeType polyline and path.  But neither of these examples seem to actually do anything.  Is this possible?
Comments
andreasbernhofer 3 years ago
I have the same issue. Despite the fact that there is no documentation on the object that has to be passed to `insertShape` / `createShape`, all the examples using them just do nothing at all :(
Reply
VercorsSciences 3 years ago
Hello, the pcb json object contains several objects and more particularly SIGNALS and TRACK. `var pcb = api('getSource', {type:'json'});` How to add a track ? First, create an arbitrary  "gId" like "myTrack" as it MUST be unique. Then, add this object  into the SIGNAL object : `pcb.SIGNALS.<your net name>.push({` `"gId": "<your gId>",` `"cmd": "TRACK",` `"layerid":1,  // <-- to be aligned with your PAD layer` `"fid": 0 // <-- set  this to zero` `})` Ok, now let add your real TRACK : `pcb.TRACK.<your gId>= {` `"gId": "<your gId>",` `"layerid": "1", //<-- MUST be aligned with your PAD layer` `"net": "R_D0",` `"pointArr": [` `{` `"x": 4373.752, //<-- x start point` `"y": 2990.835`    // <-- y start point `},` `{` `"x": 4373.752, //<-- end of the wire` `"y": 3100`    //<-- end of the wire `}]` `}` Then, repeat {x,y] tuples in the pointAddr as long as you need to add vectors. Do not forget to update your pcb with : `api('applySource', {source: pcb, createNew: !true});`<br> <br> This works for me. Feel free to give me some feedbacks I'm not sure how to generate the gId... Cheers
Reply
andreasbernhofer 3 years ago
@VercorsSciences you are right, you can add tracks by editing the project source (json) via the API. I also used this in a project here: [https://github.com/xsrf/easyeda-svg-import/](https://github.com/xsrf/easyeda-svg-import/blob/617e2032aaf45f84e93857bd65f7de0423ac6f38/extension/main.js#L431) The gId generator is (afaik) not accessible for an extension, but you can generate your own IDs. Didn't find any problems with that so far. I use this: ``` js function newId() { return "cgge"+Math.floor(Math.random() * 9e6); } ``` Better way would be to use incrementing IDs with your own prefix, but you'll need to keep track of them.
Reply
andreasbernhofer 3 years ago
Also, instead of editing the project source, the `createShape` API can be used ``` js api('createShape',{ shapeType:'TRACK', "jsonCache": { gId: "gge"+Math.floor(Math.random() * 9e6), // optional layerid: "1", pointArr: points // as described by VercorsSciences } }); ``` In this case the gId attribute is actually optional... a new one will be created. But I don't know how to reference it in case you need it afterwards... api() won't return the id.
Reply
BillyBuerger 2 years ago
Thanks, I just noticed there was some discussion here.  I was able to successfully create a track from your suggestions using this... ``` api('createShape',{ shapeType:'TRACK', "jsonCache": {         "layerid":1, pointArr: [{ "x": 0, "y": 0 }, { "x": 10, "y": 0 }, { "x": 10, "y": 10 }, { "x": 20, "y": 10 }] } }); ```  The only problem I have is that the location is not at around 0,0 but is ending up at about -1000,900.  I know in some of my other scripts, I'm converting from mm to mil even though my canvas is set to mm.  But that would still be centered at 0,0.  Not sure why these coordinates are ending up so far away.  I'll keep looking but if anyone has any thoughts there, that would be helpful.
Reply
andreasbernhofer 2 years ago
@BillyBuerger the coordinates used by the api are always in absolute relation to the canvas (not the origin) and the unit is always 1/100 Inch. You can query the origin coordinates via `api('getSource',{type:'json'}).canvas.originX` and `api('getSource',{type:'json'}).canvas.originY` and translate your tracks coordinates accordingly.
Reply
andreasbernhofer 2 years ago
Alternative for getting canvas attributes (might be faster than querying the source, not sure): `api('editorCall','getCanvas')`
Reply
BillyBuerger 2 years ago
Thank you so much.  This is now working as expected... ``` // Get the origin of the canvas var can = api('editorCall','getCanvas'); var x = can.originX; var y = can.originY; // convert mm to 100th of an inch var off = 10/0.254 // Create the track api('createShape', {     shapeType:'TRACK',     "jsonCache": {         "layerid":1,         pointArr: [             {"x":x, "y":y},             {"x":x+off, "y":y},             {"x":x+off, "y":y+off},             {"x":x+2*off, "y":y+off}         ]     } }); ```
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