iLogic - Sort sheets by sheet name in open drawing

iLogic - Sort sheets by sheet name in open drawing

GKPByDesign
Advocate Advocate
1,810 Views
6 Replies
Message 1 of 7

iLogic - Sort sheets by sheet name in open drawing

GKPByDesign
Advocate
Advocate

I work with massive drawing files sometime over 200 pages in one file, (while I know people don't like this, please reframe from comments about doing one file and multiple sheets compared to many files and one sheet) is there a way to re-order my sheets base on the sheet name? rather than having to drag each each page individually. 

0 Likes
Accepted solutions (1)
1,811 Views
6 Replies
Replies (6)
Message 2 of 7

Sergio.D.Suárez
Mentor
Mentor

Hi, try this rule below. I think it does what you need

 

Sub Main ()
On Error Resume Next
Dim drawingDoc As DrawingDocument = ThisDoc.Document
Dim Sheet As Sheet = Nothing
Dim sheetsList As New List(Of Sheet)
Dim BrowserPane As BrowserPane = drawingDoc.BrowserPanes.Item("Model")

For Each Sheet In drawingDoc.Sheets
	sheetsList.Add(Sheet)
Next

sheetsList.Sort(AddressOf Comparer)

For Each Sheet In sheetsList
	Dim sheetNode As BrowserNode = BrowserPane.GetBrowserNodeFromObject(Sheet)
	Dim bottomNode As BrowserNode = BrowserPane.TopNode.BrowserNodes.Item(BrowserPane.TopNode.BrowserNodes.Count)
	BrowserPane.Reorder(bottomNode, False, sheetNode)
Next
End Sub

I hope it is useful for you. regards

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 7

GKPByDesign
Advocate
Advocate

Error on Line 12 : 'Comparer' is a type and cannot be used as an expression.

0 Likes
Message 4 of 7

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

 

 

Sub Main ()
On Error Resume Next
Dim drawingDoc As DrawingDocument = ThisDoc.Document
Dim Sheet As Sheet = Nothing
Dim sheetsList As New List(Of Sheet)
Dim BrowserPane As BrowserPane = drawingDoc.BrowserPanes.Item("Model")

For Each Sheet In drawingDoc.Sheets
	sheetsList.Add(Sheet)
Next

sheetsList.Sort(AddressOf Comparer)

For Each Sheet In sheetsList
	Dim sheetNode As BrowserNode = BrowserPane.GetBrowserNodeFromObject(Sheet)
	Dim bottomNode As BrowserNode = BrowserPane.TopNode.BrowserNodes.Item(BrowserPane.TopNode.BrowserNodes.Count)
	BrowserPane.Reorder(bottomNode, False, sheetNode)
Next
End Sub

Private Function Comparer(x As Sheet, y As Sheet) As Integer
	Return String.Compare(x.Name,y.Name)
End Function

 

Excuse me, I am missing the function below everything, greetings!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 7

Josh_Hunt
Advocate
Advocate

Thank you @Sergio.D.Suárez 

This worked for me also... however do you know a method that works without using BrowserPane?
BrowserPane is not available in InventorCoreConsole/Forge.

Josh Hunt
0 Likes
Message 6 of 7

M_S_ALDT2
Explorer
Explorer

Hi, so I have been making a similar code, when i came across yours. the problem is when there is over 100 sheets, or if the part numbers in this case end in 100, 101, etc it then goes 1 to 10 then 100, 101, 102....109, then 11 then 110, 111, 112, etc... and mixes up the numbers. is there a way to avoid this.

0 Likes
Message 7 of 7

d_eckel
Contributor
Contributor

Hi, a fast idea:

Get length of the sheetname and insert one 0 for len(SHEETNAME)=2 and two 0 ("00") for len(SHEETNAME)=1 --> sort sheets --> delete zeroes at the beginning of the sheetnames.

0 Likes