drawing parameter in to a title block

drawing parameter in to a title block

j.oudalstoel
Contributor Contributor
462 Views
3 Replies
Message 1 of 4

drawing parameter in to a title block

j.oudalstoel
Contributor
Contributor

Hi. 

 

I am trying to add a parameter (it could be a iProperty) in to my title block. The thing about it is that each page would get a different parameter. It is to give the sheet a name. I am doing it so that I can generate a sheet list and I can have the browser name and the sheet name to be the same.  

 

I believe I saw the solution in a post at one point in time, but I can't seem to find it again. 

 

Thank you all for helping. 

0 Likes
463 Views
3 Replies
Replies (3)
Message 2 of 4

Andrii_Humeniuk
Advisor
Advisor

Hi @j.oudalstoel . If I understood correctly, you want to write the name of the sheet in one of the TitleBlock parameters, but you did not write which parameter, so I chose PartNumber, if you need another parameter, change it in line 9. You can also read another example.

Sub main
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTM As TransactionManager = ThisApplication.TransactionManager
	Dim newTM As Transaction = oTM.StartTransaction(oDDoc, "ChangeTitleBlock")
	For Each oSheet As Sheet In oDDoc.Sheets
		Dim oSketch As DrawingSketch = oSheet.TitleBlock.Definition.Sketch
		oSheet.TitleBlock.Definition.Edit(oSketch)
		For Each oText As Inventor.TextBox In oSketch.TextBoxes
			If oText.Text = "<PART NUMBER>" Then
				oText.FormattedText = oSheet.Name
			End If
		Next
		oSheet.TitleBlock.Definition.ExitEdit(True)
	Next
	newTM.End()
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 4

j.oudalstoel
Contributor
Contributor

Hi Andrii

 

Thank you so much for your response to my question. Your other example lead me to asking the correct question.

 

Which lead me to this post in the forum. sheet name to title block

The code in this let's you put your sheet name in to a prompted entry on the title block. 

The only code modification I had to to was replace the prompted entry. 

I pasted the code below

 

The prompted entry this code is looking for is "SHEET DESCRIPTION" I replaced that with what I hade in my title block and the code worked perfectly. 

 

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

 

This solved my issue

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

This has been something that several people have wanted for quite some time now, so in the 2024 version of Inventor, the Sheet Name is actually available to choose within the Format Text dialog box now, so you would no longer need any code to keep this little detail correct anymore.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-B8571FFC-9F6C-4736-92BF-7F52B09841E5 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes