Moving PMI to New Layer HELP!

I feel like I'm so close but I'm getting an error "Line 26: Type 'NXOpen.Annotations.Annotation.Later' is not declared" Could someone please point me in the correct direction.


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

Module Module9

Sub Main()

Dim PmiCollection As NXOpen.Annotations.Pmi
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim allpmi As Annotations.PmiCollection = workPart.PmiManager.Pmis

Dim sketchLayer As Integer = 33

Dim displayModification1 As DisplayModification

displayModification1 = theSession.DisplayManager.NewDisplayModification()

for each temp as NXOpen.Annotations.Annotation.Layer in allpmi
displayModification1.Apply(temp.ToArray)
next

displayModification1.NewLayer = sketchLayer

displayModification1.Dispose()

End Sub

End Module

You will need to set the new layer before calling the .Apply method. Also, if you want to move all the PMI objects to a new array, you do not need to iterate through the collection and update each item individually. The display modification object can process an array of objects.

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.NewLayer = sketchLayer
displayModification1.Apply(theSession.Parts.Work.PmiManager.Pmis.ToArray)
displayModification1.Dispose()

I seriously appreciate the reply from you. How can I navigate the help file to find everything I can call using theSession.Parts.Work? Searching for Pmis on the help file https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx...

doesn't return anything useful for me?

For instance I want to do this for sketches, features, etc.

For Features would I just do


Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.NewLayer = sketchLayer
displayModification1.Apply(theSession.Parts.Work.Features.ToArray)
displayModification1.Dispose()

Looking up the PMIManager class https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx...

I can't even find Pmis even though the code you've written shows PmiManager.Pmis

The links that you posted are for the python version of the API; NX10 was the first version that had a python implementation and the help docs are a bit incomplete. The help docs have improved a bit in the later versions, but they still are difficult to navigate.

What version of NX are you using? Look up NXOpen.Part to find all of the collections and methods that you can call from the work part. The link below is to the NX1847 version (the first continuous release version that followed NX 12).

https://docs.plm.automation.siemens.com/data_services/resources/nx/1847/...

I'm using NX12 however I see that what you linked is for Part.PmiManager but the code is written Parts.Work.PmiManager so it's plural Parts vs just Part like in the documentation and it's not including Work. Maybe I'm just misunderstanding how to use object oriented programming.

Ok, first you need a reference to the NX session; this is "theSession" in code that I write. The session object has a .Parts collection that gives you access to all the currently loaded parts. The .Parts collection has a .Work property that gives you access to the current work part (similarly, .Display gives you access to the current display part). The session's .Parts is plural because it is a collection of NXOpen.Part objects.

In review:
.Parts is a collection of NXOpen.Part objects in the NX session
.Work is an NXOpen.Part object that is the current work part

theSession.Parts.Work will have all the collections, properties, and methods listed in the documentation for the Part object.

so why doesn't .GetSession() show up under NXOpen.Session? How would I know that .GetSession() is a valid command without having seen you use it?

https://docs.plm.automation.siemens.com/data_services/resources/nx/1847/...

I am starting to understand better.

https://docs.plm.automation.siemens.com/data_services/resources/nx/1847/...

Under properties I could send "ToArray" any item which returns a collection.

For instance displayModification1.Apply(theSession.Parts.Work.ComponentGroups.ToArray)

How would I apply this same logic to get a collection of all features used to make a part. Extrudes, Cuts, Chamfers etc.

Each part object has a .Features collection.