Add leading zeros to title block

Add leading zeros to title block

ludmylla.camielli
Participant Participant
2,155 Views
11 Replies
Message 1 of 12

Add leading zeros to title block

ludmylla.camielli
Participant
Participant

Hi guys,

 

I need to fill my drawing's title block with the following, which will be the document number:

 

XXXX.XXX.XXX.<Number of Sheets><Sheet Number>

 

However, both numbers must have a leading zero (for example 0501, meaning 5 sheets and I'm currently looking at sheet 1).

 

I have spent a couple of hours looking for any solution to this and ended making the following iLogic code, which I expected to be useful somehow. But I have no idea how to sync this with my document number. Is this the best way to proceed? Can anyone help?

 

Dim oSheet As Sheet
Dim SheetNumber As Double

For Each oSheet In ThisApplication.ActiveDocument.Sheets
SheetNumber  = Mid(oSheet.Name, InStr(1, oSheet.Name, ":") + 1)
MessageBox.Show(Microsoft.VisualBasic.Strings.Format(SheetNumber,"0#"), oSheet.Name)
Next

 

0 Likes
Accepted solutions (2)
2,156 Views
11 Replies
Replies (11)
Message 2 of 12

mcgyvr
Consultant
Consultant

Will you have more than 9 sheets ever?

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 3 of 12

ludmylla.camielli
Participant
Participant

Unfortunately yes... Actually I already have 27 sheets. I thought of putting a prompted zero manually at the first 9 sheets and create 2 title blocks, but, it didn't "feel right", if I move a sheet to the top I will have a problem. Is there any way to use this piece of iLogic code to modify the Title Block?

0 Likes
Message 4 of 12

mcgyvr
Consultant
Consultant

@ludmylla.camielli  Well.. There may be a more graceful way but this gets the job done.. 

'Get Total Number of Sheets
SheetCount = ThisApplication.ActiveDocument.Sheets.Count

'Append a leading zero if less than 10
If SheetCount < 10 Then
	SheetCo = "0" & SheetCount
Else 
	SheetCo = SheetCount
End If

'Loop through each sheet and grab the sheet number from the name
For Each Sheet In ThisApplication.ActiveDocument.Sheets
SheetNumber = Mid(Sheet.Name, InStr(1, Sheet.Name, ":") + 1)

'Append a leading zero if less than 10
If SheetNumber <10 Then 
SheetNo = "0" & SheetNumber
Else
	SheetNo = SheetNumber
End If

MessageBox.Show(SheetCo & SheetNo, "Sheet descriptor")

Next

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 5 of 12

JhoelForshav
Mentor
Mentor

Hi @ludmylla.camielli 

I think you're on the right path with the string formatting. You could format an integer to a string of two digits with ToString function.

This will give the number of sheets and sheetnumber for each sheet as a string of with the format you requested:

 

Dim oSheets As Sheets = ThisDrawing.Document.Sheets
For Each oSheet As Sheet In oSheets
	oSheetNumber = CInt(oSheet.Name.Split(":")(1)).ToString("00")
	MsgBox(oSheets.Count.ToString("00") & oSheetNumber)
Next

 

Message 6 of 12

ludmylla.camielli
Participant
Participant

Hello @mcgyvr and @JhoelForshav thank you for your kind responses!

 

Both are valid solutions to format all sheet numbers the correct way! Actually, I got there too (formatting the number with a leading zero on iLogic).

However, I wonder if there is a way to merge this iLogic with the Title Block somehow, so that all sheets are numbered correctly. That's the step I'm stuck at.

 

Any thoughts on this?

 

 

0 Likes
Message 7 of 12

JhoelForshav
Mentor
Mentor
Accepted solution

@ludmylla.camielli 

I think i understand now 🙂

You'll need to modify your title block (or create a new one) to contain a promped entry.

Add the textbox in position where you want this string written and select that it should be a Prompted entry.

In this example i call it <CustomSheetNumber>

customsheetnumber.PNG

Then of course make sure this is the title block you use in your drawing template.

Running this rule will then set your formatted string to that textbox for each sheet

Dim oSheets As Sheets = ThisDrawing.Document.Sheets
For Each oSheet As Sheet In oSheets
	oSheetNumber = CInt(oSheet.Name.Split(":")(1)).ToString("00")
	Dim oTB As TitleBlock = oSheet.TitleBlock
	For Each oTextBox As Inventor.TextBox In oTB.Definition.Sketch.TextBoxes
		If oTextBox.Text = "<CustomSheetNumber>"
			oTB.SetPromptResultText(oTextBox, (oSheets.Count.ToString("00") & oSheetNumber))
			Exit For
		End If
	Next
Next

titleblock.PNG

Message 8 of 12

ludmylla.camielli
Participant
Participant

Worked like a charm! Great solution, you are awesome!!!

 

 

0 Likes
Message 9 of 12

pmaxwellNKJEX
Enthusiast
Enthusiast
Accepted solution

Thanks for this awesome work.

Thought I would add a small touch to it.

 

I've adjusted this a smidge so you can have varying start number so you can work sequentially with a drawing register.

I made SheetStartNum as a a user parameter and updatable by a field in a form.

 

 

Dim oSheets As Sheets = ThisDrawing.Document.Sheets
For Each oSheet As Sheet In oSheets
	oSheetNumber = CInt(oSheet.Name.Split(":")(1)+SheetStartNum-1).ToString("0000")
	
	Dim oTB As TitleBlock = oSheet.TitleBlock
	For Each oTextBox As Inventor.TextBox In oTB.Definition.Sketch.TextBoxes
		If oTextBox.Text = "<CustomSheetNumber>"
			oTB.SetPromptResultText(oTextBox, (oSheetNumber))
			Exit For
		End If
	Next
Next

 

Message 10 of 12

AJR1977
Contributor
Contributor

Looks like I need to create a custom iproperty for this to work, but then can I make it not editable in the "Edit Property Fields" so a user doesn't overwrite the automatically generated information?

0 Likes
Message 11 of 12

pmaxwellNKJEX
Enthusiast
Enthusiast

Further development, I need to set "oTB.SetPropmptResultText(oTextBox, (oSheetNumber))" to a custom iProperty so I can call it up as a reference in a view label.

I've tried a couple of things but I can only seem to call up the most recent computation (Eg. the last page number.)

 

Is it even possible to set a custom iProperty in this manner?

 

My next thought is to change my approach to drawing numbering and naming and shift the "drawing number" to be the sheetname instead.

0 Likes
Message 12 of 12

WCrihfield
Mentor
Mentor

Hi @pmaxwellNKJEX.  The quoted line of code you just posted is specifically for filling in a value for a 'Prompted Entry', so you could only paste the 'static value' of a custom iProperty as its value, but could not make it a 'live link' to that custom iProperty.  If you want it to become a live link to that custom iProperty, you will likely have to replace the contents of the TextBox.FormattedText, which is what the 'Format Text' dialog does, but what you see in that dialog is only the 'placeholders' for the data that you want, which is what you would see as the value of the TextBox.Text property value.

See:  XML Tags for FormattedText 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes