Skip to main content
12-Amethyst
May 29, 2023
Solved

Replace format with vartiable format using JLink

  • May 29, 2023
  • 1 reply
  • 2518 views
I am using Creo Parametric Release 7.0 and Datecode7.0.4.0

I need to replace the drawing format of sheet 2 of my drawing with Custom Size, 1x1 mm, format. Using JLink
    Best answer by rghadge

    Use below available J-Link functions (OTK Java):

    1. wfcModel.FormatSizeData.GetWidth()
    2. wfcModel.FormatSizeData.SetWidth()
    3. wfcModel.FormatSizeData.GetHeight()
    4. wfcModel.FormatSizeData.SetHeight()

    Note: Above functions will need OTK Java licenses to use in Creo Parametric. For J-Link users, macros can be used as a workaround.

    1 reply

    17-Peridot
    May 31, 2023

    @dgarcia,

    1. Use J-Link function pfcSheet.SheetOwner.SetCurrentSheetNumber() to set current drawing sheet.
    2. Use J-Link function pfcSheet.SheetOwner.SetSheetFormat() to set new or replace existing drawing format with new format.
    dgarcia12-AmethystAuthor
    12-Amethyst
    June 1, 2023

    Thanks for the help, but I'm stuck with the function:

    voidSetSheetFormat(int SheetNumber, DrawingFormat Format, /*optional*/ Integer FormatSheetNumber, /*optional*/ Model DrawingModel)

    How do I define parameter Format ? I need a variable sheet, and there is no format defined for that. And null does not work

    17-Peridot
    June 6, 2023

    @dgarcia,

     

    Below sample code changes the format of sheet# 1 in session and uses an existing .frm stored in the working directory
    ModelDescriptor desc = null;
    session.GetCurrentWindow().Activate();
    desc = pfcModel.ModelDescriptor_CreateFromFileName("a0_iso.frm");
    desc.SetPath (""); //frm file is stored in the working directory, set your own format folder path here
    DrawingFormat format = (DrawingFormat) session.RetrieveModelWithOpts(desc, pfcSession.RetrieveModelOptions_Create());
    cur_drw.SetSheetFormat(1, format, null, null); //applies to the first sheet

    Note:
    The Method SetSheetFormat() is designed only to insert a new format sheet in a drawing sheet This method is not designed to replace or remove existing drawing tables that are copied in to drawing from previous format.
    Users should identify and remove the old drawing tables using pfcTable.CheckIfIsFromFormat() and DeleteTable() Example Code Snippet: Tables tables = drw.ListTables(); System.out.println("tables info" + tables.toString()); for (int i = 0; i < tables.getarraysize(); i++) { Table table = tables.get(i); System.out.println("table" + table); if (table.CheckIfIsFromFormat(drwSheetNum) == true) { drw.DeleteTable(table, Boolean.FALSE); } }