Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic that selects which title block to use based on file extension of base view for that sheet.

BK-MTFNE
Advocate

iLogic that selects which title block to use based on file extension of base view for that sheet.

BK-MTFNE
Advocate
Advocate

So I have been working on my drawing template and so far I have been able to set up the sheet formats correctly and a few other things but my issue is we have 2 different title blocks dependant on what the drawing is for. This is easily determined by the file type of the object in that sheets drawing view. Basically .ipt gets one title block and .iam gets the other type. Below is the iLogic I have created so far however I am getting the error code as follows.

 

Error on Line 26 : Property 'TitleBlock' is 'ReadOnly'.

 

If I erase the code I can easily double click the titleblock and manually add it but I would like this to be automated.

 

 

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

' Get the file extension of the active drawing view
Dim drawingView As DrawingView = oDoc.ActiveSheet.ActiveView
Dim drawingViewExtension As String = System.IO.Path.GetExtension(drawingView.ReferencedFileDescriptor.FullFileName).ToLower()

' 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"


' Assign the appropriate title block based on the file extension
Dim titleBlockName As String = defaultTitleBlock ' Default title block

Select Case drawingViewExtension
    Case ".ipt"
        titleBlockName = titleBlockIPT
    Case ".iam"
        titleBlockName = titleBlockIAM
   
End Select

' Set the title block for the active sheet
oDoc.ActiveSheet.TitleBlock = titleBlockName

 

0 Likes
Reply
Accepted solutions (3)
625 Views
8 Replies
Replies (8)

Curtis_Waguespack
Consultant
Consultant

Hi @BK-MTFNE,

 

Give this a try.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 


Dim modelDoc = ThisDrawing.ModelDocument
Dim drawingViewExtension As String = System.IO.Path.GetExtension(modelDoc.FullFileName).ToLower()

' 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"

' Assign the appropriate title block based on the file extension
Dim titleBlockName As String = defaultTitleBlock ' Default title block

Select Case drawingViewExtension
    Case ".ipt"
        titleBlockName = titleBlockIPT
    Case ".iam"
        titleBlockName = titleBlockIAM   
End Select

' Set the title block for the active sheet
ActiveSheet.TitleBlock = titleBlockName

 

0 Likes

BK-MTFNE
Advocate
Advocate

Thank you @Curtis_Waguespack for getting back so quickly. Unfotunately I am getting the following error on line 2

 

Object reference not set to an instance of an object.

Curtis_Waguespack
Consultant
Consultant
Accepted solution

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

0 Likes

BK-MTFNE
Advocate
Advocate

You're correct the second one works perfectly for what I am doing.

 

Out of curiosity do you know a way to trigger this iLogic any time a new sheet is added?

0 Likes

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@BK-MTFNE wrote:

Out of curiosity do you know a way to trigger this iLogic any time a new sheet is added?


Unfortunately there is not an event trigger for "new sheet" in iLogic. 

 

Probably the best you can do is set the rule to run on the "before save" event, and then as you add sheets, simply click the save button to update the title block.

BK-MTFNE
Advocate
Advocate

So the second option worked great, unfotunately now that I have multiple sheets I cant get it to cycle through all the sheets and add titleblocks to them all. This seems like it should be easy to go through each sheet but it just keeps crashing.

0 Likes

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @BK-MTFNE,

 

Give this a try.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

' 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

oCurrentSheet = ThisDoc.Document.ActiveSheet

For Each oSheet In ThisDoc.Document.Sheets

	oSheet.activate

	drawingViewExtension = ""

	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
		Case Else
			titleBlockName = defaultTitleBlock
	End Select

	' Set the title block for the active sheet
	ActiveSheet.TitleBlock = titleBlockName
Next

oCurrentSheet.activate
0 Likes

BK-MTFNE
Advocate
Advocate

Perfect, it worked great. Looks like I was making a mistake in this line...

 

drawingViewExtension = ""