Thank you Curtis, smart to think of that.
I've come across it before with a Title Block replaced and seen it pass by but can't get my fingers behind it.
The code still keeps stumbling at that 'CopyTo'.
See the whole code where you can see what I'm bumbling around.
Those Prompted Entries do come across well with updating the title block.
I have also tried the same kind of technique with the border, but at a certain point my knowledge falls short.
I still don't understand why it is so difficult with the border.
Btw, maybe it says something, I haven't seen that message at the end of the sub 'InsertBorder' yet, somehow it doesn't get there.
Sub Main
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
' Point to template to get title block from
ThisDrawing.ResourceFileName = "C:\Workingfolder\CAD Settings\Inventor\Templates\HML Drawing.dwg"
Dim oCurrentNumber As Sheet
oCurrentNumber = oDoc.ActiveSheet
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
'----------------------------------------------------------------------------------------------------
' Undo Wrapper
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "Do your thing...")
'----------------------------------------------------------------------------------------------------
' Uncheck Checked Dates
iProperties.Value("Status", "Checked Date") = Nothing
iProperties.Value("Status", "Checked By") = Nothing
Dim valQTY As String = ""
Dim valFINISHING As String = ""
For Each oSheet In oDoc.Sheets
oSheet.Activate
If Not ActiveSheet.TitleBlock = "" Then
'Get the Prompted Entries, QTY and FINISH
' Let op, als we zoeken op bv 'QTY' komt dat twee keer voor, onduidelijk wanneer het de waarde betreft of niet, vandaar de 'If <> "QTY" then...' enz.
' Dim valQTY As String = ""
' Dim valFINISHING As String = ""
Dim oPromptEntry
Dim actSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
'For Each oSheet In oDoc.Sheets
ActiveSheet=ThisDrawing.Sheet(oSheet.Name)
If oSheet.TitleBlock Is Nothing Then Exit Sub
oTitleBlock=oSheet.TitleBlock
oTextBoxes=oTitleBlock.Definition.Sketch.TextBoxes
For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
'On Error Resume Next
If oTextBox.Text <>"" Then
Select oTextBox.Text
Case "QTY":
'oPromptEntry = ThisPurposeForIssue
If oTitleBlock.GetResultText(oTextBox) <> "QTY" Then
'MessageBox.Show(oTitleBlock.GetResultText(oTextBox), "QTY")
valQTY = oTitleBlock.GetResultText(oTextBox)
End If
Case "FINISHING":
'oPromptEntry = ThisPurposeForIssue
If oTitleBlock.GetResultText(oTextBox) <> "FINISHING" Then
'MessageBox.Show(oTitleBlock.GetResultText(oTextBox), "FINISHING")
valFINISHING = oTitleBlock.GetResultText(oTextBox)
End If
End Select
End If
Next
'Next
' Rename TitleBlock so it can be replaced completely, later unused TitleBlocks are removed
'On Error Resume Next
For Each oTitleBlock In oDoc.TitleBlockDefinitions
If oTitleBlock.Name = "HML" Then
oTitleBlock.Name = "HML_Old"
End If
Next
' Place 'New' Titleblock
' There Is a different Call For title blocks which contain prompted entries
'ActiveSheet.SetTitleBlock("HML", valQTY, "Kijk maar! Doe maar wat!")
ActiveSheet.SetTitleBlock("HML", valQTY, valFINISHING)
'ActiveSheet.SetTitleBlock("HML", "-", "See Paint Specification List") ' "QTY" "FINISHING"
'ActiveSheet.SetTitleBlock("HML", "promptedEntry1", "promptedEntry2")
'ActiveSheet.TitleBlock = "HML"
' ' Try to set the Border
' 'On Error Resume Next
' oBorder=oSheet.Border
' For Each oBorder In oDoc.BorderDefinitions
' If oBorder.Name = "Default Border" Or oBorder.Name = "HML Border" Then
' oBorder.Name = "HML_Border_Old"
' End If
' Next
' Try
' oSheet.Border.Delete
' Catch
' End Try
' Try
' ActiveSheet.SetBorder("HML_Border", "", "")
' Catch
' End Try
End If
Next
' Delete unused title block(s) from Drawing Recources
'On Error Resume Next '(The used Title Block can not be deleted)
For Each oTitleBlock In oDoc.TitleBlockDefinitions
Try
oTitleBlock.delete()
Catch
End Try
Next
''Delete unused Borders from Drawing Recources
''On Error Resume Next '(The used Border can not be deleted)
'Dim oBorder As Border
'For Each oBorder In oDoc.BorderDefinitions
' Try
' MessageBox.Show("oborder.name: " & oBorder.Name)
' oBorder.Delete()
' Catch
' End Try
'Next
'Dim oObj As ObjectCollection(Of String)
'oObj.Add(valQTY.ToString)
'oObj.Add(valFINISHING.ToString)
'Dim sPromptStrings(2) As String
' sPromptStrings(1) = valQTY
' sPromptStrings(2) = valFINISHING
'oSheet.AddBorder("Default Border",sPromptStrings)
' Dim oNewBorderDef As BorderDefinition
' oNewBorderDef = oDoc.BorderDefinitions.Item(oOriginalBorderDefName)
' For Each oSheet In ThisApplication.ActiveDocument.Sheets
' If Not oSheet.Border Is Nothing Then
' oSheet.Border.Delete
' End If
' Next
' If Not oSheet.Border Is Nothing Then
' oOriginalBorderDefName = oSheet.Border.Definition.Name
' Logger.Info(oOriginalBorderDefName)
' End If
' For Each oSheet In oDoc.Sheets
' oSheet.AddBorder(oNewBorderDef)
' Next
Dim oBorder As Border = oSheet.Border
If Not oSheet.Border Is Nothing Then
oOriginalBorderDefName = oSheet.Border.Definition.Name
Logger.Info(oOriginalBorderDefName)
DeleteBorders()
'MessageBox.Show("Here...")
InsertBorder(oOriginalBorderDefName)
End If
' Set Date and Author
'oTime = Now.ToShortDateString
'iProperties.Value("Project", "Creation Date") = oTime
'iProperties.Value("Summary", "Author") = "CNo"
iLogicVb.UpdateWhenDone = True
'Back to current/active sheet
oCurrentNumber.Activate
'----------------------------------------------------------------------------------------------------
' Undo Wrapper
trans.End()
'----------------------------------------------------------------------------------------------------
' Copy Sketch Symbols from Drawing Template into this Drawing
Dim strDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim SourceFile As String = ThisDrawing.ResourceFileName '"D:\Local Server\Data\Autodesk Customization\Templates\IV2014Stamps.idw"
Dim strSourceIDW As DrawingDocument
strSourceIDW = ThisApplication.Documents.Open(SourceFile, False)
Dim strStampList As New List( Of String)
Dim symbolDef As SketchedSymbolDefinition
' Remove unused Sketch Symbols
For Each symbolDef In strDrawDoc.SketchedSymbolDefinitions
Try
symbolDef.Delete
Catch
'MessageBox.Show("Error deleting Sketched Symbol: " & symbolDef.Name, "InventorPLUS", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
Next
' Add Symbols to the List
For Each symbolDef In strSourceIDW.SketchedSymbolDefinitions
strStampList.Add(symbolDef.Name)
Next
' Sort List with Sketch Symbols
strStampList.Sort
'strSelectedStamp = InputListBox("Please select a stamp.", strStampList, strSelectedStamp, "Stamp Selection", "Available Stamps")
For Each symbolDef In strSourceIDW.SketchedSymbolDefinitions
' 'If (StrComp(symbolDef.Name, strSelectedStamp, vbTextCompare) = 0) Then
CopyFrom = symbolDef.CopyTo(strDrawDoc, True)
' 'If MsgBox("Would you like to place the stamp on the drawing?", MsgBoxStyle.YesNo, "Insert Stamp") = MsgBoxResult.Yes Then
' ' 'Insert stamp if required
' ' InsertSymbol(symbolDef.Name)
' 'End If
' 'End If
Next
'----------------------------------------------------------------------------------------------------
' Sort the Sketch Symbols
ThisApplication.ActiveDocument.BrowserPanes("Model").TopNode.BrowserNodes.Item("Drawing Resources").BrowserNodes.Item(4).DoSelect
Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager
Dim oControlDef1 As ControlDefinition
oControlDef1 = oCommandMgr.ControlDefinitions.Item("DrawingResourceSort")
oControlDef1.Execute
'----------------------------------------------------------------------------------------------------
strSourceIDW.Close()
End Sub
Sub DeleteBorders()
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
For Each oSheet In ThisApplication.ActiveDocument.Sheets
If Not oSheet.Border Is Nothing Then
oSheet.Border.Delete
End If
Next
End Sub
Sub InsertBorder(oOriginalBorderDefName As String)
MessageBox.Show("Here...")
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim borderDef As BorderDefinition
strBorderRequired = True
Dim strDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
SourceFile = "C:\Workingfolder\CAD Settings\Inventor\Templates\HML Drawing.dwg"
Dim strSourceIDW As DrawingDocument
strSourceIDW = ThisApplication.Documents.Open(SourceFile, True)
Logger.Info(strSourceIDW.FullFileName)
For Each borderDef In strSourceIDW.BorderDefinitions
If (StrComp(borderDef.Name, oOriginalBorderDefName, vbTextCompare) = 0) Then
CopyFrom = borderDef.CopyTo(strDrawDoc, True)
End If
Next
'MessageBox.Show("Here...")
strSourceIDW.Close()
Dim oNewBorderDef As BorderDefinition
oNewBorderDef = oDrawDoc.BorderDefinitions.Item(oOriginalBorderDefName)
' For Each oSheet In oDrawDoc.Sheets
' oSheet.AddBorder(oNewBorderDef)
' Next
' This border definition contains 2 prompted string inputs. An array
' must be input that contains the values for the prompted strings.
Dim sPromptStrings(0 To 1) As String
sPromptStrings(0) = "Hello."
sPromptStrings(1) = "World."
For Each oSheet In oDrawDoc.Sheets
oSheet.AddBorder(oNewBorderDef, sPromptStrings)
Next
MessageBox.Show("The border was changed", "Title")
End Sub