I struggle with a code to get a list of all PMI symbols.
It works if there are only PMI symbols, but not if it is a mixture of both PMI symbols and drawing symbols.
Do you have any suggestions?
It gives this error message:
System.InvalidCastException: Unable to cast object of type 'NXOpen.Annotations.CustomSymbol' to type 'NXOpen.Annotations.PmiCustomSymbol'.
at NXJournal.Main(String[] args) in C:\Users\*****\AppData\Local\Temp\NXJournals28644\journal0.vb:line 16
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
'For Each custSymbol As Annotations.CustomSymbol In workPart.Annotations.CustomSymbols 'This works well if ONLY drawing symbols exist.
For Each custSymbol As Annotations.PmiCustomSymbol In workPart.Annotations.CustomSymbols 'This works well if ONLY PMI symbols exist.
lw.WriteLine(custSymbol.ToString)
lw.WriteLine(custSymbol.SymbolName)
lw.WriteLine("")
next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module
re: PMI symbols
Try this code (untested).
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
For Each custSymbol As Annotations.BaseCustomSymbol In workPart.Annotations.CustomSymbols
lw.WriteLine(custSymbol.ToString)
lw.WriteLine(custSymbol.SymbolName)
lw.WriteLine("")
next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module
Re: PMI Symbols
It works! Not that I doubted it.
Thanks again.
Best Regards
Gunnar