AnsweredAssumed Answered

Replace Title Block

Question asked by Steve Anderson on Dec 4, 2019
Latest reply on Dec 5, 2019 by Steve Anderson



I have asked a similar question in the past.  What I have at the moment is two functions, one to update the title block and one to update the template.


I have been told by our var that in order for this to work, I have to give the title block a different name than what currently exists, otherwise it replaces the title block with a blank sheet.  This is what I am seeing.


My fundamental disagreement with this is that at any time, we can change the title block!  Who wants to manage naming conventions?  Who will actually do that.  Plus, since this information is also controlled in document management, why would this happen?


The logic below, I thought worked well in 2017.  I am introducing it to a new program to be more batch oriented.  Again, the whole title block just goes away!


Private Sub UpdateTitleBlock(ByVal _swDraw As ModelDoc2, ByVal _ps As String, ByVal _swSheet As Sheet)
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(_swSheet), GetScale2(_swSheet), sTemplate, _swSheet)
UpdateTemplate(_swDraw, _ps, GetScale1(_swSheet), GetScale2(_swSheet), sFormat, _swSheet)

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, ByVal _swSheet As Sheet)
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 = swDwgTemplates_e.swDwgTemplateCustom

MessageBox.Show("_ps: " & _ps)

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
MessageBox.Show("Sheet: " & _swSheet.GetName.ToString & ", Papersize: " & PaperSize.ToString & ", TemplateIn " & TemplateIn.ToString & ", dScale1: " & _dScale1.ToString & ", dScale2: " & _dScale2.ToString & ", sformatName: " & _sFormatName)
bRet = _swDraw.SetupSheet4(_swSheet.GetName.ToString, PaperSize, TemplateIn, _dScale1, _dScale2, False, _sFormatName, 0.0#, 0.0#, "")

' _swDraw.Rebuild(c)
' _swDraw.Rebuild(swRebuildOptions_e.swRebuildAll)

End If


' Return to Sheet1
bSht = _swDraw.ActivateSheet(swSheetNames(0))
_swSheet = _swDraw.GetCurrentSheet

End Sub


It would seem a more correct approach would be to somehow delete or rename the title block and respective format before replacing it.


Thanks for the help!