06-21-2023
10:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-21-2023
10:37 AM
Hi @BK-MTFNE
I think this issue is you do not have a view on the drawing, so the model can not be found.
Here's an update that sets the default TB when no model is found.
(Note that this version is using the model that is the first referenced model in the drawing, which could cause issues if sheet1 is a part, and sheet2 is an assembly.)
' Define the title block names
Dim titleBlockIPT As String = "Production Drawing Title Block"
Dim titleBlockIAM As String = "Assembly Drawing Title Block"
Dim defaultTitleBlock As String = "DefaultTitleBlock"
Dim drawingViewExtension As String
titleBlockName = defaultTitleBlock
Dim modelDoc = ThisDrawing.ModelDocument
If not modelDoc Is Nothing Then
drawingViewExtension = System.IO.Path.GetExtension(modelDoc.FullFileName).ToLower()
End If
Select Case drawingViewExtension
Case ".ipt"
titleBlockName = titleBlockIPT
Case ".iam"
titleBlockName = titleBlockIAM
End Select
' Set the title block for the active sheet
ActiveSheet.TitleBlock = titleBlockName
And here is an alternate, that sets the TB per sheet by looking at the first view on the sheet, which is more in line with your original example:
' Define the title block names
Dim titleBlockIPT As String = "Production Drawing Title Block"
Dim titleBlockIAM As String = "Assembly Drawing Title Block"
Dim defaultTitleBlock As String = "DefaultTitleBlock"
Dim drawingViewExtension As String
Dim drawingView As DrawingView
titleBlockName = defaultTitleBlock
oViewCount = ThisDoc.Document.ActiveSheet.DrawingViews.count
If oViewCount > 0 Then
drawingView = ThisDoc.Document.ActiveSheet.DrawingViews.Item(1)
modelDoc = ActiveSheet.View(drawingView.Name).ModelDocument
If Not modelDoc Is Nothing Then
drawingViewExtension = System.IO.Path.GetExtension(modelDoc.FullFileName).ToLower()
End If
End If
Select Case drawingViewExtension
Case ".ipt"
titleBlockName = titleBlockIPT
Case ".iam"
titleBlockName = titleBlockIAM
End Select
' Set the title block for the active sheet
ActiveSheet.TitleBlock = titleBlockName
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com