×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

NX Journal - Move CSYS to layer, but skip CSYS on layer 2

NX Journal - Move CSYS to layer, but skip CSYS on layer 2

NX Journal - Move CSYS to layer, but skip CSYS on layer 2

(OP)
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

RE: NX Journal - Move CSYS to layer, but skip CSYS on layer 2

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features


Module Module2

    Sub Main()

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

        Const newLayer As Integer = 41
        Const skipLayer As Integer = 2

        For Each myFeature As Feature In workPart.Features.GetFeatures()
            If TypeOf (myFeature) Is DatumCsys Then

                'uncomment following If block to skip internal features
                'If myFeature.IsInternal Then
                '    Continue For
                'End If

                Dim DBuilder As DatumCsysBuilder
                DBuilder = workPart.Features.CreateDatumCsysBuilder(myFeature)
                Dim DCObj() As NXObject = DBuilder.GetCommittedObjects

                For Each temp As DisplayableObject In DCObj
                    If temp.Layer = skipLayer Then
                        'terminate the for loop
                        Exit For
                    End If
                    temp.Layer = newLayer
                    temp.RedisplayObject()
                Next
                DBuilder.Destroy()

                Dim updateMark As Session.UndoMarkId
                updateMark = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "update")
                Try
                    theSession.UpdateManager.LogForUpdate(myFeature)
                    theSession.UpdateManager.DoUpdate(updateMark)

                Catch ex As Exception

                End Try

            End If
        Next

    End Sub

End Module 

www.nxjournaling.com

RE: NX Journal - Move CSYS to layer, but skip CSYS on layer 2

Dear Cowski,

What is an internal feature? How is relative to the part navigator tree?

Thank you.

RE: NX Journal - Move CSYS to layer, but skip CSYS on layer 2

(OP)
Thanks a lot for the quick reply, cowski!

I've just tested the script and I get this error message:

Line 42: 'LogForUpdate' is not a member of 'NXopen.Update'

Do you know how to fix this?

BR

Stian LA

RE: NX Journal - Move CSYS to layer, but skip CSYS on layer 2

Quote (StianA)

Line 42: 'LogForUpdate' is not a member of 'NXopen.Update'

Do you know how to fix this?

Hasten the move the NX 8.5 smile
For NX 6, you could try commenting out that line; I don't have NX 6 installed to test with, so I can't guarantee that that will fix the problem and everything will run fine...

www.nxjournaling.com

RE: NX Journal - Move CSYS to layer, but skip CSYS on layer 2

Quote (EngProgrammer)

What is an internal feature? How is relative to the part navigator tree?

For an example of an internal feature, start the "extrude" command. In the "select curve" prompt, hit the sketch icon and create a sketch. Finish the sketch and enter values for the extrude. When you press OK, the extrude is created, but the sketch does not show up in the part navigator, even though it is a full fledged feature. The sketch has been made "internal" to the extrude feature.

www.nxjournaling.com

RE: NX Journal - Move CSYS to layer, but skip CSYS on layer 2

(OP)
Thanks a lot, Cowski! That works perfectly in NX 8.5:)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources