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/abouc/OneDrive - USN/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".