Hello All,
I am a NX designer and new to this forum.
I am trying to create a journal to create specific named categories according to my company spec. Each category need to contain a specific layer in that.
There are almost 15 categories I need to create and move corresponding layers to those.
Eg: Layer 30 should contain all trim planes and need to be under category _TRIM_PLANES
(*designer need to move manually trim planes to layer 30 while designing, no journal required for that).
I have succeeded to create the journal; but the issue is, journal is working for new files only (* for new files no _TRIM_PLANES category present in initial default status).
When I run this journal for an existing file (*that file may already contain some of the desired layers created by previous user), I am getting below error.
" NXOPEN.NXEception: The category name already exists. Specify a new category Name.
at NXOpen.NXobject.SetName(String name)
at NXjournal.Main(String[]args) in C:Temp\xxxxx\NXjournals6900\journal.vb:line50 "
So I need to modify something like, If category _TRIM_PLANES already present, END creating _TRIM_PLANES category and proceed to next step.
I am not sure how to add this "CHECK and ENDIf stratergy" before a particular action line.
Please help
Thanks
Cool_Designer
re: create category
The code below checks the current work part for all the defined layer categories and stores the category names in a list. It then attempts to create a layer category; if the name is in the list it already exists in the work part and it skips the category.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module create_standard_categories
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
If IsNothing(theSession.Parts.BaseWork) 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 = "Create layer categories"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim existingLayerCategories As New List(Of String)
For Each temp As Layer.Category In workPart.LayerCategories
If temp.Name = "ALL" Then
'skip the ALL category
Continue For
End If
existingLayerCategories.Add(temp.Name)
Next
'create standard layer categories
'repeat for other desired categories
Dim catName As String = "_TRIM_PLANES"
Dim catLayer As Integer = 30
If existingLayerCategories.Contains(catName) Then
'skip this one, it already exists
'write note to info window for debugging
'lw.WriteLine("category exists")
Else
workPart.LayerCategories.CreateCategory(catName, "trim planes", {catLayer})
End If
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Thanks...It worked well
Thanks...It worked well