StianA
Mechanical
- Nov 7, 2011
- 12
Hi,
I'm new to journaling and have a question I hope you can help me with. I found this code online, which moves CSYS to a specific layer:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Imports NXOpen.Utilities
Imports NXOpen.UF
Module ChangeDatums
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
Const Layno As Integer = 41
For Each myFeature As Feature In workPart.Features
If TypeOf (myFeature) Is DatumCsys Then
'uncomment the following If block to skip internal features
'If myFeature.IsInternal Then
' Continue For
'End If
Dim csys_tag As Tag
Dim origin_tag As Tag
Dim daxes As Tag()
Dim dplanes As Tag()
ufs.Modl.AskDatumCsysComponents(myFeature.Tag, csys_tag, origin_tag, daxes, dplanes)
ufs.Obj.SetLayer(origin_tag, Layno)
ufs.Obj.SetLayer(csys_tag, Layno)
For Each thisObj As NXOpen.Tag In daxes
ufs.Obj.SetLayer(thisObj, Layno)
Next
For Each thisObj As NXOpen.Tag In dplanes
ufs.Obj.SetLayer(thisObj, Layno)
Next
End If
Next
End Sub
End Module
I would like to add something to this code so that it skips any CSYS that already was placed on layer two. Similar to what this script is doing with sketches:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Imports NXOpen.Utilities
Imports NXOpen.UF
Module ChangeDatums
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
Const SketchLayer As Integer = 22
Dim i As Integer = 0
'move sketches
For Each sketchObj As Sketch In workPart.Sketches
'skip internal sketches
If sketchObj.IsInternal Then
Continue For
End If
'skip sketches on layer 2
If sketchObj.Layer = 2 Then
Continue For
End If
sketchObj.Activate(False)
sketchObj.Layer = SketchLayer + i
sketchObj.RedisplayObject()
sketchObj.Deactivate(False, Sketch.UpdateLevel.SketchOnly)
i += 1
Next
'Update layers by turning on and off layer 22
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
theSession.SetUndoMarkName(markId1, "Layer Settings Dialog")
Dim stateArray1(0) As Layer.StateInfo
stateArray1(0).Layer = 22
stateArray1(0).State = Layer.State.Selectable
workPart.Layers.ChangeStates(stateArray1, False)
Dim stateArray2(0) As Layer.StateInfo
stateArray2(0).Layer = 22
stateArray2(0).State = Layer.State.Hidden
workPart.Layers.ChangeStates(stateArray2, False)
theSession.SetUndoMarkName(markId1, "Layer Settings")
theSession.DeleteUndoMark(markId1, Nothing)
End Sub
End Module
In the last script this is what makes it skip layer 2:
'skip sketches on layer 2
If sketchObj.Layer = 2 Then
Continue For
End If
Do any of you have a suggestion for how I could add something similar to the first script?
(I don't really understand what the "tag"-stuff is about, maybe someone could shine some light on that as well?) Thank you!
I'm currently on NX6, but moving to 8.5 soon, if that matters.
BR
Stian LA
I'm new to journaling and have a question I hope you can help me with. I found this code online, which moves CSYS to a specific layer:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Imports NXOpen.Utilities
Imports NXOpen.UF
Module ChangeDatums
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
Const Layno As Integer = 41
For Each myFeature As Feature In workPart.Features
If TypeOf (myFeature) Is DatumCsys Then
'uncomment the following If block to skip internal features
'If myFeature.IsInternal Then
' Continue For
'End If
Dim csys_tag As Tag
Dim origin_tag As Tag
Dim daxes As Tag()
Dim dplanes As Tag()
ufs.Modl.AskDatumCsysComponents(myFeature.Tag, csys_tag, origin_tag, daxes, dplanes)
ufs.Obj.SetLayer(origin_tag, Layno)
ufs.Obj.SetLayer(csys_tag, Layno)
For Each thisObj As NXOpen.Tag In daxes
ufs.Obj.SetLayer(thisObj, Layno)
Next
For Each thisObj As NXOpen.Tag In dplanes
ufs.Obj.SetLayer(thisObj, Layno)
Next
End If
Next
End Sub
End Module
I would like to add something to this code so that it skips any CSYS that already was placed on layer two. Similar to what this script is doing with sketches:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Imports NXOpen.Utilities
Imports NXOpen.UF
Module ChangeDatums
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
Const SketchLayer As Integer = 22
Dim i As Integer = 0
'move sketches
For Each sketchObj As Sketch In workPart.Sketches
'skip internal sketches
If sketchObj.IsInternal Then
Continue For
End If
'skip sketches on layer 2
If sketchObj.Layer = 2 Then
Continue For
End If
sketchObj.Activate(False)
sketchObj.Layer = SketchLayer + i
sketchObj.RedisplayObject()
sketchObj.Deactivate(False, Sketch.UpdateLevel.SketchOnly)
i += 1
Next
'Update layers by turning on and off layer 22
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
theSession.SetUndoMarkName(markId1, "Layer Settings Dialog")
Dim stateArray1(0) As Layer.StateInfo
stateArray1(0).Layer = 22
stateArray1(0).State = Layer.State.Selectable
workPart.Layers.ChangeStates(stateArray1, False)
Dim stateArray2(0) As Layer.StateInfo
stateArray2(0).Layer = 22
stateArray2(0).State = Layer.State.Hidden
workPart.Layers.ChangeStates(stateArray2, False)
theSession.SetUndoMarkName(markId1, "Layer Settings")
theSession.DeleteUndoMark(markId1, Nothing)
End Sub
End Module
In the last script this is what makes it skip layer 2:
'skip sketches on layer 2
If sketchObj.Layer = 2 Then
Continue For
End If
Do any of you have a suggestion for how I could add something similar to the first script?
(I don't really understand what the "tag"-stuff is about, maybe someone could shine some light on that as well?) Thank you!
I'm currently on NX6, but moving to 8.5 soon, if that matters.
BR
Stian LA