Regard Layer Get and set layer

Actually I want to move sketeches to the layer 101, 102,... and so on
Suppose my part model has three sketches SKT_000,SKT_001,& SKT_002
My NX journal select first sketch "SKT_000" to move into layer 101, like wise SKT_001 to 102 and SKT_002 to 103
I have made below code for the task, but i couldn't make it.
Can any one help for the correction of below one.
*****************************************************
Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim layno as integer
layno = 101

For Each ts As Sketch In workPart.Sketches
ts.Activate(Sketch.ViewReorient.False)
ts.layer.set = layno
layno = layno+1
Next

End Sub
End Module
*********************************************
Regards,
Gopal Parthasarathy
+91 7799221856

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

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

Dim Layno as integer
layno =101

For Each ts As Sketch In workPart.Sketches

ts.Activate(Sketch.ViewReorient.False)

ts.layer.set = layno

layno = layno+1

Next

End Sub

End Module

Gopal Parthasarathy
CERT/FEA Engineer
B/E Aerospace

After you set the layer, you will need to call the .RedisplayObject method and perform an update. An easier way is to use the DisplayModification object as follows:





Option Strict Off
Imports System
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 Layno As Integer
Layno = 101

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()

For Each ts As Sketch In workPart.Sketches

displayModification1.NewLayer = Layno

Dim objects1(0) As DisplayableObject
objects1(0) = ts
displayModification1.Apply(objects1)

Layno += 1

Next

displayModification1.Dispose()

End Sub

End Module

You can write the displayModification code in a slightly tidier way using VB's ability to construct arrays on the fly. For example, you could write:

Dim objects1 As DisplayableObject() = {ts}
displayModification1.Apply(objects1)

Or even just this:


displayModification1.Apply({ts})

Good tip!

Thanks ciao.