AnsweredAssumed Answered

Update Title Block with API

Question asked by Steve Anderson on Aug 5, 2019
Latest reply on Aug 5, 2019 by Steve Anderson

Update Templates (formats and titleblocks).  This code used to work great in 2017, but in 2017 it just erases the title block altogether.


Someone suggested the new template could not have the same name as the old one.  I did rename it, which made absolutely no difference.


    Private Sub UpdateTitleBlock(ByVal swDraw As ModelDoc2, ByVal _PS As String)

        Dim templatename As String = _PS & " WMI DWG TMPLT.DRWDOT"

        Dim formatname As String = _PS & ".slddrt"


        Dim sTemplate As String = "C:\Sackett-Waconia\Master Documents\SOLIDWORKS TEMPLATES\NewTitleBlocks\" & templatename

        Dim sFormat As String = "C:\Sackett-Waconia\Master Documents\SOLIDWORKS TEMPLATES\NewTitleBlocks\" & formatname


        UpdateTemplate(swDraw, _PS, GetScale1(swDraw), GetScale2(swDraw), sTemplate)

        UpdateTemplate(swDraw, _PS, GetScale1(swDraw), GetScale2(swDraw), sFormat)


    End Sub


    Private Sub UpdateTemplate(ByVal swDraw As ModelDoc2, ByVal _PS As String, ByVal dScale1 As Double, ByVal dScale2 As Double, ByVal sFormatName As String)

        Dim bRet As Boolean ' defines the value to change the drawing format

        Dim swSheetNames As Object = swDraw.GetSheetNames

        Dim bSht As Boolean ' defines sheet


        Dim PaperSize As Integer

        Dim TemplateIn As Integer


        Select Case _PS

            Case "A"

                PaperSize = swDwgPaperSizes_e.swDwgPaperAsize

                TemplateIn = swDwgTemplates_e.swDwgTemplateAsize


            Case "B"

                PaperSize = swDwgPaperSizes_e.swDwgPaperBsize

                TemplateIn = swDwgTemplates_e.swDwgTemplateBsize


            Case "C"

                PaperSize = swDwgPaperSizes_e.swDwgPaperCsize

                TemplateIn = swDwgTemplates_e.swDwgTemplateCsize


            Case "D"

                PaperSize = swDwgPaperSizes_e.swDwgPaperDsize

                TemplateIn = swDwgTemplates_e.swDwgTemplateDsize


        End Select


        For c As Integer = 0 To UBound(swSheetNames)

            bSht = swDraw.ActivateSheet(swSheetNames(c))

            SWSHEET = swDraw.GetCurrentSheet


            If (SWSHEET.IsLoaded) Then

                bRet = swDraw.SetupSheet4(SWSHEET.GetName.ToString, PaperSize, TemplateIn, dScale1, dScale2, False, sFormatName, 0.0#, 0.0#, "")






            End If




        ' Return to Sheet1

        bSht = swDraw.ActivateSheet(swSheetNames(0))

        SWSHEET = swDraw.GetCurrentSheet


    End Sub


Thank you!