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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Translate the entire conversation x

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

SC_TK
12-Amethyst

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

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
ACCEPTED SOLUTION

Accepted Solutions
RPN
17-Peridot
17-Peridot
(To:SC_TK)

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😉

View solution in original post

5 REPLIES 5
SC_TK
12-Amethyst
(To:SC_TK)

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 I
(To:SC_TK)

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.

RPN
17-Peridot
17-Peridot
(To:SC_TK)

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😉

SC_TK
12-Amethyst
(To:RPN)

Thanks,  That is the right approach. VB help file doesn't really mention anything about "ipfctable.CheckIfIsFromFormat". The code goes through all the tables. If the table belongs to format then delete it. 

In case someone needs the code, I list it here.

    Sub ReplaceDrawingFormat(ByVal asyncConnection As IpfcAsyncConnection)
        Dim session As IpfcBaseSession = asyncConnection.Session
        session.CurrentWindow.Activate()
        Dim model As IpfcModel = session.CurrentModel
        Dim currentDrawing = CType(model, IpfcDrawing)
        Dim CurrentShtOwner As IpfcSheetOwner
        Dim CurrentFormat As IpfcDrawingFormat
        Dim NewFormat As IpfcDrawingFormat

        'determine Sheetsize
        CurrentShtOwner = CType(currentDrawing, IpfcSheetOwner)
        CurrentFormat = CurrentShtOwner.GetSheetFormat(1)
        Dim NewFormatName As String
        Dim CurrentShtInfo As IpfcSheetInfo = CurrentShtOwner.GetSheetInfo(1)
        If CurrentShtInfo.SheetSize = EpfcPlotPaperSize.EpfcCSIZEPLOT Then
            NewFormatName = "New-c.frm"
        Else
            NewFormatName = "NEW-D.frm"
        End If

        Dim frmDescr As IpfcModelDescriptor
        frmDescr = (New CCpfcModelDescriptor).CreateFromFileName(NewFormatName)
        NewFormat = session.RetrieveModel(frmDescr)

        Dim sheets As Integer
        Dim i As Integer
        Dim j As Integer

        Dim tableOwner As IpfcTableOwner = CType(currentDrawing, IpfcTableOwner)
        Dim tables As IpfcTables = tableOwner.ListTables
        Dim table As IpfcTable
        For i = 0 To tables.Count - 1
            table = tables.Item(i)
            If table.CheckIfIsFromFormat(Nothing) Then
                tableOwner.DeleteTable(table, False)
            End If
        Next

        sheets = CurrentShtOwner.NumberOfSheets
        Console.WriteLine(sheets)
        For i = 1 To sheets
            'remove existing format tables
            CurrentShtOwner.SetSheetFormat(i, NewFormat, Nothing, Nothing)
        Next

    End Sub

 

RPN
17-Peridot
17-Peridot
(To:SC_TK)

Again, you have to take care about segmented Tables😉

Announcements



Top Tags