Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

export image file in java from COMSOL and also plotting while solving

Please login with a confirmed email address before reporting spam

I am running a bunch of 1 hour time dependent COMSOL models in a big 'for' loop. I can get Eclipse to export a .txt file for each iteration of the 'for' loop and I can show a progress bar and a 2D/3D image at the end inside a the GUI (this is the GUI in the back of the API guide) Comsol provides for eclipse. I am having 2 problems though:

1) I can not get COMSOL to export an image file. The line of code:

model.result().export("plot1").run();

works for exporting .txt, but using:

model.result().export("img1").run();

does NOT work for exporting an image file. nothing appears.

I added the code:

BufferedImage bi = new BufferedImage(pWidth,pHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
frame.paint(g);
g.dispose();
try{ImageIO.write(bi,"png",new File("C:\\Users\\Alex\\Desktop\\surf_"+i+".png"));}catch (Exception e) {}

and I can get a screenshot of the JFrame of the GUI at the end of each time simulation but not the 2D plot that shoud appear (see attached file).

Anyone have hints how to make the export feature work for COMSOL and an image or how to take a screenshot with the 2D image in the JFrame?

2)
In that same GUI, what code and where do I need to add it to have the GUI display the solution as it happens?

model.sol("sol1").feature("t1").feature("fc1").set("plot", "on"); does not work, and:
model.sol("sol1").feature().create("t1","PlotWhileSolving") gives me the error:

com.comsol.util.exceptions.FlException: Operation cannot be created in this context

Thanks for any help



1 Reply Last Post 3 août 2012, 07:17 UTC−4

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 3 août 2012, 07:17 UTC−4
So I can use "Robot" to take a screenshot of the GUI but this is only kind of what I want. Does anyone have other suggestions besides exporting the data and compiling it in another program
So I can use "Robot" to take a screenshot of the GUI but this is only kind of what I want. Does anyone have other suggestions besides exporting the data and compiling it in another program

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.