I’ve been very busy in the last few weeks, mainly preparing for exams, presentation, assessments, work, more work, etc….and I’ve missed scripting!!
Igeo allows to save Obj and 3dm files directly, but that’s it, no more extensions allow as they will through an error, so I put together a script that saves points coordinates to a CSV file, which is very useful sometimes, as they don’t need all that extra information.
There is a problem though, that I’m trying to make a FileChooser to pop up to select a directory and choose a file name, but I still need to work that out. In the meantime the path is hardcoded and won’t catch any errors (I don’t know why) so be careful or not!
EDIT: I still can’t make the filechooser to come up, if you store the points on an IServer, processing’s own methods don’t work, in the meantime the amended code collects the basepath of your processing sketch and saves the file there!, still overrides an old file with the same though, what a pain!!!
code:
import igeo.*;
import processing.opengl.*;
void setup() {
size(1200, 1200, IG.GL);
String filename = “test”;
//Example to create and export point coordinates to CSV file
List<IPoint> myList = new ArrayList<IPoint>();
IRand currentRandom = new IRand(); //creates a new IRandom Object
currentRandom.initByTime();//Links the random seed to current time millisecs
for (int i=0; i<100; i++)
{
myList.add(new IPoint(new IVec(currentRandom.point())));
}
boolean result = EExport.exportPointCoordinates(filename);
if (result)
{
println (“Successfully exported point coordinates to file”);
}
else
{
println (“Sorry I couldn’t export point coordinates to file”);
}
}
//IO class
static class EExport
{
public static boolean exportPointCoordinates(String filename)
{
boolean result = false;
IG currentServer = IG.current();
File aFile = new File(currentServer.basePath + “/” + filename + “.txt”);
try
{
FileWriter aFileWriter = new FileWriter(aFile);
IPoint[] allPointsInServer = currentServer.getPoints();
{
for (IPoint eachPoint : allPointsInServer)
{
aFileWriter.write( Double.toString(eachPoint.x()) + “,” + Double.toString(eachPoint.y())
+ “,” + Double.toString(eachPoint.z()));
aFileWriter.write(System.getProperty(“line.separator”));
}
aFileWriter.close();
result = true;
}
}
catch(Exception e)
{
println(“Error while writing to file ” + ” ” + e);
}
return result;
}
}

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales License.