UG nx layer setting journal

Hi

I have to write a journel to do layer setting for harness routing
(Electrical routing)
I dont have much knowledge in
creating journals.
I have a scenario where,
All the routing segments should be
moved to layer 230 and the colour should be changed to blue.

Stocks and solid objects
(connectors,terminal tags) should be
moved to layer 231 and colour should be green

Routing control points to layer 234 and colour to be white

Ports to 236 and colour white

Points to 235 and colour red

CSYS to 200 colour yellow

Legends(copyright curves) to 250 and colour to be brown.



Please help

What version of NX are you using?

It appears that you are using routing objects. I do not currently have access to a routing license to create such objects (therefore I would not be able to test any code against them); could you send (email) an example NX file that contains all the objects you would like moved to layers to:
info@nxjournaling.com?

Hi..
I'm on NX7.5
Sorry i could not upload any such files into this link . Uploading any .prt files in websites is banned in our work place.

Can you email an example file to the address given above? It doesn't have to be a production part (in fact, I prefer it NOT to be), but it does have to contain each of the object types that you want to move/manipulate.

I have sent a file which has all the components to mail.. pls check

Hello sri089,
Send me an email to carlo.daristotile@gmail.com .
I work with routing electrical and I have studied the NXOPEN routingelectrical namespace, so maybe I can help.
Thanks

Carlo Tony Daristotile

I have mailed. Pls have a look.

' hello sri089,
' Here is the solution
' EXCEPT FOR THIS "Legends(copyright curves) to 250 and colour to be brown."
' I did not see this in the 3D model

' NX 7.5.4.4
' Journal created by cdaristotile on Tue Oct 14 12:45:00 2014 E. South America Standard Time
' by Carlo Tony Daristotile
' carlo.daristotile@gmail.com
'

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal

' NXOpen.Body to layer 231 and colour green = 2
dim bdy_Col as integer = 2
dim bdy_Layer as integer = 231
' NXOpen.Point to layer 235 and colour red = 4
dim pt_Col as integer = 4
dim pt_Layer as integer = 235
' NXOpen.Routing.SplineSegment to layer 230 and colour blue = 1
dim rtSeg_Col as integer = 1
dim rtSeg_Layer as integer = 230
' NXOpen.Routing.Port to layer 236 and colour white = 7
dim rtPort_Col as integer = 7
dim rtPort_Layer as integer = 236
' NXOpen.Routing.ControlPoint to layer 234 and colour white = 7
dim rtContrlPt_Col as integer = 7
dim rtContrlPt_Layer as integer = 234
' NXOpen.CartesianCoordinateSystem to layer 200 and colour yellow = 6
dim rtCCS_Col as integer = 6
dim rtCCS_Layer as integer = 200

' Legends(copyright curves) to layer 250 and colour brown = 10

Sub Main

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

Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "routing-layers")

' ----------------------------------------------
' NXOpen.Body to layer 231 and colour green
' ----------------------------------------------

Dim myBodies() As Body
dim tempBody As Body
myBodies = workPart.Bodies.ToArray

For Each tempBody In myBodies
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = true
displayModification1.ApplyToOwningParts = true
displayModification1.NewColor = bdy_Col 'GREEN
displayModification1.NewLayer = bdy_Layer
Dim objects1(0) As DisplayableObject
objects1(0) = tempBody
displayModification1.Apply(objects1)
displayModification1.Dispose()
Next

' ----------------------------------------------
' NXOpen.Point to layer 235 and colour red
' ----------------------------------------------

Dim myPoints() As Point
dim tempPoint As Point
myPoints = workPart.Points.ToArray

For Each tempPoint In myPoints
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = false
displayModification1.ApplyToOwningParts = false
displayModification1.NewColor = pt_Col 'red
displayModification1.NewLayer = pt_Layer
Dim objects1(0) As DisplayableObject
objects1(0) = tempPoint
displayModification1.Apply(objects1)
displayModification1.Dispose()
Next

' ----------------------------------------------
' NXOpen.Routing.SplineSegment to layer 230 and colour blue
' ----------------------------------------------

Dim SplineSegmentCollection1 As Routing.SplineSegmentCollection
SplineSegmentCollection1 = workPart.SegmentManager.SplineSegments
Dim SplineSegments1() As Routing.SplineSegment = SplineSegmentCollection1.ToArray()

dim tempSplineSegment As Routing.SplineSegment

For Each tempSplineSegment In SplineSegments1
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = false
displayModification1.ApplyToOwningParts = false
displayModification1.NewColor = rtSeg_Col 'blue
displayModification1.NewLayer = rtSeg_Layer
Dim objects1(0) As DisplayableObject
objects1(0) = tempSplineSegment
displayModification1.Apply(objects1)
displayModification1.Dispose()
Next

' ----------------------------------------------
' NXOpen.Routing.Port to layer 236 and colour white
' ----------------------------------------------

Dim PortCollection1 as NXOpen.Routing.PortCollection
PortCollection1 = workPart.RouteManager.Ports
Dim Ports1() As Routing.Port = PortCollection1.ToArray()

dim tempPort As Routing.Port

For Each tempPort In Ports1
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = false
displayModification1.ApplyToOwningParts = false
displayModification1.NewColor = rtPort_Col 'white
displayModification1.NewLayer = rtPort_Layer
Dim objects1(0) As DisplayableObject
objects1(0) = tempPort
displayModification1.Apply(objects1)
displayModification1.Dispose()
Next

' ----------------------------------------------
' NXOpen.Routing.ControlPoint to layer 234 and colour white = 7
' ----------------------------------------------

Dim ControlPointCollection1 As NXOpen.Routing.ControlPointCollection
ControlPointCollection1 = workPart.RouteManager.ControlPoints
Dim ControlPoints1() As NXOpen.Routing.ControlPoint = ControlPointCollection1.ToArray()

dim tempControlPoint As Routing.ControlPoint

For Each tempControlPoint In ControlPoints1
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = false
displayModification1.ApplyToOwningParts = false
displayModification1.NewColor = rtContrlPt_Col 'white
displayModification1.NewLayer = rtContrlPt_Layer
Dim objects1(0) As DisplayableObject
objects1(0) = tempControlPoint
displayModification1.Apply(objects1)
displayModification1.Dispose()
Next

' ----------------------------------------------
' NXOpen.CartesianCoordinateSystem to layer 200 and colour yellow = 6
' ----------------------------------------------

dim CoordinateSystemCollection1 as CoordinateSystemCollection
CoordinateSystemCollection1 = workPart.CoordinateSystems
dim CoordinateSystems1() as CoordinateSystem = CoordinateSystemCollection1.ToArray

dim tempCoordinateSystem As CoordinateSystem

For Each tempCoordinateSystem In CoordinateSystems1
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = false
displayModification1.ApplyToOwningParts = false
displayModification1.NewColor = rtCCS_Col 'red
displayModification1.NewLayer = rtCCS_Layer
Dim objects1(0) As DisplayableObject
objects1(0) = tempCoordinateSystem
displayModification1.Apply(objects1)
displayModification1.Dispose()
Next

End Sub
End Module

Carlo Tony Daristotile

I'd like to suggest an optimization to the code above, if I may. The code above will loop through each body in the file, creating a new display modification object for each (creating, using, then destroying the display modification object for each body). While this approach works, it is a bit wasteful. The display modification object can act on an entire array of objects at once (assuming you want the same modification applied to all the objects, which is true in our case). Instead of changing the display of each body individually, we can modify all the bodies in one pass.

As an example, let's look at the body objects:

The body objects are being processed one by one in the For loop. Each time through the loop, a display modification object is created, used, and destroyed.


Dim myBodies() As Body
Dim tempBody As Body
myBodies = workPart.Bodies.ToArray

For Each tempBody In myBodies
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = True
displayModification1.NewColor = bdy_Col 'GREEN
displayModification1.NewLayer = bdy_Layer
Dim objects1(0) As DisplayableObject
objects1(0) = tempBody
displayModification1.Apply(objects1)
displayModification1.Dispose()
Next

The code above can be simplified to apply the modification to all the bodies in one call:


Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = True
displayModification1.NewColor = bdy_Col 'GREEN
displayModification1.NewLayer = bdy_Layer
displayModification1.Apply(workPart.Bodies.ToArray)
displayModification1.Dispose()

This change eliminates the need for the For loop and some variables; it will also run faster since only one "displayModification1" object is created and used. A similar change can be made for the other object types (points, ports, etc).

Hello NxJournaling,
Thanks for the optimization.
Is ... Dim objects1() as .... Still required?

Carlo Tony Daristotile

If you are using the compiler option:
Option Strict Off
at the top of your code, then you can get rid of the objects1() array; the compiler will convert the body objects to displayable objects for you. This conversion works because the Body class inherits from the DisplayableObject class.

Should you use Option Strict On, the compiler won't convert types for you in the background and you will have to explicitly cast the Body to a DisplayableObject. In this case, you'd probably do the type conversion and hold the results in an array such as objects1() and then use that in the display modification.

' NX 7.5.4.4
' Journal created by cdaristotile on Tue Oct 14 12:45:00 2014 E. South America Standard Time
'
' carlo.daristotile@gmail.com
' 2014-10-17
'

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal

' NXOpen.Body to layer 231 and colour green = 2
dim bdy_Col as integer = 2
dim bdy_Layer as integer = 231
' NXOpen.Point to layer 235 and colour red = 4
dim pt_Col as integer = 4
dim pt_Layer as integer = 235
' NXOpen.Routing.SplineSegment to layer 230 and colour blue = 1
dim rtSeg_Col as integer = 1
dim rtSeg_Layer as integer = 230
' NXOpen.Routing.Port to layer 236 and colour white = 7
dim rtPort_Col as integer = 7
dim rtPort_Layer as integer = 236
' NXOpen.Routing.ControlPoint to layer 234 and colour white = 7
dim rtContrlPt_Col as integer = 7
dim rtContrlPt_Layer as integer = 234
' NXOpen.CartesianCoordinateSystem to layer 200 and colour yellow = 6
dim rtCCS_Col as integer = 6
dim rtCCS_Layer as integer = 200

' Legends(copyright curves) to layer 250 and colour brown = 10

Sub Main

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

Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "routing-layers")

' ----------------------------------------------
' NXOpen.Body to layer 231 and colour green
' ----------------------------------------------

Dim displayModification2 As DisplayModification
displayModification2 = theSession.DisplayManager.NewDisplayModification()
displayModification2.ApplyToAllFaces = true
displayModification2.ApplyToOwningParts = true
displayModification2.NewColor = bdy_Col 'GREEN
displayModification2.NewLayer = bdy_Layer
displayModification2.Apply(workPart.Bodies.ToArray)
displayModification2.Dispose()

' ----------------------------------------------
' NXOpen.Point to layer 235 and colour red
' ----------------------------------------------

Dim displayModification3 As DisplayModification
displayModification3 = theSession.DisplayManager.NewDisplayModification()
displayModification3.ApplyToAllFaces = false
displayModification3.ApplyToOwningParts = false
displayModification3.NewColor = pt_Col 'red
displayModification3.NewLayer = pt_Layer
displayModification3.Apply(workPart.Points.ToArray)
displayModification3.Dispose()

' ----------------------------------------------
' NXOpen.Routing.SplineSegment to layer 230 and colour blue
' ----------------------------------------------

Dim SplineSegmentCollection1 As Routing.SplineSegmentCollection
SplineSegmentCollection1 = workPart.SegmentManager.SplineSegments

Dim displayModification4 As DisplayModification
displayModification4 = theSession.DisplayManager.NewDisplayModification()
displayModification4.ApplyToAllFaces = false
displayModification4.ApplyToOwningParts = false
displayModification4.NewColor = rtSeg_Col 'blue
displayModification4.NewLayer = rtSeg_Layer
displayModification4.Apply(SplineSegmentCollection1.ToArray())
displayModification4.Dispose()

' ----------------------------------------------
' NXOpen.Routing.Port to layer 236 and colour white
' ----------------------------------------------

Dim PortCollection1 as NXOpen.Routing.PortCollection
PortCollection1 = workPart.RouteManager.Ports

Dim displayModification5 As DisplayModification
displayModification5 = theSession.DisplayManager.NewDisplayModification()
displayModification5.ApplyToAllFaces = false
displayModification5.ApplyToOwningParts = false
displayModification5.NewColor = rtPort_Col 'white
displayModification5.NewLayer = rtPort_Layer
displayModification5.Apply(PortCollection1.ToArray())
displayModification5.Dispose()

' ----------------------------------------------
' NXOpen.Routing.ControlPoint to layer 234 and colour white = 7
' ----------------------------------------------

Dim ControlPointCollection1 As NXOpen.Routing.ControlPointCollection
ControlPointCollection1 = workPart.RouteManager.ControlPoints

Dim displayModification6 As DisplayModification
displayModification6 = theSession.DisplayManager.NewDisplayModification()
displayModification6.ApplyToAllFaces = false
displayModification6.ApplyToOwningParts = false
displayModification6.NewColor = rtContrlPt_Col 'white
displayModification6.NewLayer = rtContrlPt_Layer
displayModification6.Apply(ControlPointCollection1.ToArray())
displayModification6.Dispose()

' ----------------------------------------------
' NXOpen.CartesianCoordinateSystem to layer 200 and colour yellow = 6
' ----------------------------------------------

dim CoordinateSystemCollection1 as CoordinateSystemCollection
CoordinateSystemCollection1 = workPart.CoordinateSystems

Dim displayModification7 As DisplayModification
displayModification7 = theSession.DisplayManager.NewDisplayModification()
displayModification7.ApplyToAllFaces = false
displayModification7.ApplyToOwningParts = false
displayModification7.NewColor = rtCCS_Col 'red
displayModification7.NewLayer = rtCCS_Layer
displayModification7.Apply(CoordinateSystemCollection1.ToArray)
displayModification7.Dispose()

End Sub
End Module

Carlo Tony Daristotile

Hi Carlo,

Thanks for the help. This code works fine.

Few Spline Extension in layer 1 still exists,Is it possible to move this to Layer 235 and change the colour to white.
In addition to the above layers setting requirements ,I have to move the components to layer 230 and colour white.
I tried the below code

' ----------------------------------------------
' NXOpen.component to layer 230 and colour white
' ----------------------------------------------

Dim displayModification8 As DisplayModification
displayModification8 = theSession.DisplayManager.NewDisplayModification()
displayModification8.ApplyToAllFaces = true
displayModification8.ApplyToOwningParts = true
displayModification8.NewColor = cmp_Col 'white
displayModification8.NewLayer = cmp_Layer
displayModification8.Apply(componentCollection1.ToArray())
displayModification8.Dispose()

But facing below error
"Name'componentcollection1'is not declared"

Thanks in advance

Regards,
Sri

The author of the website shows you how to get the components

http://www.nxjournaling.com/content/creating-subroutine-process-all-comp...

Carlo Tony Daristotile

Hi Journal Developers,

I have modified the current journal from online.currently, this Journal goes over the assembly components and makes each component as a display part. I need line of code to change the current layer of the display part to different layer or specific layer.Or to insert the code instead of the msgbox below. Any help is appreciated.Thank You.

***********************************************************************
msgbox(c.DisplayName())
***********************************************************************

Option Strict On
Imports System
Imports System.IO
Imports System.Collections
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.Drawings
Imports NXOpen.UF
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim ufSession As UFSession = ufSession.GetUFSession()
Dim prototype As Part
Sub Main()
System.Diagnostics.Debugger.Launch()
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine("Listing child components")
Try
Dim part1 As Part = theSession.Parts.Work
Dim origPart As Part = part1
theSession.ListingWindow.WriteLine("Work part: " & part1.FullPath)
theSession.ListingWindow.WriteLine(part1.Name)
Dim c As ComponentAssembly = part1.ComponentAssembly
max(c.RootComponent, 0)
Dim partLoadStat As PartLoadStatus
theSession.Parts.SetDisplay(origPart, False, False, partLoadStat)
Catch e As Exception
theSession.ListingWindow.WriteLine("Error running application: " & e.Message)
End Try
End Sub
Sub max(ByVal c As Component, ByVal level As Integer)
Dim children As Component() = c.GetChildren()
Dim child As Component
prototype = CType(c.Prototype, Part)
Dim partLoadStat As PartLoadStatus
Dim displayPart As Part
theSession.Parts.SetDisplay(prototype, False, False, partLoadStat)
displayPart = theSession.Parts.Display
***********************************************************************
msgbox(c.DisplayName())

***********************************************************************
For Each child In children
max(child, level + 1)
Next
End Sub
End module

Raeed Kena
{Mechanical / Civil Engineer}

Never mind, I think it is not possible to move the displayed part to a specific layer. I created a journal to move the component to a specific layer instead.

Raeed Kena
{Mechanical / Civil Engineer}

To check what is possible and what is not try to record journal in NX and see what code you get.
I had same problems in the beginning to understand difference beteween prototype, part and component but I got help here and I was guided to SNAP docu. While you cant use functionality of SNAP without author license, this docu contains good explanation of structure.

https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx...

Thank You For your respond.

In NX when I tried to move the displayed part into specific layer did not work. So nothing to record because the original function doesn't exist. You can move any of the features under the displayed part only. The logic here is moving the component to the specific layer without the need to make display part.

Raeed Kena
{Mechanical / Civil Engineer}