I need help applying the same Logic used for Features.Feature to Annotations.Annotation

I'm getting the error 'PmiManager' is not a member of 'NXOpen.Annotations.AnnotationManager'.


for each temp2 as Annotations.Annotation in theSession.Parts.Work.Annotations.PmiManager.Pmis
if TypeOf(temp2) is Annotations.Dimension then
SurfaceToMove.add(temp2)
end if
next

I'm trying to apply the same logic that was used to move features which works to annotations which is


for each temp1 as Features.Feature in theSession.Parts.Work.Features
if TypeOf(temp1) is Features.DatumCsys then
dim myCsys as Features.DatumCsys = temp1
for each featureitem as DisplayableObject in myCsys.GetEntities
CsysToMove.add(featureitem)
next
end if
next

A PMI object has a .GetDisplayInstances() method that returns an array of annotation objects. Some pseudocode is below, you'll probably need to tweak it for your use.

for each temp2 as Annotations.Annotation in theSession.Parts.Work.PmiManager.Pmis
StuffToMove.add(temp2.GetDisplayInstances())
next

Even if I just test out the code using


for each temp2 as Annotations.Annotation in theSession.Parts.Work.Annotations.PmiManager.Pmis
next

I get the same error as above.

The PMI manager belongs to the part, not the annotation collection.

So what is the correct code to use to loop through the annotations?

for each temp2 as Annotations.Annotation in theSession.Parts.Work.PmiManager.Pmis

Okay thank you. Sorry for frustrating you. I'll keep playing with it and try to figure out how to apply this to surfacefinishes.

You are not frustrating me, I don't mind the questions. I had inadvertently copied the incorrect code; but I have now edited the reply. My answers have been a bit terse because it has been a busy day.

Oh alright, just know I appreciate all of your help. I'm still just learning and trying to understand the structure of NXOpen.

When I apply your advice I'm obviously still missing something because I get the error 'GetDisplayInstances' is not a member of 'NXOpen.Annotations.SurfaceFinish'.

for each temp2 as Annotations.Annotation in theSession.Parts.Work.PmiManager.Pmis
if typeof(temp2) is Annotations.SurfaceFinish then
dim myDimension as Annotations.SurfaceFinish = temp2
surfaceToMove.add(myDimension.GetDisplayInstances())
end if
next

I'm a bit surprised that code doesn't give a type mismatch at the start of the for loop because the PMI object can't be directly cast to an annotation object.

I've not done much work with the PMI class. Can you create a simple example file with a few surface finish symbols you are looking for and email it to me?
info@nxjournaling.com

I just emailed you a part with several types of PMI on it.

The code below gets the PMI display annotation, reports the type, adds it to a list, and uses a display modification to change the color of all the PMIs. If you need to change the different types separately (Datums, FCFs, surface finish symbols, etc), you might need to sort them out yourself in the For loop (add them to different lists).

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

Module MovePmiSurfaceFinish

Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

lw.Open()

Dim myPmi As New List(Of Annotations.Annotation)

For Each tempPmi As Annotations.Pmi In theSession.Parts.Work.PmiManager.Pmis
Dim pmiAnnotations() As Annotations.Annotation = tempPmi.GetDisplayInstances
For Each tempAnnotation As Annotations.Annotation In pmiAnnotations
myPmi.Add(tempAnnotation)
lw.WriteLine("PMI display instance type: " & tempAnnotation.GetType.ToString)
Next
Next

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.NewColor = 156
displayModification1.Apply(myPmi.ToArray)
displayModification1.Dispose()

End Sub

End Module

This works amazing. Do you run this forum in your free time? Thank you so much for your help.

Glad I could help!
Yes, this website is a hobby of mine that I run in my spare time.

I think that's such a great thing you do for us. Personally I wouldn't have known where to begin and I'm learning a lot from the way I read you implementing the code.

With your help and the help from this website I was finally able to finish this tool here is the source code. It moves sketches to the specified layer and then each additional sketch to the previous layer + 1. It moves datums to the specified layer. It moves the Csys to the specified layer. It moves PMI to the specified layer.

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

Module Module9

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim sketchToMove As New List(Of DisplayableObject)
Dim CsysToMove As New List(Of DisplayableObject)
Dim myPmi As New List(Of Annotations.Annotation)
Dim DatumFeatureToMove As New List(Of DisplayableObject)

Dim PmiLayer As Integer = 100
Dim SketchLayer As Integer = 25
Dim CsysLayer As Integer = 5
Dim DatumFeatureLayer As Integer = 180

Dim displayModification1 As DisplayModification
Dim displayModification2 As DisplayModification
Dim displayModification3 As DisplayModification
Dim displayModification4 As DisplayModification

displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.NewLayer = PmiLayer

displayModification2 = theSession.DisplayManager.NewDisplayModification()
displayModification2.NewLayer = SketchLayer

displayModification3 = theSession.DisplayManager.NewDisplayModification()
displayModification3.NewLayer = CsysLayer

displayModification4 = theSession.DisplayManager.NewDisplayModification()
displayModification4.NewLayer = DatumFeatureLayer

for each temp as DisplayableObject in theSession.Parts.Work.Sketches
sketchToMove.add(temp)
displayModification2.Apply(sketchToMove.ToArray)
sketchToMove.Clear
sketchLayer = sketchLayer + 1
displayModification2.NewLayer = sketchLayer
next

for each temp1 as Features.Feature in theSession.Parts.Work.Features
if TypeOf(temp1) is Features.DatumCsys then
dim myCsys as Features.DatumCsys = temp1
for each featureitem as DisplayableObject in myCsys.GetEntities
CsysToMove.add(featureitem)
next
end if
next

for each temp3 as Features.Feature in theSession.Parts.Work.Features
if TypeOf(temp3) is Features.DatumFeature then
dim myDatumFeature as Features.DatumFeature = temp3
for each Datumfeatureitem as DisplayableObject in myDatumFeature.GetEntities
DatumFeatureToMove.add(Datumfeatureitem)
next
end if
next

'lw.Open()

For Each tempPmi As Annotations.Pmi In theSession.Parts.Work.PmiManager.Pmis
Dim pmiAnnotations() As Annotations.Annotation = tempPmi.GetDisplayInstances
For Each tempAnnotation As Annotations.Annotation In pmiAnnotations
myPmi.Add(tempAnnotation)
'lw.WriteLine("PMI display instance type: " & tempAnnotation.GetType.ToString)
Next
Next

'Dim displayModification1 As DisplayModification
'displayModification1 = theSession.DisplayManager.NewDisplayModification()
'displayModification1.NewColor = 156
displayModification1.Apply(myPmi.ToArray)
'displayModification1.Dispose()

displayModification2.Apply(sketchToMove.ToArray)
displayModification3.Apply(CsysToMove.ToArray)
displayModification4.Apply(DatumFeatureToMove.ToArray)

displayModification1.Dispose()
displayModification2.Dispose()
displayModification3.Dispose()
displayModification4.Dispose()

End Sub

End Module

Thanks for posting your code!