Skip to main content
12-Amethyst
March 22, 2025
Solved

VB API Replace sheet format - No option to delete the old one

  • March 22, 2025
  • 1 reply
  • 1190 views

Hi, 

 

We are changing our drawing format to change the layout.  Below is my VB code to set the drawing with a new format. The code only half worked. 

The new format could be applied, but the old format stayed.  I had been searching up and down and try to find if there was an option of "replace" but I couldn't find anything.  The online VB help about "IpfcDrawingFormat" has no help at all

Can anyone please help?

 Dim currentDrawing As IpfcDrawing = CType(session.CurrentModel, IpfcDrawing)
 'Replace format
 Dim NewFormatName As String = "new-d.frm"
 Dim frmDescr As IpfcModelDescriptor
 frmDescr = (New CCpfcModelDescriptor).CreateFromFileName(NewFormatName)
 Dim NewFormat As IpfcDrawingFormat
 NewFormat = session.RetrieveModel(frmDescr)

 Dim sheets As Integer
 Dim i As Integer
 Dim CurrentShtOwner As IpfcSheetOwner
 CurrentShtOwner = CType(currentDrawing, IpfcSheetOwner)

 sheets = CurrentShtOwner.NumberOfSheets
 For i = 1 To sheets
 CurrentShtOwner.SetSheetFormat(i, NewFormat, Nothing, Nothing)
 Next
Best answer by RPN

You must ask the table first 

 

extern ProError ProDwgtableIsFromFormat (
ProDwgtable *table,
ProBoolean *from_format);
/*
Purpose:
Determines whether the specified table is associated with
the format.

Input Arguments:
table - The drawing table

Output Arguments:
from_format - PRO_B_TRUE if the table is associated with the format;
PRO_B_FALSE if the table is not associated with the format.
Return Values:
PRO_TK_NO_ERROR - The function succeeded.
PRO_TK_GENERAL_ERROR - The function failed.
*/

Next you have to check the segment data, but this is a good start😉

1 reply

SC_TK12-AmethystAuthor
12-Amethyst
March 22, 2025

To make my question a bit clearer.

When manually replaces the sheet format, there was a pop up window to ask if all format tables should be removed. I want to use "Remove All" . But it seems there is no such option in VB.  So the old tables and new tables were overlapped.

SC_TK_0-1742651446657.png

 

KenFarley
21-Topaz II
March 22, 2025

I've not done any programming of this sort, but it seems that if you can access the tables associated with the format that is originally in place, you might have to parse through them, deleting them, and then replace the sheet format. Probably not as straightforward as desireable, but that's typical, isn't it?

Anyway, just a guess, but that's all I've got.