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!

NXopen - How to move complete DatumCsys to new Layer 1

Status
Not open for further replies.

MEichWey

Industrial
Apr 16, 2014
39
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!


 
Replies continue below

Recommended for you

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
 
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

 
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
 
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
 
Hi cowski,

both codes works fine!

Thank you - It was very helpfull!

Also best regards to Koutilya.

Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor