cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Export a Tiff file

akok
12-Amethyst

Export a Tiff file

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

1 REPLY 1
akok
12-Amethyst
(To:akok)

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

Announcements


Top Tags