logo

Thread

logo
the fair gds editor

Introduction
Screenshots
License
Download
Userinterface
Function Index
White Papers
Community
Contact

Use your OpenID:

getopenID

mouse left
no help

Macro File input

by Peter - 21 Jul 2009, 22:01 CEST

Hi I am trying to use a text file with the macro programming in LayoutEditor and I am having some trouble.

Lets say I have a text file with two columns of data ( an x and y coordinate), how would I read from the file and import the coordinates as separate variables?

by Juergen Thies - 22 Jul 2009, 8:39 CEST

If you have a file like this with space separated values:

0 0
100 0
100 100
0 0

You can read it via:


pointArray readFromFile(string filename){
file f;
f.filename=filename;
bool b=true;
//open for input
f.open(b);
string s=f.read();
f.close();

int pos=0;
pointArray pa;
point p;
do {
 pos=s.indexOf(" ",pos);
 if (pos>=0)
  {
   p.setX(s.left(pos).toInt());
   s=s.mid(pos+1);
   pos=s.indexOf("\n",pos);
   if (pos>=0){
    p.setY(s.left(pos).toInt());
    s=s.mid(pos+1);
    pa.attachPoint(p);
   }
  }
 } while (pos>0);
return pa;
}

by Juergen Thies - 22 Jul 2009, 8:49 CEST

BTW: The LayoutEditor supports reading from a CSV file. If you just need to import coordinates generated from a spread sheet programm like Microsoft Excel or OpenOffice calc, the CSV file will be the best choice.

by physnano - 22 Jul 2009, 17:18 CEST

I have imported the coordinates into an excel spreadsheet (2 separate columns). How do I import this into a macro?


by Juergen Thies - 22 Jul 2009, 17:26 CEST

A CSV File can directly be loaded via file open/import without the use of a macro. Within a macro use:
layout->drawing->importFile(filename);

Path/Polygon elements with the imported coordinates will be added to the active layer.


Please log in to post!