Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Have the sheet name automatically generate in Title block

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
brandon.lee97
713 Views, 7 Replies

Have the sheet name automatically generate in Title block

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. 

7 REPLIES 7
Message 2 of 8
JelteDeJong
in reply to: brandon.lee97

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 8
brandon.lee97
in reply to: JelteDeJong

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

 

brandonlee97_0-1637971104059.png

 

Message 4 of 8
JelteDeJong
in reply to: brandon.lee97

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 8
brandon.lee97
in reply to: JelteDeJong

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. 

Message 6 of 8
JelteDeJong
in reply to: brandon.lee97

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 8
brandon.lee97
in reply to: JelteDeJong

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

Message 8 of 8
j.oudalstoel
in reply to: JelteDeJong

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. 

 



Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report