Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

NXOPEN set first datum to layer 62 all other to 64 1

Status
Not open for further replies.

Halasox

Civil/Environmental
Jun 5, 2016
16
0
0
US
Hi all,

Have a basic code that puts all datums to layer 64, but I would like to set the first datum feature onto layer 62. What would I need to modify? Thanks

Code:
        For Each obj As DisplayableObject In workpart.Datums
        If Not obj.IsBlanked AndAlso workpart.Layers.GetState(obj.Layer) <> Layer.State.Hidden Then
          objArray(0) = obj
          workpart.Layers.MoveDisplayableObjects(Val(64), objArray)
        End If
        Next
 
Replies continue below

Recommended for you

By "first datum", do you mean the first one in the part navigator feature list? Also, for this "first datum", are you looking for a datum csys, datum plane, datum axis, or any one of the above?

The code that you have posted is iterating through the Datums collection, which may or may not return the datums in the same order as the feature tree. I'd suggest keeping the code you have now and adding a secondary for loop that iterates through the features looking for your desired datum type and moving the first one it finds to the desired layer. Once it finds and moves the desired datum, it can exit the loop.

www.nxjournaling.com
 
I mean the first one in the part navigator that is always present! I am looking to put the csys, plane, axis of the initial datum into a separate layer and all other in a different one. I was thinking the same but wasn't able to get it running using "first feature".
 
The following code will move the first datum csys it finds to layer 62. Note that a datum csys is "always present" in your files because one is included in the template; there is nothing stopping a user from deleting it or reordering it to another timestamp in the feature list.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features


Module Module3

    Sub Main()

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


        'your code for moving all datums to desired layer


        'the code below will move the first datum cys feature found (if any) to the specified layer
        Const newLayer As Integer = 62

        Dim featEntities() As NXObject

        'lw.WriteLine("*** All Features ***")
        For Each myFeature As Feature In workPart.Features.GetFeatures()
            'lw.WriteLine(myFeature.GetFeatureName)
            'lw.WriteLine(myFeature.FeatureType)
            If TypeOf (myFeature) Is DatumCsys Then

                If myFeature.IsInternal Then
                    Continue For
                End If

                featEntities = myFeature.GetEntities
                'lw.WriteLine("Entity Count: " & featEntities.Length)
                'For Each myEnt As NXObject In featEntities
                '    lw.WriteLine("Type: " & myEnt.GetType.ToString)
                'Next

                Dim DBuilder As DatumCsysBuilder
                DBuilder = workPart.Features.CreateDatumCsysBuilder(myFeature)
                Dim DCObj() As NXObject = DBuilder.GetCommittedObjects
                'lw.WriteLine("num committed objects: " & DCObj.Length)

                For Each temp As DisplayableObject In DCObj
                    'lw.WriteLine("type: " & temp.GetType.ToString)
                    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

                'exit for loop
                Exit For

            End If
            lw.WriteLine("")
        Next
        lw.Close()

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function

End Module

www.nxjournaling.com
 
Status
Not open for further replies.
Back
Top