Hello,
I'm trying to build a journal (VB) for NX 9 that selects all components in a workpart that have a specific attribute with a specific string value, after that it moves them to a specific layer.
E.g. all datum planes with an attribute "GSDDIR" and value "-X" (string) are moved to layer 20
I know how to move all datums to a specific layer, but now I strugling to improve this journal.
Any help will be very much appreciated
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Module move_all_datums_and_csys_to_specified_layer
Sub Main
Dim theSession As Session = Session.GetSession()
Dim WP as Part = theSession.Parts.Work
Dim objArray(0) As DisplayableObject
Dim strLayer As String
strLayer = 3
For Each obj As DisplayableObject In WP.Datums
If Not obj.IsBlanked AndAlso WP.Layers.GetState(obj.Layer) <> Layer.State.Hidden Then
objArray(0) = obj
WP.Layers.MoveDisplayableObjects(Val(strLayer), objArray)
End If
Next
End Sub
End Module
re: move datum plane based on attribute
Try the following code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "move datum plane layer"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
'specify layer for datum planes with specified attribute
Const dPlaneLayer As Integer = 20
Const attributeTitle As String = "GSDDIR"
Dim attributeValue As String
Dim targetValue As String = "-X"
'create list to hold datum planes with specified attribute
Dim myDatumPlanes As New List(Of DatumPlane)
For Each temp As TaggedObject In workPart.Datums
If TypeOf (temp) Is DatumPlane Then
Dim dPlane As DatumPlane = temp
'check for attribute
If dPlane.HasUserAttribute(attributeTitle, NXObject.AttributeType.String, -1) Then
attributeValue = dPlane.GetStringUserAttribute(attributeTitle, -1)
If attributeValue.ToUpper = targetValue.ToUpper Then
myDatumPlanes.Add(dPlane)
End If
End If
End If
Next
'move datum planes to specified layer
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.NewLayer = dPlaneLayer
displayModification1.Apply(myDatumPlanes.ToArray)
displayModification1.Dispose()
lw.Close()
End Sub
End Module
re: move datum plane based on attribute
Many Thanks!
That's exactly what I mean, it works fine.