Have the sheet name automatically generate in Title block

Have the sheet name automatically generate in Title block

BrandonLee_Innovex
Contributor Contributor
1,169 Views
8 Replies
Message 1 of 9

Have the sheet name automatically generate in Title block

BrandonLee_Innovex
Contributor
Contributor

I am trying to have my title block sheet name automatically populated once the sheet name has been set. 

 

For example, the image i have attached shows the sheet names we type in, 

but our current process requires us to type in the sheet name multiple times to appear both in the sidebar shown as well as the title block.

 

I am wondering if there is a way to make the title block auto-populate once the sheet name has been filled out in the sidebar. 

0 Likes
Accepted solutions (1)
1,170 Views
8 Replies
Replies (8)
Message 2 of 9

JelteDeJong
Mentor
Mentor

you can try this.

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim titleBlock As TitleBlock = sheet.TitleBlock

Dim textBox As Inventor.TextBox = titleBlock.Definition.Sketch.TextBoxes.
        Cast(Of Inventor.TextBox).
        Where(Function(tb) tb.FormattedText.Contains("<Prompt")).
        Where(Function(tb) tb.FormattedText.Contains("SHEET DESCRIPTION")).
        FirstOrDefault()
If (textBox Is Nothing) Then Throw New Exception("Promted entry not found.")
titleBlock.SetPromptResultText(textBox, sheet.Name)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 9

BrandonLee_Innovex
Contributor
Contributor

Is there a way to update the code to remove the :1, :2 at the end 

 

brandonlee97_0-1637971104059.png

 

Message 4 of 9

JelteDeJong
Mentor
Mentor

here is an updated rule:

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim titleBlock As TitleBlock = sheet.TitleBlock

Dim textBox As Inventor.TextBox = titleBlock.Definition.Sketch.TextBoxes.
        Cast(Of Inventor.TextBox).
        Where(Function(tb) tb.FormattedText.Contains("<Prompt")).
        Where(Function(tb) tb.FormattedText.Contains("SHEET DESCRIPTION")).
        FirstOrDefault()
If (textBox Is Nothing) Then Throw New Exception("Promted entry not found.")

Dim sheetDescription = sheet.Name
Dim puntPlace = InStr(sheetDescription, ":") - 1
sheetDescription = sheetDescription.Substring(0, puntPlace)
titleBlock.SetPromptResultText(textBox, sheetDescription)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 9

BrandonLee_Innovex
Contributor
Contributor

Thank you for the help on this, one last thing, the code has to be run on each sheet. Is there a way to have to automatically run on each sheet in the drawing. 

0 Likes
Message 6 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

try this:

Dim doc As DrawingDocument = ThisDoc.Document
For Each sheet As Sheet In doc.Sheets
    Dim titleBlock As TitleBlock = Sheet.TitleBlock

    Dim textBox As Inventor.TextBox = titleBlock.Definition.Sketch.TextBoxes.
	    Cast(Of Inventor.TextBox).
	    Where(Function(tb) tb.FormattedText.Contains("<Prompt")).
	    Where(Function(tb) tb.FormattedText.Contains("SHEET DESCRIPTION")).
	    FirstOrDefault()
    If (textBox Is Nothing) Then 
		MsgBox("Promted entry not found on sheet: " & Sheet.Name)
		continue for
	End If

    Dim sheetDescription = Sheet.Name
    Dim puntPlace = InStr(sheetDescription, ":") - 1
    sheetDescription = sheetDescription.Substring(0, puntPlace)
    titleBlock.SetPromptResultText(textBox, sheetDescription)
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 7 of 9

BrandonLee_Innovex
Contributor
Contributor

Instead of having the code reference a prompted entry. How would you adjust this to referencing iproperty vaule "SHEET DESCRIPTION" 

0 Likes
Message 8 of 9

j.oudalstoel
Contributor
Contributor

JelteDeJong

 

Just wanted to say thank you for providing this code. It solved an issue I was having with getting my title block to reflect the sheet name. 

 



0 Likes
Message 9 of 9

shaight
Participant
Participant

Thank you for providing this @JelteDeJong! I was trying to have AI write me something similar but wasn't getting the results I wanted. After using the code you provided, I was getting an error because of some sheets that we have as Excluded from Count. I ran your code through an AI chat and got the below to adjust that for me. If anyone else uses Exclude from Count on certain sheets, feel free to use this. (our prompted entry is SHEET TITLE, instead of SHEET DESCRIPTION, so that is changed in the below).

shaight_0-1759509937503.png

Exclude from Count error:

Length cannot be less than zero.
Parameter name: length

 

Dim doc As DrawingDocument = ThisDoc.Document
For Each sheet As Sheet In doc.Sheets
    Dim titleBlock As TitleBlock = Sheet.TitleBlock

    ' Find the textbox within the title block's sketch that contains the prompt markers
    Dim textBox As Inventor.TextBox = titleBlock.Definition.Sketch.TextBoxes _
        .Cast(Of Inventor.TextBox)() _
        .Where(Function(tb) tb.FormattedText.Contains("<Prompt") AndAlso tb.FormattedText.Contains("SHEET TITLE")) _
        .FirstOrDefault()

    If (textBox Is Nothing) Then
        MsgBox("Prompted entry not found on sheet: " & Sheet.Name)
        Continue For
    End If

    ' Extract the sheet description; here, trimming after colon
    Dim sheetDescription As String = Sheet.Name
    Dim puntPlace As Integer = InStr(sheetDescription, ":")
    If puntPlace > 0 Then
        sheetDescription = sheetDescription.Substring(0, puntPlace - 1)
    End If

    ' Set the prompt result text in the title block
    titleBlock.SetPromptResultText(textBox, sheetDescription)
Next

 

0 Likes