Submitted by lorenzo_ghizzoni on Wed, 09/07/2016 - 01:38
Forums:
Hi,
i have to create new layers in many existing parts
someone could help me to create a journal to make this ?
i have the list of the layers, but i don't know how to import in my existig part
Thanks
re: layer settings
Are you talking about creating layer categories, changing the layer status (work layer, visible only, etc) or both?
You say that you "have a list of the layers" - in what form do you have this list (a text file, a spreadsheet, an existing part file, etc)?
Creating a layer category is fairly easy, see the following thread for a simple example:
http://nxjournaling.com/comment/3707#comment-3707
Layer settings
I'm talking about creating layer categories.
I have a text file but also an existing part file with the correct layers
re: layer settings
Can you post an example entry of your text file? If it has a well-defined structure (such as a CSV file), we can read the text file, parse out the values and create the layer categories in the NX part file.
Alternately, we could read the example file and re-create the layer categories in the target file.
Do you have a preference?
Layer Settings
This is my text file, i think it's not correct as a CSV file, but is simple to create from this ..
1 Axis
2-24 Mold inserts
25-49 Mold frames
50-59 Vents
60-69 Cooling inserts
70-79 Cooling lines
80-89 Ejector Plate and pins
100-119 Cores
120-139 Core box inserts
140-149 Core box frames
150-159 Blow tubes
160-169 Hydraulic or mechanic movers
170-179 NK’s
200-209 Ejection pins
210-219 Screws, washers and bolts
220-250 Sketches
231-250 Construction geometry
251-256 WNC models and transition surfaces.
I think it's better from a file, so I can simply change the file as needed
Anyway the better way is the simplest way !
re: layer categories from file
The code below will prompt for a text file and attempt to parse the information and create layer categories in the current work part. The input file needs to have the following formatting:
{layer|layer range}:{category name}
So the input would be very similar to what is shown in your post above (note that there needs to be a colon (:) between the layer(s) and category name.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.Text.RegularExpressions
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "layer categories from file")
lw.Open()
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 1
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = DialogResult.OK Then
Dim line As String
Dim delim As Char() = {":"c}
Dim layerList As New List(Of Integer)
Using sr As IO.StreamReader = New IO.StreamReader(openFileDialog1.FileName)
'line = sr.ReadLine()
'Do While Not line Is Nothing
Do
layerList.Clear()
line = sr.ReadLine()
If IsNothing(line) Then
Exit Do
End If
If Not line.Contains(delim) Then
Continue Do
End If
Dim strings As String() = line.Split(delim)
'strings(0) = category layer range
'strings(1) = category name
Dim layers() As String = Nothing
Dim layerRangeStart As Integer = Nothing
Dim layerRangeEnd As Integer = Nothing
If strings(0).Contains("-") Then
'string represents a range of layers
'e.g. "220-250: Sketches"
layers = strings(0).Split("-"c)
Dim rangeParsed As Boolean = False
If Not Integer.TryParse(layers(0), layerRangeStart) Then
'could not parse string to integer, skip this entry
Continue Do
End If
If Not Integer.TryParse(layers(1), layerRangeEnd) Then
'could not parse string to integer, skip this entry
Continue Do
End If
For i As Integer = layerRangeStart To layerRangeEnd
layerList.Add(i)
Next
Else
'string represents a single layer
'e.g. "1: Solid"
If Not Integer.TryParse(strings(0), layerRangeStart) Then
'could not parse string to integer
Continue Do
End If
layerList.Add(layerRangeStart)
End If
'strip potentially problematic characters from the layer category name
Dim layerCatName As String = strings(1).Trim
layerCatName = Regex.Replace(layerCatName, " ", "_")
layerCatName = Regex.Replace(layerCatName, "\W", "")
If String.IsNullOrWhiteSpace(layerCatName) Then
'layer name cannot be an empty string
Continue Do
End If
'create the layer category
Dim category1 As Layer.Category
category1 = theSession.Parts.Work.LayerCategories.CreateCategory(layerCatName, "", layerList.ToArray)
'line = sr.ReadLine()
'Loop
Loop Until line Is Nothing
End Using
End If
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Actif Work Layer ?
Hello,
I need to know what is the WorkLayer in a part.
I use this code from GTAC (nx_api3102) but he dosn't work.
You can help me ?
Regards!
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Module demo_different_enum_values_for_layer_status
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Sub Main()
Echo("UF Session Values: ")
Echo("UF_LAYER_WORK_LAYER: " & _
UFConstants.UF_LAYER_WORK_LAYER.ToString())
Echo(" ")
Echo("Session Values: ")
Echo("NXOpen.Layer.State.WorkLayer: " & _
NXOpen.Layer.State.WorkLayer)
End Sub
Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
Pat
re: work layer
The GTAC code is simply printing out the value of previously defined constants; it is not looking at the current work layer. It is working correctly, it is simply not designed to do what you are looking for.
The code below will display the work part and work layer information to the listing window.
Option Strict Off
Imports System
Imports NXOpen
Module Module73
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
lw.WriteLine("work part: " & theSession.Parts.Work.FullPath)
lw.WriteLine("work layer: " & theSession.Parts.Work.Layers.WorkLayer.ToString)
lw.Close()
End Sub
End Module
Is it possible to extract the layer number from an object ?
Hi,
Is it possible to extract the layer number from an object in modeling?
I searched on Gtac and here, but I can not find an example.
http://www.nxjournaling.com/content/add-features-group
Finally, I want to query each object in modeling (extrude, datum, sketch, curve, body ...ect),
if this object is on a layer "X", I want to add it in an array list and finally
I want to take all the elements of the list to insert into a new group or an existing group.
I can create the goup, but I can't get the no layer objects ... I tried several ways.
Regards!
Pat
re: layers from objects
"Is it possible to extract the layer number from an object in modeling?"
Yes! Every geometric object (such as bodies, curves, datums, etc) have a .Layer property that you can query or change as desired. The code here:
http://nxjournaling.com/comment/362#comment-362
shows how to iterate through all the curve objects in the part, check the layer, and if the layer number matches the given target, add the curve to a list and later delete all the curves in the list.