regard No.Of Symbols details in each Sheet

Suppose I have 10 drawing sheet in my workpart, Each drawing sheet has diffrent number of symbols,
I want to know no .of symbols in each sheet wise. it has to dispaly message like no of sysmbols in current drawing after the message it should go to next sheet as well display (active) in current window. when ever I used to get information of symbols it's going through entire workpart and giving no.of symbols used in all drawing sheet

For Each sheet As Drawings.DrawingSheet In workPart.DrawingSheets
sheet.open()
For Each tempID As Annotations.IdSymbol In workPart.Annotations.IdSymbols

Instead of " For Each tempID As Annotations.IdSymbol In workPart.Annotations.IdSymbols" I used

For Each tempID As Annotations.IdSymbol In sheet.Annotations.IdSymbols, error with "sheet" variable not declared in workpart not declared
what shpould I do for the above requirement

Gopal Parthasarathy
CERT/FEA Engineer
B/E Aerospace

What version of NX are you running?

Below is some code (written for NX 8.5) that will report the symbols by drawing sheet.

'NXJournaling.com
'October 28, 2014
'
'Report ID symbols by drawing sheet.
'
'NX 8.5

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module report_id_symbols_sheet

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If

lw.Open()

Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, undoMarkName)

Dim drawingSheetNames As New List(Of String)
Dim sheetIdSymbols As New List(Of List(Of Annotations.IdSymbol))
For Each tempDrawingSheet As Drawings.DrawingSheet In workPart.DrawingSheets
drawingSheetNames.Add(tempDrawingSheet.Name)
Dim idSymbolList As New List(Of Annotations.IdSymbol)
sheetIdSymbols.Add(idSymbolList)
Next

For Each tempSymbol As Annotations.IdSymbol In workPart.Annotations.IdSymbols

Dim symbolSheet As Drawings.DrawingSheet = AskDrawingSheet(tempSymbol)
If IsNothing(symbolSheet) Then
'something went wrong
lw.WriteLine("error: " & tempSymbol.Name)
Continue For
End If

Dim sheetIndex As Integer = GetSheetIndex(symbolSheet)
If sheetIndex = -1 Then
'something went wrong
lw.WriteLine("error with GetSheetIndex(" & symbolSheet.Name & ")")
Continue For
End If

sheetIdSymbols.Item(sheetIndex).Add(tempSymbol)

Next

'report symbols by sheet
For Each dwgSheet As Drawings.DrawingSheet In workPart.DrawingSheets
lw.WriteLine(dwgSheet.Name & ": " & sheetIdSymbols.Item(GetSheetIndex(dwgSheet)).Count.ToString & " symbol(s)")
For Each tempSymbol As Annotations.IdSymbol In sheetIdSymbols.Item(GetSheetIndex(dwgSheet))
lw.WriteLine(" idSymbol tag: " & tempSymbol.Tag)
Next
Next
lw.WriteLine("")

lw.Close()

End Sub

' This function will work for:
' an object which "Resides on drawing" or is "View Dependent In" a DraftingView
' a DraftingView
' a DrawingSheet.View
' Returns Nothing for all other (ie. model mode) objects
'code by Amy Webster of GTAC,
'GTAC document: nx_api4936 or nx_api4937
Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet

Dim theView As View = TryCast(theObject, View)
If Not theView Is Nothing Then
Dim sheetTag As Tag = Nothing
Try
theUFSession.Draw.AskDrawingOfView(theView.Tag, sheetTag)
Return Utilities.NXObjectManager.Get(sheetTag) ' the drawing it is on
Catch ex As NXException
Return Nothing ' it is a model view
End Try
End If

Dim viewName As String = Nothing
Dim status As Integer = Nothing
Try
theUFSession.View.AskViewDependentStatus(theObject.Tag, status, viewName)
Catch ex As NXException
Return Nothing
End Try
If status = 0 Then Return Nothing ' it is a model mode object

Dim viewTag As Tag = Nothing
theUFSession.View.AskTagOfViewName(viewName, viewTag)
Dim viewType As Integer = Nothing
Dim viewSubtype As Integer = Nothing
theUFSession.View.AskType(viewTag, viewType, viewSubtype)
If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view

Dim drawingTag As Tag = Nothing
theUFSession.Draw.AskDrawingOfView(viewTag, drawingTag)
Return Utilities.NXObjectManager.Get(drawingTag) ' the drawing it is on!

End Function

Function GetSheetIndex(ByVal theSheet As Drawings.DrawingSheet) As Integer

Dim sheetArray() As Drawings.DrawingSheet
sheetArray = workPart.DrawingSheets.ToArray

For i As Integer = 0 To sheetArray.Length - 1

If sheetArray(i).Name = theSheet.Name Then
Return i
End If

Next

'sheet not found (should never get here)
Return -1

End Function

End Module