Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

nx open Move Datum CSYS Completely From Layer

Status
Not open for further replies.

Low Level User

Aerospace
Jun 12, 2019
4
Hello,

Searching the forums I found very helpful information. cowski posted some NX Open code that I was hoping him or someone else could help me with.. The Code is to completely move datum Csys (origin, 3 axes, 3 planes) to a new layer.

I cant figure out how to specify to only move the datum csys from a particular layer. Ex. "move all datum csys completely from layer 2 to layer 99" And not effect the Datum Csys on say layer 3 they stay where they are at.


Here is the code i found before:

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
 
Replies continue below

Recommended for you

Here's one possible solution:

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module131

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = theSession.ListingWindow()

    Sub Main()

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "datum csys layer")

        lw.Open()

        Const layerMoveFrom As Integer = 2
        Const layerMoveTo As Integer = 99

        For Each tempFeat As Features.Feature In theSession.Parts.Work.Features
            If Not TypeOf (tempFeat) Is Features.DatumCsys Then
                Continue For
            End If

            Dim myDatumCsys As Features.DatumCsys = tempFeat

            Dim dispObj As DisplayableObject = myDatumCsys.GetEntities(0)
            If dispObj.Layer = layerMoveFrom Then
                Dim myDatumCsysObjs As New List(Of DisplayableObject)
                For Each temp As DisplayableObject In myDatumCsys.GetEntities
                    myDatumCsysObjs.Add(temp)
                Next
                theSession.Parts.Work.Layers.MoveDisplayableObjects(layerMoveTo, myDatumCsysObjs.ToArray)
            End If

        Next

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

www.nxjournaling.com
 
Cowski.... You always have the answers when it comes to NX Open questions. It worked Great, exactly what I needed, Thank you very much!

While you are here, whats the best way to find NX Open samples to leverage? I got on the GTAC Support Center and they have alot of samples but its hard to find specific things.

 
In the GTAC solution center, after you enter your search phrase, you can filter by document type; choose the "nx_api" to get the code samples. You can further filter by programming language used, if there are multiple results returned.

This forum has a pretty good search function (the search button can be found on this page right below the thread title). When I'm searching for code, I use "journal" as one of the keywords.

Siemens has a forum dedicated to NX customizaion and programming; it also has a search function.

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

Part and Inventory Search

Sponsor