Support Forum

Place Refereces of cells in a big cell based on coordinates from a TXT file

Angelos

Tuesday 14th June 2022
Hey I want to fill a cell with references of a few different cells that i can design. I want to place references of the copies on coordinates that will be taken from a txt file. The format will have (X "space" Y) in each line and the next set of coordinates will be on the next line. From the macro recording i have got the following to place a reference of a cell and it works but i don't know how to do this while reading coords from a file. I am completely clueless in programming (just some numerical things on matlab) so if someone could help me by writing a loop for this , that would be very nice. I believe this is a very simple script but i just havent managed anything yet. ( Where do i have to place the txt file so the software can read it)? ```cpp int main(){ layout->drawing->point( X ,Y ); layout->drawing->cellref("CELL1"); } } ```
Jürgen
LayoutEditorFull
Tuesday 14th June 2022
Within the any LayoutEditor package there is a folder named *macros/examples.* In that folder is an example macro named *circles.layout* almost doing what you need: reading coordinates from a TXT file and place a circle at that position with a certain radius. You just need to exchange the *circle* command with the *cellref* command you have already mentioned and you are done: ```cpp #!/usr/bin/layout #name=read coordinates from file from file #help=read coordinates from file from file int main(){ file f; f.filename="coordinates.txt"; // filename bool b=true; f.open(b); string s=f.read(); f.close(); stringList sl=s.split("\n"); int i,k; layout->drawing->clearPoints(); for(i=0;i<sl.size();i++){ if (sl.at(i).left(1)!="#"){ // line starting with a # are ignored stringList sl2=sl.at(i).split(","); // x,y are separated by , if (sl2.size()>=3){ double x=sl2.at(0).toDouble(); double y=sl2.at(1).toDouble(); int layer=1; if (sl2.size()>3) layer=sl2.at(2).toInt(); // third value is used as layer layout->drawing->activeLayer=layer; layout->drawing->p(x,y); layout->drawing->cellref("mycell"); } } } layout->drawing->scaleFull(); } ```
Angelos

Tuesday 14th June 2022
Thank you for your quick reply. Where should i put my txt file or my layout design with the existing cells? I am using windows if that matters ? It is just the name of it or directory ( C:user\documents\..\ coords.txt )? I see i must seperate the x and y with coma (,). I tried the code but nothing happens. Thank you
Angelos

Tuesday 14th June 2022
Quick update I disabled the " if (sl2.size()<=3){ " and replaced "stringList sl2=sl.at(i).split(",")" with space " " instead of "," and it works . Although i get an error but who cares for now :D Executing Macro "read coordinates from file from file" (C:/Users/Usr/Loc/Ledit/SCRIPT WORKING.layout). Errors: 1 out of range (row 21) 1 Executing abort. Strong warnings: 1 main function exit code: 1
Jürgen
LayoutEditorFull
Thursday 16th June 2022
please change the line ```if (sl2.size()<=3){ ``` to ```if (sl2.size()<=2){ ``` as two parameters are fine for you application. If you remove the line completely you will get the menitoned error on ever empty line or line with just one value. The file should be in the folder of the macro. If it is place in another folder, please add the path in front of in for example "C:/User/my_mane/data/coordinates.txt".
Angelos

Monday 18th July 2022
Hi again Jurgen Thank you for your reply. For now, i will be using just 2 parameters (x,y) but later i will probably start using more parameters like angle. What i would like some extra help is creating a loop to execute the script X times. For example i set the number of loop to 4. In this case 4 means there are 4 different cells and 4 txt files. The naming of the cells and the txt files is simple. It is the name of the cell and a numbering (cell1, cell2,cell3,cell4 for cells and coords1.txt, coords2.txt ... for txt files). So the script would place the cell1 based on the coords1.txt, then it will go to the cell2 and place it based on coords2.txt etc. Could you please help me with that? Thank you
Jürgen
LayoutEditorFull
Monday 18th July 2022
I that case you just need to add a further *for* loop to the script: ```CPP int main(){ for (int count=1;count<5;++count){ file f; string countString; countString.setNum(count); f.filename="coordinates"+countString+".txt"; // filename bool b=true; f.open(b); .... } } } } layout->drawing->scaleFull(); } ```