×
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

NXopen - How to move complete DatumCsys to new Layer

NXopen - How to move complete DatumCsys to new Layer

NXopen - How to move complete DatumCsys to new Layer

(OP)
Hello,

How can I move a complete DatumCsys - 3 DatumPlanes, 3 DatumAxis, 1 Point and 1 CSys to a new Layer with a VisualBasic Script?
I have a Script for that, but it does not move the Point and the Csys of the DatumCsys to the new Layer.
Here is the Code I used:

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

Dim Layno As Integer
Layno = 41

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
Dim objArray(0) As DisplayableObject

For Each ksobj As DisplayableObject In workPart.Datums
Dim ks_feat As NXOpen.Tag = NXOpen.Tag.Null
ufs.Modl.AskObjectFeat(ksobj.Tag, ks_feat)
If ks_feat <> NXOpen.Tag.Null Then
Dim datumfeat As NXOpen.Features.Feature = NXOpen.Utilities.NXObjectManager.Get(ks_feat)
If datumfeat.FeatureType.StartsWith("DATUM_CSYS") Then
objArray(0) = ksobj
workPart.Layers.MoveDisplayableObjects(Layno, objArray)
End If
End If
Next

End Sub

End Module

Can anyone help me with that problem??

With best Regards!


RE: NXopen - How to move complete DatumCsys to new Layer

Hi,

Below is the proper code:

Dim csys_tag As Tag
Dim origin_tag As Tag
Dim daxes As Tag()
Dim dplanes As Tag()
ufs.Modl.AskDatumCsysComponents(feat.Tag, csys_tag, origin_tag, daxes, dplanes)
ufs.Obj.SetLayer(origin_tag, layer)
ufs.Obj.SetLayer(csys_tag, layer)
For Each thisObj As NXOpen.Tag In daxes
ufs.Obj.SetLayer(thisObj, layer)
Next
For Each thisObj As NXOpen.Tag In dplanes
ufs.Obj.SetLayer(thisObj, layer)
Next

Regards,

Koutilya

RE: NXopen - How to move complete DatumCsys to new Layer

(OP)
Hi Koutilya,

It doesn´t work. I have changed my to to this:

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
Dim Layno As Integer
Layno = 41

For Each obj As DisplayableObject In workPart.Datums
Dim feat_tag As Tag
Dim csys_tag As Tag
Dim origin_tag As Tag
Dim daxes As Tag()
Dim dplanes As Tag()
ufs.Modl.AskDatumCsysComponents(feat_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
Next
End Sub
End Module

Now I get the error:

System.Runtime.InteropServices.SEHException: One external Component has one Exception
by NXOpen.UF.UFModl._AskDatumCsysComponents(Tag datum_csys_tag, Tag& csys_tag, Tag& origin, Tag* daxes, Tag* dplanes)
by NXOpen.UF.UFModl.AskDatumCsysComponents(Tag datum_csys_tag, Tag& csys_tag, Tag& origin, Tag[]& daxes, Tag[]& dplanes)
by ChangeDatums.Main() in C:\Users\xxxxxxx\AppData\Local\Teamcenter\TMP\tc\NXJournals7288\journal.vb:Zeile 57.

I Have changed "...AskDatumCsysComponents(feat.tag..." to "...AskDatumCsysComponents(feat_tag..." couse i get some message, that "feat" was not declared. So I also habe declared "Dim feat_tag As Tag".

Regards
Michael

RE: NXopen - How to move complete DatumCsys to new Layer

Here is some working code:

CODE

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 

www.nxjournaling.com

RE: NXopen - How to move complete DatumCsys to new Layer

Alternately, here is a version that doesn't use the UF functions.

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features


Module Module1

    Sub Main()

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

        Const newLayer As Integer = 41

        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
                    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: NXopen - How to move complete DatumCsys to new Layer

(OP)
Hi cowski,

both codes works fine!

Thank you - It was very helpfull!

Also best regards to Koutilya.

Michael

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