Hello Everyone
I just customized a journal to open a part with specific revision, get all the objects count on layer (1) and move all to layer 180.
I am getting a "reference not found, null exception". Can you please help me debug this script.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim answer as String
dim layerNumber as Integer = 1
dim i as Integer = 0
Dim lw As ListingWindow = theSession.ListingWindow
Dim allObjects as NXObject()
Dim pointObject as Point
Dim myPoints as DisplayableObject()
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
'open a part with revision
Dim BasePart1 as BasePart
BasePart1 = theSeesion.Parts.OpenBseDisplay("@DB/AB0000123/R000"",PartLoadStatus1)
allObjects = workPart.Layers.GetAllObjectsOnLayer(layerNumber)
lw.Open
for each someObject as NXObject in allObjects
redim preserve myPoints(i)
myPoints(i) = someObject
i += 1
next
'move or copy object to another layer using the layer manager
'workPart.Layers.MoveDisplayableObjects(4, myPoints)
workPart.Layers.CopyObjects(180, myPoints)
With displayModification1
'move layers with a display modification
.NewLayer = 180
.Apply(myPoints)
.Dispose
End With
End Sub
End Module
re: display modification
You've opened a new part, BasePart1, but the rest of your code references the "workPart" variable, which probably does not reference the same part as BasePart1.
workpart = basepart1
even if replacing the workpart with basepart1 is not solving the problem. I am still getting the null reference issue.
re: display modification
Which line of code is indicated as throwing the error?
Also, why are you copying AND moving the objects to the new layer?
re: typo
If the code above is an exact copy of what you are running, you should note that "Session" is misspelled in the following line:
BasePart1 = theSeesion.Parts.OpenBseDisplay("@DB/AB0000123/R000"",PartLoadStatus1)
Such a typo could lead to a "null reference" error.
typo
movedisplayable object is commented already and not getting executed
am getting error exactly on this line:
allObjects = workPart.Layers.GetAllObjectsOnLayer(layerNumber)
I understand that we are not working on workPart but basepart. What code is to be written so that i get all the objects on Layer 1 for part loaded @DB/AB0000123/R000
re: display modification
"movedisplayable object is commented already and not getting executed"
I understand that. I was commenting on the call to .CopyObjects and the use of the displayModification to move the objects to a new layer.
Rather than using the "workPart" variable, use the new variable that you have created:
allObjects = BasePart1.Layers.GetAllObjectsOnLayer(layerNumber)
Or, after opening the new part, update the workPart variable to point to the newly opened part.
basePart1
Done that already, still get the same error
"object reference not set to an instance of an object"
I am attempting to do the following:
1. I have an excel sheet with partname/rev data which I load in NX
2. Move all objects from Layer 1 to 180
3. Close Part and load next (again perform step 2)
re: display modification
"Done that already, still get the same error"
Done what, exactly? Did you fix the misspelled keywords and update the reference to the work part? Or something else?
What does your current code look like?
code
See the code below. I am getting this data from an excel, where I have ItemName/Rev, Source Layer, Target Layer, Object found on Source Layer, Objects found on Target Layer
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Strict Off
Imports System
Imports NXOpen
Imports System.IO
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpenUI
Module ChangeLayer
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
Dim sPartIDFile = "C:\LayerChange_PartIDs.xlsx"
Dim theUISession As UI = UI.GetUI
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "journal")
Dim iRowCounter : Dim sTextPart : Dim iLayerNumberSource : Dim iLayerNumberTarget
dim i as Integer = 0
Dim allObjects as NXObject()
Dim myPoints as DisplayableObject()
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
'create Excel object
Dim objExcel = CreateObject("Excel.Application")
If objExcel Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not start Excel, journal exiting")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
'open Excel file
Dim objWorkbook = objExcel.Workbooks.Open(sPartIDFile)
If objWorkbook Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not open Excel file: " & sPartIDFile & ControlChars.NewLine & "journal exiting.")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
Dim objWorksheet = objWorkbook.Worksheets(1)
Dim iExcelRowCount = objWorksheet.UsedRange.Rows.Count
For iRowCounter = 2 to iExcelRowCount
'open part file with rev
sTextPart = "@DB/" & objExcel.Cells(iRowCounter ,1).Value
iLayerNumberSource = objExcel.Cells(iRowCounter ,2).Value
iLayerNumberTarget = objExcel.Cells(iRowCounter ,3).Value
basePart1 = theSession.Parts.OpenBaseDisplay(sTextPart , partLoadStatus1)
partLoadStatus1.Dispose()
'perform layer change
allObjects = workPart.Layers.GetAllObjectsOnLayer(iLayerNumberSource)
for each someObject as NXObject in allObjects
redim preserve myPoints(i)
myPoints(i) = someObject
i += 1
next
objExcel.Cells(iRowCounter ,4).Value = myPoints.Length
'move or copy object to another layer using the layer manager
workPart.Layers.MoveDisplayableObjects(iLayerNumberTarget, myPoints)
'workPart.Layers.CopyObjects(5, myPoints)
allObjects = workPart.Layers.GetAllObjectsOnLayer(iLayerNumberTarget)
for each someObject as NXObject in allObjects
redim preserve myPoints(i)
myPoints(i) = someObject
i += 1
next
objExcel.Cells(iRowCounter ,5).Value = myPoints.Length
Next
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
re: display modification
Here's some code that seems to work (for me, at least - I'm running native NX).
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
'Imports System.IO
'Imports System.Windows.Forms
'Imports System.Drawing
'Imports System.Drawing.Imaging
'Imports System.Runtime.InteropServices
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpenUI
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim sPartIDFile = "C:\LayerChange_PartIDs.xlsx"
'Dim sPartIDFile = "C:\Temp\LayerChange_PartIDs.xlsx"
Dim theUISession As UI = UI.GetUI
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "journal")
Dim iRowCounter : Dim iLayerNumberSource : Dim iLayerNumberTarget As Integer
Dim sTextPart As String
'create Excel object
Dim objExcel = CreateObject("Excel.Application")
If objExcel Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not start Excel, journal exiting")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
'open Excel file
Dim objWorkbook = objExcel.Workbooks.Open(sPartIDFile)
If objWorkbook Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not open Excel file: " & sPartIDFile & ControlChars.NewLine & "journal exiting.")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
Dim objWorksheet = objWorkbook.Worksheets(1)
Dim iExcelRowCount = objWorksheet.UsedRange.Rows.Count
Dim firstRow As Integer = objWorksheet.usedrange.rows(1).row
Dim lastRow As Integer = objWorksheet.usedrange.rows(objWorksheet.usedrange.rows.count).row
'MsgBox("firstRow: " & firstRow.ToString & ControlChars.NewLine & _
' "lastRow: " & lastRow.ToString)
For iRowCounter = firstRow To lastRow
Dim i As Integer = 0
Dim myPoints As DisplayableObject()
Dim allObjects As NXObject()
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
Dim objsOnLayer As New List(Of DisplayableObject)
'open part file with rev
sTextPart = "@DB/" & objExcel.Cells(iRowCounter, 1).Value
'sTextPart = objExcel.Cells(iRowCounter, 1).Value
iLayerNumberSource = objExcel.Cells(iRowCounter, 2).Value
iLayerNumberTarget = objExcel.Cells(iRowCounter, 3).Value
basePart1 = theSession.Parts.OpenBaseDisplay(sTextPart, partLoadStatus1)
partLoadStatus1.Dispose()
workPart = basePart1
'perform layer change
allObjects = workPart.Layers.GetAllObjectsOnLayer(iLayerNumberSource)
For Each temp As NXObject In allObjects
Dim tempDispObj As DisplayableObject = TryCast(temp, DisplayableObject)
If Not IsNothing(tempDispObj) Then
objsOnLayer.Add(tempDispObj)
End If
Next
With displayModification1
'move layers with a display modification
.NewLayer = iLayerNumberTarget
.Apply(objsOnLayer.ToArray)
.Dispose()
End With
Next
End Sub
End Module
re: display modification
The variables "i" and "myPoints" should be reset each time through the For loop; one way to do that is to declare them inside the For loop.
After you open the new part, you need to update the "workPart" variable to point to it OR use the "basePart1" reference instead of "workPart".
I'll keep looking, but those are the things that immediately caught my attention.
Perfecto!!
Amazing. It worked like a charm. I added few lines of code to close the loose ends.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpenUI
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim sPartIDFile = "C:\LayerChange_PartIDs.xlsx"
'Dim sPartIDFile = "C:\Temp\LayerChange_PartIDs.xlsx"
Dim theUISession As UI = UI.GetUI
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "journal")
Dim iRowCounter : Dim iLayerNumberSource : Dim iLayerNumberTarget As Integer
Dim sTextPart As String
'create Excel object
Dim objExcel = CreateObject("Excel.Application")
If objExcel Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not start Excel, journal exiting")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
'open Excel file
Dim objWorkbook = objExcel.Workbooks.Open(sPartIDFile)
If objWorkbook Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not open Excel file: " & sPartIDFile & ControlChars.NewLine & "journal exiting.")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
Dim objWorksheet = objWorkbook.Worksheets(1)
Dim iExcelRowCount = objWorksheet.UsedRange.Rows.Count
Dim firstRow As Integer = objWorksheet.usedrange.rows(2).row
Dim lastRow As Integer = objWorksheet.usedrange.rows(objWorksheet.usedrange.rows.count).row
'MsgBox("firstRow: " & firstRow.ToString & ControlChars.NewLine & _
' "lastRow: " & lastRow.ToString)
For iRowCounter = firstRow To lastRow
Dim i As Integer = 0
Dim myPoints As DisplayableObject()
Dim allObjects As NXObject()
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
Dim objsOnLayer As New List(Of DisplayableObject)
'open part file with rev
sTextPart = "@DB/" & objExcel.Cells(iRowCounter, 1).Value
'sTextPart = objExcel.Cells(iRowCounter, 1).Value
iLayerNumberSource = objExcel.Cells(iRowCounter, 2).Value
iLayerNumberTarget = objExcel.Cells(iRowCounter, 3).Value
basePart1 = theSession.Parts.OpenBaseDisplay(sTextPart, partLoadStatus1)
partLoadStatus1.Dispose()
workPart = basePart1
'perform layer change
allObjects = workPart.Layers.GetAllObjectsOnLayer(iLayerNumberSource)
For Each temp As NXObject In allObjects
Dim tempDispObj As DisplayableObject = TryCast(temp, DisplayableObject)
If Not IsNothing(tempDispObj) Then
objsOnLayer.Add(tempDispObj)
End If
Next
'set source layer objs
objExcel.Cells(iRowCounter, 4).Value = objsOnLayer.Count
Dim iSourceObjs = objsOnLayer.Count
With displayModification1
'move layers with a display modification
.NewLayer = iLayerNumberTarget
.Apply(objsOnLayer.ToArray)
.Dispose()
End With
allObjects = workPart.Layers.GetAllObjectsOnLayer(iLayerNumberSource)
For Each temp As NXObject In allObjects
Dim tempDispObj As DisplayableObject = TryCast(temp, DisplayableObject)
If Not IsNothing(tempDispObj) Then
objsOnLayer.Add(tempDispObj)
End If
Next
'set target layer objs
objExcel.Cells(iRowCounter, 5).Value = objsOnLayer.Count
Dim iTargetObjs = objsOnLayer.Count
'get the final status
If iSourceObjs = iTargetObjs Then
objExcel.Cells(iRowCounter, 6).Value = "PASS" : objExcel.Cells(iRowCounter, 6).Interior.ColorIndex = 4 'Green
Else
objExcel.Cells(iRowCounter, 6).Value = "FAIL" : objExcel.Cells(iRowCounter, 6).Interior.ColorIndex = 3 'Red
End If
Next
objWorkbook.Save()
objWorkbook.Close()
objExcel.Quit()
End Sub
End Module
Now my query is, to gracefully close the part with saving and make the sourcelayer as visible layer. Can you help me out here as I could not find the code in this forum.
NX Journal
I could work out code for following:
- Closing a part file if already opened
-Save the Part file
#The only query is to set a layer as active/work layer.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpenUI
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim sPartIDFile = "C:\LayerChange_PartIDs.xlsx"
'Dim sPartIDFile = "C:\Temp\LayerChange_PartIDs.xlsx"
Dim theUISession As UI = UI.GetUI
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "journal")
Dim iRowCounter : Dim iLayerNumberSource : Dim iLayerNumberTarget As Integer
Dim sTextPart As String
try
'close any opened part/assy
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Close Part")
workPart.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.UseResponses, Nothing)
Catch ex As Exception
'If a part is already opened, perform action here
End Try
'create Excel object
Dim objExcel = CreateObject("Excel.Application")
If objExcel Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not start Excel, journal exiting")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
'open Excel file
Dim objWorkbook = objExcel.Workbooks.Open(sPartIDFile)
If objWorkbook Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not open Excel file: " & sPartIDFile & ControlChars.NewLine & "journal exiting.")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
Dim objWorksheet = objWorkbook.Worksheets(1)
Dim iExcelRowCount = objWorksheet.UsedRange.Rows.Count
Dim firstRow As Integer = objWorksheet.usedrange.rows(2).row
Dim lastRow As Integer = objWorksheet.usedrange.rows(objWorksheet.usedrange.rows.count).row
'MsgBox("firstRow: " & firstRow.ToString & ControlChars.NewLine & _
' "lastRow: " & lastRow.ToString)
For iRowCounter = firstRow To lastRow
Dim i As Integer = 0
Dim myPoints As DisplayableObject()
Dim allObjects As NXObject()
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
Dim objsOnLayer As New List(Of DisplayableObject)
'open part file with rev
sTextPart = "@DB/" & objExcel.Cells(iRowCounter, 1).Value
'sTextPart = objExcel.Cells(iRowCounter, 1).Value
iLayerNumberSource = objExcel.Cells(iRowCounter, 2).Value
iLayerNumberTarget = objExcel.Cells(iRowCounter, 3).Value
basePart1 = theSession.Parts.OpenBaseDisplay(sTextPart, partLoadStatus1)
partLoadStatus1.Dispose()
workPart = basePart1
'perform layer change
allObjects = workPart.Layers.GetAllObjectsOnLayer(iLayerNumberSource)
For Each temp As NXObject In allObjects
Dim tempDispObj As DisplayableObject = TryCast(temp, DisplayableObject)
If Not IsNothing(tempDispObj) Then
objsOnLayer.Add(tempDispObj)
End If
Next
'set source layer objs
objExcel.Cells(iRowCounter, 4).Value = objsOnLayer.Count
Dim iSourceObjs = objsOnLayer.Count
With displayModification1
'move layers with a display modification
.NewLayer = iLayerNumberTarget
.Apply(objsOnLayer.ToArray)
.Dispose()
End With
allObjects = workPart.Layers.GetAllObjectsOnLayer(iLayerNumberSource)
For Each temp As NXObject In allObjects
Dim tempDispObj As DisplayableObject = TryCast(temp, DisplayableObject)
If Not IsNothing(tempDispObj) Then
objsOnLayer.Add(tempDispObj)
End If
Next
'set target layer objs
objExcel.Cells(iRowCounter, 5).Value = objsOnLayer.Count
Dim iTargetObjs = objsOnLayer.Count
'get the final status
If iSourceObjs = iTargetObjs Then
objExcel.Cells(iRowCounter, 6).Value = "PASS" : objExcel.Cells(iRowCounter, 6).Interior.ColorIndex = 4 'Green
Else
objExcel.Cells(iRowCounter, 6).Value = "FAIL" : objExcel.Cells(iRowCounter, 6).Interior.ColorIndex = 3 'Red
End If
'save work part
Dim partSaveStatus1 As PartSaveStatus
partSaveStatus1 = workPart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False)
partSaveStatus1.Dispose()
workPart.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.UseResponses, Nothing)
Next
objWorkbook.Save()
objWorkbook.Close()
objExcel.Quit()
workPart = Nothing
End Sub
End Module
final script
Hi.
Thanks a lot for all the inputs. Finally my script is complete. Do let me know If you have any suggestions as well
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpenUI
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim sPartIDFile = "C:\LayerChange_PartIDs.xlsx"
'Dim sPartIDFile = "C:\Temp\LayerChange_PartIDs.xlsx"
Dim theUISession As UI = UI.GetUI
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "journal")
Dim iRowCounter : Dim iLayerNumberSource : Dim iLayerNumberTarget As Integer
Dim sTextPart As String
try
'close any opened part/assy
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Close Part")
workPart.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.UseResponses, Nothing)
Catch ex As Exception
'If a part is already opened, perform action here
End Try
'create Excel object
Dim objExcel = CreateObject("Excel.Application")
If objExcel Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not start Excel, journal exiting")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
'open Excel file
Dim objWorkbook = objExcel.Workbooks.Open(sPartIDFile)
If objWorkbook Is Nothing Then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not open Excel file: " & sPartIDFile & ControlChars.NewLine & "journal exiting.")
theSession.UndoToMark(markId1, "journal")
Exit Sub
End If
Dim objWorksheet = objWorkbook.Worksheets(1)
Dim iExcelRowCount = objWorksheet.UsedRange.Rows.Count
Dim firstRow As Integer = objWorksheet.usedrange.rows(2).row
Dim lastRow As Integer = objWorksheet.usedrange.rows(objWorksheet.usedrange.rows.count).row
'MsgBox("firstRow: " & firstRow.ToString & ControlChars.NewLine & _
' "lastRow: " & lastRow.ToString)
For iRowCounter = firstRow To lastRow
Dim i As Integer = 0
Dim myPoints As DisplayableObject()
Dim allObjects As NXObject()
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
Dim objsOnLayer As New List(Of DisplayableObject)
'open part file with rev
sTextPart = "@DB/" & objExcel.Cells(iRowCounter, 1).Value
'sTextPart = objExcel.Cells(iRowCounter, 1).Value
iLayerNumberSource = objExcel.Cells(iRowCounter, 2).Value
iLayerNumberTarget = objExcel.Cells(iRowCounter, 3).Value
basePart1 = theSession.Parts.OpenBaseDisplay(sTextPart, partLoadStatus1)
partLoadStatus1.Dispose()
workPart = basePart1
'perform layer change
allObjects = workPart.Layers.GetAllObjectsOnLayer(iLayerNumberSource)
For Each temp As NXObject In allObjects
Dim tempDispObj As DisplayableObject = TryCast(temp, DisplayableObject)
If Not IsNothing(tempDispObj) Then
objsOnLayer.Add(tempDispObj)
End If
Next
'set source layer objs
objExcel.Cells(iRowCounter, 4).Value = objsOnLayer.Count
Dim iSourceObjs = objsOnLayer.Count
Try
'Move objects to Target Layer
With displayModification1
'move layers with a display modification
.NewLayer = iLayerNumberTarget
.Apply(objsOnLayer.ToArray)
.Dispose()
End With
objExcel.Cells(iRowCounter, 6).Value = "PASS" : objExcel.Cells(iRowCounter, 6).Interior.ColorIndex = 4 'Green
Catch ex As Exception
msgbox (ex.Message)
objExcel.Cells(iRowCounter, 6).Value = "FAIL" : objExcel.Cells(iRowCounter, 6).Interior.ColorIndex = 3 'Red
End Try
'Count Objs on Target Layer
allObjects = workPart.Layers.GetAllObjectsOnLayer(iLayerNumberTarget)
For Each temp As NXObject In allObjects
Dim tempDispObj As DisplayableObject = TryCast(temp, DisplayableObject)
If Not IsNothing(tempDispObj) Then
objsOnLayer.Add(tempDispObj)
End If
Next
'set target layer objs
objExcel.Cells(iRowCounter, 5).Value = objsOnLayer.Count
Dim iTargetObjs = objsOnLayer.Count
'Set Target Layer as work layer
Dim markID10 As Session.UndoMarkId
markID10 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
'theSession.SetUndoMark(markID10, "Layer Settings Dialog")
Dim stateArray1(1) As Layer.StateInfo
stateArray1(0).Layer = iLayerNumberSource
stateArray1(0).State = Layer.State.Selectable
stateArray1(1).Layer = iLayerNumberTarget
stateArray1(1).State = Layer.State.WorkLayer
workPart.Layers.ChangeStates(stateArray1, True)
'theSession.SetUndoMarkName(markID10, "Layer Settings")
theSession.DeleteUndoMark(markID10, Nothing)
'save work part
Dim partSaveStatus1 As PartSaveStatus
partSaveStatus1 = workPart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False)
partSaveStatus1.Dispose()
workPart.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.UseResponses, Nothing)
Next
objWorkbook.Save()
objWorkbook.Close()
objExcel.Quit()
workPart = Nothing
End Sub
End Module
Object Count in Layer setting
Hi.
In layer setting dialo box, the object count is fetched from where ??
re: object count
I assume that NX keeps an internal count of objects on layers. I don't know exactly "where" this information comes from.
You can get a report of the count and type of objects on each layer by opening the layer settings dialog (expand the "layer control" section, if necessary) and clicking on the "information" button.
Layer Setting - Object Count
Am not able to see Layer Control Section . However, is their native function in NXOpen to get this count. As the count we get on layer (using GetAllObjectsOnLayer) is too many compared to what we can see in Object count under Layer setting.
re: object count
Other than .GetAllObjectsOnLayer(), I'm not aware of a method that would report how many entities are on a particular layer.
IDE and NXOpen dll
Hello
Thanks a lot. I wonder if you can share which IDE you use for programming. I am using SharpDevelop with added reference of NXOpen dll files. However, I do not get the native methods using which we solved the issue.
Do you care to share your programming deskboard ?
Thanks
Vivek
re: IDE
I'm currently using VB.NET express (2010 version).