Sheet Numbering

Sheet Numbering

timothy_berg
Advocate Advocate
1,567 Views
15 Replies
Message 1 of 16

Sheet Numbering

timothy_berg
Advocate
Advocate

I have the code below to name the sheets for easy export to DWG.

SyntaxEditor Code Snippet

Dim oSheets As Sheets = ThisDrawing.Document.sheets
Dim oSheet As Sheet
Dim count As Integer
count=0

For Each oSheet In oSheets
    count+=1
    Page_Count=count
    'MessageBox.Show(Page_Count)
    oSheet.activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
    EquipName = oModel.PropertySets.Item("Inventor Summary Information").Item("Comments").Value
    EquipName1=Left(EquipName,3)
        ActiveSheet.Sheet.Name =EquipName1 & " S" & Page_Count
Next

 which provides a result of 

001 S1

001 S2

002 S3

002 S4

My preferred result would be

001 S1

001 S1

002 S1

002 S2

In other words I want the "S""number" to count with the instance of the "EquipName1".

 

0 Likes
Accepted solutions (1)
1,568 Views
15 Replies
Replies (15)
Message 2 of 16

dgreatice
Collaborator
Collaborator

Hi,

 

so in 1 sheet there are > 1 view and each view is difference component?

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 3 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@timothy_berg,

 

"EquipName1" seems unique in each sheet. Try below iLogic code.

 

ActiveSheet.Sheet.Name =EquipName1 & " S" & EquipName1 

How to get instance of "EquipName1" ?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 16

timothy_berg
Advocate
Advocate

Thanks for the reply

 

the count will be the number of instances of the same value coming from EquipName1 not the sheet number

001 S1:1

001 S2:2

002 S1:3

002 S2:4

003:5

004:6

005 S1:7

005 S2:8

005 S3:9

the EquipName1 would refer to the number of sheets it has, in 005's case i am providing 3 sheets etc.

 

 

 

0 Likes
Message 5 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@timothy_berg,

 

Try below iLogic code to count instance of EquipName1.

 

Dim oSheets As Sheets = ThisDrawing.Document.Sheets
Dim oSheet As Sheet 
Dim oList As ArrayList = New ArrayList()
For Each oSheet In oSheets 
	
    oSheet.activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
    EquipName = oModel.PropertySets.Item("Inventor Summary Information").Item("Comments").Value
    EquipName1 = Left(EquipName, 3) 
	oList.Add(EquipName1)
	Dim item As String
	Dim i As Integer
	For Each item In oList
	    If item = EquipName1 Then
	        i = i + 1
	    End If
	Next 
	
	ActiveSheet.Sheet.Name = EquipName1 & " S" & i
     
Next

In this, it is considered single instance of EquipName1. It would results in below sheet names.

 

001 S1:1

001 S2:2

002 S1:3

002 S2:4

003 S1:5

004 S1:6

005 S1:7

005 S2:8

005 S3:9

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 16

timothy_berg
Advocate
Advocate

thanks for the reply i'm getting this result

001 S1:1

001 S3:2

002 S4:3

002 S6:4

0 Likes
Message 7 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@timothy_berg,

 

Can you please share drawing file to test? Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 16

timothy_berg
Advocate
Advocate

files attached

0 Likes
Message 9 of 16

timothy_berg
Advocate
Advocate

files attached

0 Likes
Message 10 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@timothy_berg,

 

Try below iLogic code.

 

Dim oSheets As Sheets = ThisDrawing.Document.Sheets
Dim oSheet As Sheet 
Dim oList As ArrayList = New ArrayList()
For Each oSheet In oSheets 
	
    oSheet.activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
    EquipName = oModel.PropertySets.Item("Inventor Summary Information").Item("Comments").Value
    EquipName1 = Left(EquipName, 3)  

	oList.Add(EquipName1)
	Dim item As String
	Dim i As Integer = 0
	For Each item In oList
	    If item = EquipName1 Then
	        i = i + 1
	    End If
	Next 
	
	ActiveSheet.Sheet.Name = EquipName1 & " S" & i
Next

Result of above code for attached sample drawing.

 

001 S1:1

001 S2:2

002 S1:3

002 S2:4

003 S1:5

004 S1:6

005 S1:7

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 16

timothy_berg
Advocate
Advocate

Thanks for the reply is there any way to get the code to only put the S count on the duplicate instance of the EquipName1. I've attached a screen shot of the desired result that I modified manually.

 

 

 

0 Likes
Message 12 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@timothy_berg,

 

Try below iLogc code to get desired result. If desired result is achieved, click on "ACCEPT SOLUTION".

Dim oSheets As Sheets = ThisDrawing.Document.Sheets
Dim oSheet As Sheet 
Dim oList As ArrayList = New ArrayList()
For Each oSheet In oSheets 
	
    oSheet.activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
    EquipName = oModel.PropertySets.Item("Inventor Summary Information").Item("Comments").Value
    EquipName1 = Left(EquipName, 3) 
	oList.Add(EquipName1)
	Dim item As String
	Dim i As Integer = 0
	For Each item In oList
	    If item = EquipName1 Then
	        i = i + 1
	    End If
	Next 
	
	ActiveSheet.Sheet.Name = EquipName1 & " S" & i
     
Next

For Each item As String In oList
 
	Dim itemName As String = item

	Dim itemCount = (From a As String In oList Select a Where a = itemName).Count 
	If itemCount = 1 Then
		oName = item & " S1"
		For Each oSheet In oSheets
			oSheet.activate 
			If ActiveSheet.Sheet.Name.StartsWith(oName) = True Then
				ActiveSheet.Sheet.Name = item
			End If
		Next
	End If 
	 
Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 13 of 16

timothy_berg
Advocate
Advocate

Thank you for helping me on this, I have this error message:

Error on Line 28 : Expression of type 'System.Collections.ArrayList' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.

 

 

0 Likes
Message 14 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@timothy_berg,

 

Linq is advanced technique to query duplicate count in ArrayList. It is supported in Inventor 2018. iLogic code is modified with simple technique to get duplicate. You can try below iLogic code to achieve desire result.

 

Dim oSheets As Sheets = ThisDrawing.Document.Sheets
Dim oSheet As Sheet 
Dim oList As ArrayList = New ArrayList()
For Each oSheet In oSheets 
	
    oSheet.activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
    EquipName = oModel.PropertySets.Item("Inventor Summary Information").Item("Comments").Value
    EquipName1 = Left(EquipName, 3) 
	oList.Add(EquipName1)
	Dim item As String
	Dim i As Integer =0
	For Each item In oList
	    If item = EquipName1 Then
	        i = i + 1
	    End If
	Next 
	
	ActiveSheet.Sheet.Name = EquipName1 & " S" & i
     
Next

For Each item As String In oList
 
	Dim itemName As String = item

	Dim itemCount As Integer  = 0
	For Each itemName In oList
		If item = itemName Then
			itemCount = itemCount + 1
		End If
	Next
	 
	
	If itemCount = 1 Then
		oName = item & " S1"
		For Each oSheet In oSheets
			oSheet.activate 
			If ActiveSheet.Sheet.Name.StartsWith(oName) = True Then
				ActiveSheet.Sheet.Name = item
			End If
		Next
	End If 
	 
Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 15 of 16

timothy_berg
Advocate
Advocate

Thanks for figuring that out.

0 Likes
Message 16 of 16

timothy_berg
Advocate
Advocate

One more thing can the Active Sheet Name be displayed in the titleblock?

0 Likes