Now look again at my code. It does exactly the same, but faster because it doesn't activate each sheet (thus Inventor doesn't need to generate the graphics for it). I'm not trying to be harsh on you, I just want you to learn, young padawan.
The workflow of your code (red are the unnecessary parts):
1) Get all sheets
2) Get active document
3) Check document type
4) Set temp active sheet (oSheetTest)
5) Check for views in (4)
6) Get model document from active view
7) Get part number from (6)
8) Loop throught all sheets
9) Activate each sheet
10) Check for views in sheet
11) Get first view
12) Get model document from active sheet
13) Get part number
14) Check the active sheet name
15) Set the active sheet name
- end of loop -
16) Re-Activate the first sheet
And mine:
1) Get active document
2) Check document type
3) Loop throught all sheets
4) Check for views in sheet
5) Get first view
6) Get model document
7) Get part number
8) Check the part number
9) Check if the sheet name = part number
10) Set the sheet name
- end of loop -
On row 32 you're calling "Exit Sub" instead of "Continue For"
If you realy want to have there the message boxes and spam yourself with messages, here you go:
Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
For Each oSheet As Sheet In oDoc.Sheets
If oSheet.DrawingViews.Count = 0 Then
MsgBox("The sheet (" & oSheet.Name & ") does not contain any views!")
Continue For
End If
Dim oView As DrawingView = oSheet.DrawingViews(1)
Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oName As String = iProperties.Value(oModelDoc.DisplayName, "Project", "Part Number")
If oName = vbNullString Then
MsgBox("The sheet's (" & oSheet.Name & ") model's part number is empty!")
Continue For
End If
If oSheet.Name = oName Then Continue For
oSheet.Name = oName
Next
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods