Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
I'm trying to save a image of a part as a tiff-file, but I can't get it to work.
This is there I came to, it failed on the last line.
I also need to orientate the part in "default orientation" and show in "ho hidden"
Can anyone help?
private RasterImageExportInstructions getRasterInstructions(RasterType type) throws jxthrowable {
double rasterHeight = 7.5;
double rasterWidth = 10.0;
DotsPerInch dpi = DotsPerInch.RASTERDPI_100;
RasterDepth depth = RasterDepth.RASTERDEPTH_24;
RasterImageExportInstructions instructions;
TIFFImageExportInstructions tiff_instrs = pfcWindow.TIFFImageExportInstructions_Create (rasterHeight, rasterWidth);
instructions = tiff_instrs;
return instructions;
}
RasterImageExportInstructions instructions;
TIFFImageExportInstructions tiff_instrs = pfcWindow.TIFFImageExportInstructions_Create(7.5, 10.0);
instructions = tiff_instrs;
RasterType type = null;
RasterImageExportInstructions instructions = getRasterInstructions (RasterType.RASTER_TIFF);
instructions.SetImageDepth(RasterDepth.RASTERDEPTH_8);
instructions.SetDotsPerInch(DotsPerInch.RASTERDPI_100);
String sModelName = model.GetFullName() + ".tif";
MySession.ExportCurrentRasterImage (sModelName, instructions);
Regards
Allan
If I put the last part of my code in a void:
private static void CreateDTIF(Model model, Session session) throws jxthrowable {
DotsPerInch dpi = DotsPerInch.RASTERDPI_100;
RasterDepth depth = RasterDepth.RASTERDEPTH_24;
RasterType type = null;
RasterImageExportInstructions instructions = getRasterInstructions (RasterType.RASTER_TIFF);
instructions.SetImageDepth(depth);
instructions.SetDotsPerInch(dpi);
String sModelName = model.GetFullName() + ".tif";
session.ExportCurrentRasterImage(sModelName, instructions);
}
then it works then I call it then I have a part open. But I will like to start the script then I have a drawing, and let the script open the part.
I have tried this:
private static void ExportToTiff(Session MySession, Model model) throws jxthrowable {
try {
String ModelName = model.GetFileName();
try {
String PartName = ModelName.substring(0, ModelName.length()-4) + ".prt";
ModelDescriptor descriptor = pfcModel.ModelDescriptor_CreateFromFileName(PartName);
com.ptc.pfc.pfcWindow.Window window = MySession.OpenFile(descriptor);
window.Activate();
CreateDTIF(window.GetModel(), pfcGlobal.GetProESession());
} catch (Exception exp) {
JFrame jFrame = new JFrame();
jFrame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(jFrame, exp.getMessage() + "\n" + exp.toString() + "\n" + "Exception Occured - TIFF 1");
}
try {
String PartName = ModelName.substring(0, ModelName.length()-4) + ".asm";
ModelDescriptor descriptor = pfcModel.ModelDescriptor_CreateFromFileName(PartName);
com.ptc.pfc.pfcWindow.Window window = MySession.OpenFile(descriptor);
window.Activate();
CreateDTIF(window.GetModel(), pfcGlobal.GetProESession());
} catch (Exception exp) {
JFrame jFrame = new JFrame();
jFrame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(jFrame, exp.getMessage() + "\n" + exp.toString() + "\n" + "Exception Occured - TIFF 2");
}
} catch (Exception exp) {
JFrame jFrame = new JFrame();
jFrame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(jFrame, exp.getMessage() + "\n" + exp.toString() + "\n" + "Exception Occured - TIFF 3");
}
}
This opens the part, but not export the tiff file.
I think it have some do with the call of "CreateDTIF(window.GetModel(), pfcGlobal.GetProESession());" and using the right session and/or model.
Allan