You need to use EasyEDA editor to create some projects before publishing
Change prefix attribute programmatically with API Script
608 2
112358 5 years ago
Hi! I'm new in the use of javascript and i'm trying to write a script that copy a component, place it in a specified position and then change its suffix. The js code i wrote copy and move correctly the new component but when i change the prefix it doesn't change on the screen while in the attribute i can see it correctly like shown in the picture. Can anyone help me? ![Untitled.jpg](//image.easyeda.com/pullimage/qaATzIbSvaJQ6GxF7HrMuu2stKdg8viEHnryAbfo.jpeg) The code is the following: ``` create_TP("gge2",2.54,2.54,"TIP2"); ``` ``` function create_TP (id,x_mm,y_mm,reference) { var newId = api('clone', {ids:[id]}); // create clone api('moveObjsTo', {objs:newId, x: api('unitConvert', {type:'mm2pixel',value:x_mm}), y: api('unitConvert', {type:'mm2pixel',value:y_mm})});     var json = api('getSource', {type:'json'}); json.FOOTPRINT[newId].TEXT[Object.keys(json.FOOTPRINT[newId].TEXT)[0]].text="TP2"; //alert(json.FOOTPRINT[newId].TEXT[Object.keys(json.FOOTPRINT[newId].TEXT)[0]].text); api('applySource', {source: json, createNew: !true}); } ``` Thank you. Andrea.
Comments
eric 5 years ago
You can try change this line ``` json.FOOTPRINT[newId].TEXT[Object.keys(json.FOOTPRINT[newId].TEXT)[0]].text="TP2"; ``` to ``` var objPrefix = json.FOOTPRINT[newId].TEXT[Object.keys(json.FOOTPRINT[newId].TEXT)[0]]; objPrefix.text="TP2"; objPrefix.pathStr=''; //clear cached pathStr, this is the key point ```
Reply
112358 5 years ago
It works! Thank you!
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