Auto Page Numbering (1, 1A, 1B...)

Auto Page Numbering (1, 1A, 1B...)

Anonymous
Not applicable
601 Views
2 Replies
Message 1 of 3

Auto Page Numbering (1, 1A, 1B...)

Anonymous
Not applicable

I'm trying to find a way to automate the numbering process. We number our pages currently as prompted entries and the order usually goes something like this: 

# = any number

Sheet 1 = #      (2)

Sheet 2 = #A   (2A)

Sheet 3 = #B   (2B)

Sheet 4 = #C   (2C)

 

The time consumption comes in when I have a drawing that goes up to letter N and I need to add a sheet in between say #C & #D....that means I need to update all sheets that follow. I'm not sure if there is a way to do this, but it's worth a shot!

 

Thank you in advance! 

 

I did post this into the inventor forums but was told I'd have better luck here, below is the link to the other forum.

https://forums.autodesk.com/t5/inventor-forum/auto-page-numbering-1-1a-1b/m-p/8850760#M748892

0 Likes
Accepted solutions (1)
602 Views
2 Replies
Replies (2)
Message 2 of 3

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Hoping that below iLogic code may be helpful.

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument 

num = InputBox("Prompt", "Title", "1")

Dim oSheet As Sheet 
oSheet = oDoc.Sheets.Item(1)
oSheet.Name = oSheet.Name + num

Dim a As Char = "A"

For i = 2 To oDoc.Sheets.Count 
	oSheet = oDoc.Sheets.Item(i)
	Call oSheet.Activate 
	oSheet.Name = oSheet.Name + num + a.ToString 
	MessageBox.Show(oSheet.Name + num + a.ToString, "Title")

	a = Chr(Asc(a) + 1)
Next

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

With help from the Autodesk community, I have found a solution to the posted problem.

I am posting the solution for anyone else that may need it.

1) Have your title block page number setup as a prompted entry

2) Create an external rule with the below code,

     NOTE: you must add your title block name to line 41.

Sub main ()
	Rename_SheetName ()
	Create_PageNo()
End Sub
	
Function Rename_SheetName
		Dim oDoc As DrawingDocument
	oDoc = ThisApplication.ActiveDocument
	Dim oSheet As Sheet
	oSheet = oDoc.ActiveSheet

	Number = InputBox("Input initial number", "Rename sheets", "1")
	Letter = "A"
	FirstSheet=True
	For Each oSheet In oDoc.Sheets
		
		'uncomment all lines below to make the first sheet not have a letter
		If FirstSheet = True
			oSheet.Name = Number
			FirstSheet = False
		Else 
		oSheet.Name=Number + Letter
		Letter = Chr(Asc(Letter) + 1)
		End If
	Next 

End Function

Function Create_PageNo
	Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
		

	' Set a reference to the drawing document.

	' This assumes a drawing document is active.

	' Obtain a reference to the desired border defintion.

	Dim oTitleBlockDef As TitleBlockDefinition

		oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("YOUR TITLE BLOCK NAME")

	Dim oSheet As Sheet
	Dim oSheets As Sheets = oDrawDoc.Sheets
	'oSheet = oDrawDoc.ActiveSheet
	For Each oSheet In oSheets
		
		' Check to see if the sheet already has a title block and delete it if it does.

		If Not oSheet.TitleBlock Is Nothing Then

		oSheet.TitleBlock.Delete()

		End If

		' This title block definition contains one prompted string input. An array

		' must be input that contains the strings for the prompted strings.

			positionOfDubbleDot = Strings.InStrRev(oSheet.Name, ":")
			Length = Len(oSheet.Name)
		Dim sPromptStrings(0) As String 'start counting by 0 !!!

		sPromptStrings(0) = Left(oSheet.Name, Length-(Length-positionOfDubbleDot)-1) 'if there is only one promped entry

		'sPromptStrings(1) = "String 2"

		' Add an instance of the title block definition to the sheet.

		Dim oTitleBlock As TitleBlock

		oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef, , sPromptStrings)
		
	Next

End Function

3) Run Rule to test if it works

 

**Optional**

 

I created a macro button to run the code to make the process easier,

1) go to Tools/VBA Editor

2) in the tree expand ApplicationProject(Default.ivb) and right click on the Modules folder then select insert/Module

3) Copy and paste the below code (This code is assuming the above iLogic code is in your external rules)

 

Public Sub Auto_Page_Numbering()
Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns
Set addIns = ThisApplication.ApplicationAddIns
    For Each addIn In addIns
        If InStr(addIn.DisplayName, "iLogic") > 0 Then
                        addIn.Activate
            Dim iLogicAuto As Object
            Set iLogicAuto = addIn.Automation
            Exit For
        End If
    Next
Debug.Print addIn.DisplayName
 
 
Dim RuleName1 As String
EXTERNALrule = "Page Numbering" 'Name of your external iLogic code you want this macro to run

'Dim RuleName2 As String
'INTERNALrule = "Rule0"
 
  Dim oDoc As Document
 
  Set oDoc = ThisApplication.ActiveDocument
  If oDoc Is Nothing Then
    MsgBox "Missing Inventor Document"
    Exit Sub
  End If
 
'iLogicAuto.RunRule oDoc, INTERNALrule 'for internal rule
iLogicAuto.RunExternalRule oDoc, EXTERNALrule 'for external rule

End Sub

4) Rename the EXTERALrule = "Page Numbering" with your iLogic code name you want to run

5) make note of your module name (Mine is Module 3), save & Close VBA application window

6) I've attached the image I used for my macro buttons you may use them as well! place them at

     C:\Users\Public\Documents\Autodesk\Inventor 2019\Macros

     Rename the Images where they say "Module3" to what your module is named

7) In an Inventor drawing template right click on the ribbon/Customize User Commands...

8) where it says All Commands, Click on it and select Macros, your new button should be there.Macro Button.JPG   add and hit okay  

 

 

 

 

 

your new button should now appear on the ribbon.

 

Hope this helps!

 

the below forms were very helpful:

https://forums.autodesk.com/t5/inventor-customization/sheet-names/m-p/6827453/highlight/true#M69576

https://forums.autodesk.com/t5/inventor-forum/auto-page-numbering-1-1a-1b/m-p/8850249#M748843

 

0 Likes