Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to avoid popup

Status
Not open for further replies.

DesEngineer4

Mechanical
Feb 19, 2013
181
HI
I am using the below journal to move objects and assembly components to respective layers. And this journal is combined with objects and assembly components.

If a part does not have any assembly components means, it is showing an pop up box that there is no assembly components. Can you help me in avoiding that popup...



Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies

Module layermove

Sub Main()

Dim s As Session = Session.GetSession()
Dim lw As ListingWindow = s.ListingWindow
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = s.Parts.Work

Dim displaypart As Part = s.Parts.Display

Dim pointcol As PointCollection = workPart.Points
Dim linecol As LineCollection = workPart.Lines
Dim arccol As ArcCollection = workPart.Arcs
Dim splinecol As SplineCollection = workPart.Splines
Dim sketchcol As SketchCollection = workpart.Sketches
Dim bodycol As BodyCollection = workpart.Bodies
Dim allComp1 As ArrayList = New ArrayList

Dim objArray(0) As DisplayableObject

Dim pointslayer As Integer = 90
Dim linelayer As Integer = 90
Dim arclayer As Integer = 90
Dim coniclayer As Integer = 90
Dim splinelayer As Integer = 90
Dim csyslayer As Integer = 40
Dim daxislayer As Integer = 40
Dim dplanelayer As Integer = 40
Dim bodylayer As Integer = 1
Dim sketchlayer As Integer = 40

If pointcol.ToArray().Length > 0 Then
For Each pt As Point In pointcol
If (pt.Layer >79 or pt.Layer <60)
ufs.Obj.SetLayer(pt.Tag, pointslayer)
End If
Next
End If

If linecol.ToArray().Length > 0 Then
For Each ln As Line In linecol
If ((ln.Layer >79 or ln.Layer <60) and (ln.Layer >256 or ln.Layer <241) and ln.Layer >1)
ufs.Obj.SetLayer(ln.Tag, linelayer)
End If
Next
End If

If arccol.ToArray().Length > 0 Then
For Each arc1 As Arc In arccol
If (arc1.Layer >79 or arc1.Layer <60)
ufs.Obj.SetLayer(arc1.Tag, arclayer)
End If
Next
End If

If splinecol.ToArray().Length > 0 Then
For Each sp As Spline In splinecol
If (sp.Layer >79 or sp.Layer <60)
ufs.Obj.SetLayer(sp.Tag, splinelayer)
End If
Next
End If

If bodycol.ToArray().Length > 0 Then
For Each sb As Body In bodycol
If sb.Layer >19 Then
ufs.Obj.SetLayer(sb.Tag,bodylayer)
End If
Next
End If


For Each obj As DisplayableObject In workPart.Datums
If TypeOf obj Is DatumPlane Then
objArray(0) = obj
workPart.Layers.MoveDisplayableObjects(dplanelayer, objArray)
End If

If TypeOf obj Is DatumAxis Then
objArray(0) = obj
workPart.Layers.MoveDisplayableObjects(daxislayer, objArray)
End If
Next

If sketchcol.ToArray().Length > 0 Then
For Each sk As Sketch In sketchcol
If (sk.Layer >39 or sk.Layer <40)
ufs.Obj.SetLayer(sk.Tag, sketchlayer)
End If
Next
End If

Dim coniccol(-1) As Tag
Dim conictype As Integer = 6
Dim conictag As Tag = Tag.Null
Dim count As Integer = 0

ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)
While conictag <> Tag.Null
ReDim Preserve coniccol(count)
coniccol(count) = conictag
count += 1
ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)
End While


If coniccol.Length > 0 Then
For i As Integer = 0 To coniccol.Length - 1
ufs.Obj.SetLayer(coniccol(i), coniclayer)
Next
End If

Dim csyscol(-1) As Tag
Dim csystype As Integer = 45

Dim csystag As NXOpen.Tag = Tag.Null
count = 0

ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)
While csystag <> Tag.Null
ReDim Preserve csyscol(count)
csyscol(count) = csystag
count += 1
ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)
End While
If csyscol.Length > 0 Then
For i As Integer = 0 To csyscol.Length - 1
ufs.Obj.SetLayer(csyscol(i), csyslayer)
Next
End If

If allcomp1.ToArray().Length > 0 Then
Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent
getAllComponents2(root, allComp1)
Dim dispobj As DisplayableObject = Nothing
Dim cnt1 As Integer = allComp1.Count
Dim objectArray1(cnt1 - 1) As DisplayableObject
Dim objlayer As Integer = Nothing
Dim cnt2 As Integer = 0
For i As Integer = 0 To cnt1 - 1
dispobj = DirectCast(allComp1(i), DisplayableObject)
objlayer = dispobj.Layer
If objlayer > 19 Then
ReDim Preserve objectArray1(cnt2)
objectArray1(cnt2) = allComp1(i)
cnt2 += 1
End If
Next
If cnt2 > 0 Then
displaypart.Layers.MoveDisplayableObjects(1, objectArray1)
End If
End If
End Sub

Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList)
Dim child As Component = Nothing
Dim space As String = Nothing
For Each child In comp.GetChildren()
allComp.Add(child)
getAllComponents2(child, allComp)
Next
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







Thanks & Regards,
Sam
 
Replies continue below

Recommended for you

Are you sure you have the correct code listed? I have run the above code on a part with no components and there is no popup.

In fact, there seems to be a logic error and even if the file had components it would simply ignore them.

allcomp1 is your list of components, but at the time the following line of code is executed, nothing has been added to the array list. Therefore, the check will evaluate to false (since the length = 0) and the entire If block will be skipped.

Code:
If allcomp1.ToArray().Length > 0 Then

www.nxjournaling.com
 
HI cowski,
SORRY FOR THAT.
THIS IS ACTUAL CODE.
PLEASE HAVE A LOOK


Code:
Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies

Module layermove

    Sub Main()

        Dim s As Session = Session.GetSession()
        Dim lw As ListingWindow = s.ListingWindow
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim workPart As Part = s.Parts.Work
        
        Dim displaypart As Part = s.Parts.Display

        Dim pointcol As PointCollection = workPart.Points
        Dim linecol As LineCollection = workPart.Lines
        Dim arccol As ArcCollection = workPart.Arcs
        Dim splinecol As SplineCollection = workPart.Splines
        Dim sketchcol As SketchCollection = workpart.Sketches
	   Dim bodycol As BodyCollection = workpart.Bodies
        Dim allComp1 As ArrayList = New ArrayList
	
	Dim objArray(0) As DisplayableObject

	Dim pointslayer As Integer = 90
        Dim linelayer As Integer = 90
        Dim arclayer As Integer = 90
        Dim coniclayer As Integer = 90
        Dim splinelayer As Integer = 90
        Dim csyslayer As Integer = 40
        Dim daxislayer As Integer = 40
        Dim dplanelayer As Integer = 40
        Dim bodylayer As Integer = 1
        Dim sketchlayer As Integer = 40

        If pointcol.ToArray().Length > 0 Then
            For Each pt As Point In pointcol
                If (pt.Layer >79 or pt.Layer <60)
                ufs.Obj.SetLayer(pt.Tag, pointslayer)
              End If
            Next
        End If

        If linecol.ToArray().Length > 0 Then
            For Each ln As Line In linecol
                If ((ln.Layer >79 or ln.Layer <60) and (ln.Layer >256 or ln.Layer <241) and ln.Layer >1)
                ufs.Obj.SetLayer(ln.Tag, linelayer)
	      End If
            Next
        End If

        If arccol.ToArray().Length > 0 Then
            For Each arc1 As Arc In arccol
                If (arc1.Layer >79 or arc1.Layer <60)
                ufs.Obj.SetLayer(arc1.Tag, arclayer)
              End If
            Next
        End If

        If splinecol.ToArray().Length > 0 Then
            For Each sp As Spline In splinecol
                If (sp.Layer >79 or sp.Layer <60)
                ufs.Obj.SetLayer(sp.Tag, splinelayer)
               End If
            Next
        End If

         If bodycol.ToArray().Length > 0 Then
            For Each sb As Body In bodycol
		If sb.Layer >19 Then
                ufs.Obj.SetLayer(sb.Tag,bodylayer)
		End If
	    Next
	End If

        
          For Each obj As DisplayableObject In workPart.Datums
            If TypeOf obj Is DatumPlane Then
                objArray(0) = obj
                workPart.Layers.MoveDisplayableObjects(dplanelayer, objArray)
            End If

            If TypeOf obj Is DatumAxis Then
                objArray(0) = obj
                workPart.Layers.MoveDisplayableObjects(daxislayer, objArray)
            End If
        Next
	
	 If sketchcol.ToArray().Length > 0 Then
            For Each sk As Sketch In sketchcol
                If (sk.Layer >39 or sk.Layer <40)
                ufs.Obj.SetLayer(sk.Tag, sketchlayer)
             End If
            Next
        End If
	
        Dim coniccol(-1) As Tag
        Dim conictype As Integer = 6
        Dim conictag As Tag = Tag.Null
        Dim count As Integer = 0

        ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)
        While conictag <> Tag.Null
            ReDim Preserve coniccol(count)
            coniccol(count) = conictag
            count += 1
            ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)
        End While


        If coniccol.Length > 0 Then
            For i As Integer = 0 To coniccol.Length - 1
                ufs.Obj.SetLayer(coniccol(i), coniclayer)
            Next
        End If
 
        Dim csyscol(-1) As Tag
        Dim csystype As Integer = 45

        Dim csystag As NXOpen.Tag = Tag.Null
        count = 0

        ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)
        While csystag <> Tag.Null
            ReDim Preserve csyscol(count)
            csyscol(count) = csystag
            count += 1
            ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)
        End While
        If csyscol.Length > 0 Then
            For i As Integer = 0 To csyscol.Length - 1
                ufs.Obj.SetLayer(csyscol(i), csyslayer)
            Next
        End If
   
        Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent
        getAllComponents2(root, allComp1)
        Dim dispobj As DisplayableObject = Nothing
        Dim cnt1 As Integer = allComp1.Count
        Dim objectArray1(cnt1 - 1) As DisplayableObject
        Dim objlayer As Integer = Nothing
        Dim cnt2 As Integer = 0
        For i As Integer = 0 To cnt1 - 1
            dispobj = DirectCast(allComp1(i), DisplayableObject)
            objlayer = dispobj.Layer
            If objlayer > 19 Then
                ReDim Preserve objectArray1(cnt2)
                objectArray1(cnt2) = allComp1(i)
                cnt2 += 1
            End If
        Next
        If cnt2 > 0 Then
            displaypart.Layers.MoveDisplayableObjects(1, objectArray1)
        End If
    
    End Sub

    Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList)
        Dim child As Component = Nothing
        Dim space As String = Nothing
        For Each child In comp.GetChildren()
            allComp.Add(child)
            getAllComponents2(child, allComp)
        Next
        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

Thanks & Regards,
Sam
 
The key is the following line:

Code:
Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent

if root = nothing, then you are working with a part that has no components. A simple If block will take care of the error.

Code:
If Not IsNothing(root) Then
'process components
Else
'any special processing for piece parts
End If


www.nxjournaling.com
 
Thank you cowski..

Thanks a lot..


Thanks & Regards,
Sam
 
hi cowski,

Still I am getting the same error...
So, thats why I attached the snap shot of error.. and sample work part.While using the above journal..It was completing the task successfully and showing that error message which is in attachment. Please have a look on attachments. Please help me.

Thanks & Regards,
Sam
 
 http://files.engineering.com/getfile.aspx?folder=0d4776fa-3fd4-4204-b962-c180d76f0fd9&file=sample_part.zip
Here's what I added to the code that seems to work:

Code:
Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies

Module layermove

    Sub Main()

        Dim s As Session = Session.GetSession()
        Dim lw As ListingWindow = s.ListingWindow
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim workPart As Part = s.Parts.Work
        
        Dim displaypart As Part = s.Parts.Display

        Dim pointcol As PointCollection = workPart.Points
        Dim linecol As LineCollection = workPart.Lines
        Dim arccol As ArcCollection = workPart.Arcs
        Dim splinecol As SplineCollection = workPart.Splines
        Dim sketchcol As SketchCollection = workpart.Sketches
	   Dim bodycol As BodyCollection = workpart.Bodies
        Dim allComp1 As ArrayList = New ArrayList
	
	Dim objArray(0) As DisplayableObject

	Dim pointslayer As Integer = 90
        Dim linelayer As Integer = 90
        Dim arclayer As Integer = 90
        Dim coniclayer As Integer = 90
        Dim splinelayer As Integer = 90
        Dim csyslayer As Integer = 40
        Dim daxislayer As Integer = 40
        Dim dplanelayer As Integer = 40
        Dim bodylayer As Integer = 1
        Dim sketchlayer As Integer = 40

        If pointcol.ToArray().Length > 0 Then
            For Each pt As Point In pointcol
                If (pt.Layer >79 or pt.Layer <60)
                ufs.Obj.SetLayer(pt.Tag, pointslayer)
              End If
            Next
        End If

        If linecol.ToArray().Length > 0 Then
            For Each ln As Line In linecol
                If ((ln.Layer >79 or ln.Layer <60) and (ln.Layer >256 or ln.Layer <241) and ln.Layer >1)
                ufs.Obj.SetLayer(ln.Tag, linelayer)
	      End If
            Next
        End If

        If arccol.ToArray().Length > 0 Then
            For Each arc1 As Arc In arccol
                If (arc1.Layer >79 or arc1.Layer <60)
                ufs.Obj.SetLayer(arc1.Tag, arclayer)
              End If
            Next
        End If

        If splinecol.ToArray().Length > 0 Then
            For Each sp As Spline In splinecol
                If (sp.Layer >79 or sp.Layer <60)
                ufs.Obj.SetLayer(sp.Tag, splinelayer)
               End If
            Next
        End If

         If bodycol.ToArray().Length > 0 Then
            For Each sb As Body In bodycol
		If sb.Layer >19 Then
                ufs.Obj.SetLayer(sb.Tag,bodylayer)
		End If
	    Next
	End If

        
          For Each obj As DisplayableObject In workPart.Datums
            If TypeOf obj Is DatumPlane Then
                objArray(0) = obj
                workPart.Layers.MoveDisplayableObjects(dplanelayer, objArray)
            End If

            If TypeOf obj Is DatumAxis Then
                objArray(0) = obj
                workPart.Layers.MoveDisplayableObjects(daxislayer, objArray)
            End If
        Next
	
	 If sketchcol.ToArray().Length > 0 Then
            For Each sk As Sketch In sketchcol
                If (sk.Layer >39 or sk.Layer <40)
                ufs.Obj.SetLayer(sk.Tag, sketchlayer)
             End If
            Next
        End If
	
        Dim coniccol(-1) As Tag
        Dim conictype As Integer = 6
        Dim conictag As Tag = Tag.Null
        Dim count As Integer = 0

        ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)
        While conictag <> Tag.Null
            ReDim Preserve coniccol(count)
            coniccol(count) = conictag
            count += 1
            ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)
        End While


        If coniccol.Length > 0 Then
            For i As Integer = 0 To coniccol.Length - 1
                ufs.Obj.SetLayer(coniccol(i), coniclayer)
            Next
        End If
 
        Dim csyscol(-1) As Tag
        Dim csystype As Integer = 45

        Dim csystag As NXOpen.Tag = Tag.Null
        count = 0

        ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)
        While csystag <> Tag.Null
            ReDim Preserve csyscol(count)
            csyscol(count) = csystag
            count += 1
            ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)
        End While
        If csyscol.Length > 0 Then
            For i As Integer = 0 To csyscol.Length - 1
                ufs.Obj.SetLayer(csyscol(i), csyslayer)
            Next
        End If
   
        Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent
		[highlight #FCE94F]If Not IsNothing(root) Then[/highlight]
			getAllComponents2(root, allComp1)
			Dim dispobj As DisplayableObject = Nothing
			Dim cnt1 As Integer = allComp1.Count
			Dim objectArray1(cnt1 - 1) As DisplayableObject
			Dim objlayer As Integer = Nothing
			Dim cnt2 As Integer = 0
			For i As Integer = 0 To cnt1 - 1
				dispobj = DirectCast(allComp1(i), DisplayableObject)
				objlayer = dispobj.Layer
				If objlayer > 19 Then
					ReDim Preserve objectArray1(cnt2)
					objectArray1(cnt2) = allComp1(i)
					cnt2 += 1
				End If
			Next
			If cnt2 > 0 Then
				displaypart.Layers.MoveDisplayableObjects(1, objectArray1)
			End If
		[highlight #FCE94F]End If[/highlight]
    
    End Sub

    Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList)
        Dim child As Component = Nothing
        Dim space As String = Nothing
        For Each child In comp.GetChildren()
            allComp.Add(child)
            getAllComponents2(child, allComp)
        Next
        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

www.nxjournaling.com
 
Hi Cowski,

Thanks a lot. Its working.

I need to clarify another doubt from you on above journal.

I am using the above journal in my daily work..
As per standards.. The threads must be in layer 1. when we use directly thread hole or only thread option (specifically symbolic threads) and these threads are recognized as arcs in ug right. so, these threads are moving to the arc or curves layers which was specified in the journal.

In the above journal, it is coded that all arcs should be in so and so layer.. so even the threads all moving to that specific layer..

Is there any option to avoid the treads in moving to arc layer. Or do you have any suggestions. please advice..



Thanks & Regards,
Sam
 
Loop through the part's features and move the symbolic thread arcs back to layer 1.

Code:
[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] System.Collections  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpen.UF  
[COLOR=blue]Imports[/color] NXOpen.Utilities  
[COLOR=blue]Imports[/color] NXOpen.Assemblies  
[highlight #FCE94F][COLOR=blue]Imports[/color] NXOpen.Features
[/highlight]
[COLOR=blue]Module[/color] layermove  

    [COLOR=blue]Sub[/color] Main()  

        [COLOR=blue]Dim[/color] s [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
        [COLOR=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] s.ListingWindow  
        [COLOR=blue]Dim[/color] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession()  
        [COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] s.Parts.Work  
          
        [COLOR=blue]Dim[/color] displaypart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] s.Parts.Display  

        [COLOR=blue]Dim[/color] pointcol [COLOR=blue]As[/color] PointCollection [COLOR=blue]=[/color] workPart.Points  
        [COLOR=blue]Dim[/color] linecol [COLOR=blue]As[/color] LineCollection [COLOR=blue]=[/color] workPart.Lines  
        [COLOR=blue]Dim[/color] arccol [COLOR=blue]As[/color] ArcCollection [COLOR=blue]=[/color] workPart.Arcs  
        [COLOR=blue]Dim[/color] splinecol [COLOR=blue]As[/color] SplineCollection [COLOR=blue]=[/color] workPart.Splines  
        [COLOR=blue]Dim[/color] sketchcol [COLOR=blue]As[/color] SketchCollection [COLOR=blue]=[/color] workpart.Sketches  
	   [COLOR=blue]Dim[/color] bodycol [COLOR=blue]As[/color] BodyCollection [COLOR=blue]=[/color] workpart.Bodies  
        [COLOR=blue]Dim[/color] allComp1 [COLOR=blue]As[/color] ArrayList [COLOR=blue]= New[/color] ArrayList  
	  
	Dim objArray(0) [COLOR=blue]As[/color] DisplayableObject  

	Dim pointslayer [COLOR=blue]As Integer =[/color] 90  
        [COLOR=blue]Dim[/color] linelayer [COLOR=blue]As Integer =[/color] 90  
        [COLOR=blue]Dim[/color] arclayer [COLOR=blue]As Integer =[/color] 90  
        [COLOR=blue]Dim[/color] coniclayer [COLOR=blue]As Integer =[/color] 90  
        [COLOR=blue]Dim[/color] splinelayer [COLOR=blue]As Integer =[/color] 90  
        [COLOR=blue]Dim[/color] csyslayer [COLOR=blue]As Integer =[/color] 40  
        [COLOR=blue]Dim[/color] daxislayer [COLOR=blue]As Integer =[/color] 40  
        [COLOR=blue]Dim[/color] dplanelayer [COLOR=blue]As Integer =[/color] 40  
        [COLOR=blue]Dim[/color] bodylayer [COLOR=blue]As Integer =[/color] 1  
        [COLOR=blue]Dim[/color] sketchlayer [COLOR=blue]As Integer =[/color] 40  

        [COLOR=blue]If[/color] pointcol.ToArray().Length > 0 [COLOR=blue]Then[/color]  
            [COLOR=blue]For Each[/color] pt [COLOR=blue]As[/color] Point [COLOR=blue]In[/color] pointcol  
                [COLOR=blue]If[/color] (pt.Layer >79 [COLOR=blue]or[/color] pt.Layer <60)  
                ufs.Obj.SetLayer(pt.Tag, pointslayer)  
              End [COLOR=blue]If[/color]  
            [COLOR=blue]Next[/color]  
        End [COLOR=blue]If[/color]  

        [COLOR=blue]If[/color] linecol.ToArray().Length > 0 [COLOR=blue]Then[/color]  
            [COLOR=blue]For Each[/color] ln [COLOR=blue]As[/color] Line [COLOR=blue]In[/color] linecol  
                [COLOR=blue]If[/color] ((ln.Layer >79 [COLOR=blue]or[/color] ln.Layer <60) [COLOR=blue]and[/color] (ln.Layer >256 [COLOR=blue]or[/color] ln.Layer <241) [COLOR=blue]and[/color] ln.Layer >1)  
                ufs.Obj.SetLayer(ln.Tag, linelayer)  
	      End [COLOR=blue]If[/color]  
            [COLOR=blue]Next[/color]  
        End [COLOR=blue]If[/color]  

        [COLOR=blue]If[/color] arccol.ToArray().Length > 0 [COLOR=blue]Then[/color]  
            [COLOR=blue]For Each[/color] arc1 [COLOR=blue]As[/color] Arc [COLOR=blue]In[/color] arccol  
                [COLOR=blue]If[/color] (arc1.Layer >79 [COLOR=blue]or[/color] arc1.Layer <60)  
                ufs.Obj.SetLayer(arc1.Tag, arclayer)  
              End [COLOR=blue]If[/color]  
            [COLOR=blue]Next[/color]  
        End [COLOR=blue]If[/color]  

        [COLOR=blue]If[/color] splinecol.ToArray().Length > 0 [COLOR=blue]Then[/color]  
            [COLOR=blue]For Each[/color] sp [COLOR=blue]As[/color] Spline [COLOR=blue]In[/color] splinecol  
                [COLOR=blue]If[/color] (sp.Layer >79 [COLOR=blue]or[/color] sp.Layer <60)  
                ufs.Obj.SetLayer(sp.Tag, splinelayer)  
               End [COLOR=blue]If[/color]  
            [COLOR=blue]Next[/color]  
        End [COLOR=blue]If[/color]  

         [COLOR=blue]If[/color] bodycol.ToArray().Length > 0 [COLOR=blue]Then[/color]  
            [COLOR=blue]For Each[/color] sb [COLOR=blue]As[/color] Body [COLOR=blue]In[/color] bodycol  
		If sb.Layer >19 [COLOR=blue]Then[/color]  
                ufs.Obj.SetLayer(sb.Tag,bodylayer)  
		End [COLOR=blue]If[/color]  
	    [COLOR=blue]Next[/color]  
	End [COLOR=blue]If[/color]  

          
          [COLOR=blue]For Each[/color] obj [COLOR=blue]As[/color] DisplayableObject [COLOR=blue]In[/color] workPart.Datums  
            [COLOR=blue]If TypeOf[/color] obj [COLOR=blue]Is[/color] DatumPlane [COLOR=blue]Then[/color]  
                objArray(0) [COLOR=blue]=[/color] obj  
                workPart.Layers.MoveDisplayableObjects(dplanelayer, objArray)  
            End [COLOR=blue]If[/color]  

            [COLOR=blue]If TypeOf[/color] obj [COLOR=blue]Is[/color] DatumAxis [COLOR=blue]Then[/color]  
                objArray(0) [COLOR=blue]=[/color] obj  
                workPart.Layers.MoveDisplayableObjects(daxislayer, objArray)  
            End [COLOR=blue]If[/color]  
        [COLOR=blue]Next[/color]  
	  
	 [COLOR=blue]If[/color] sketchcol.ToArray().Length > 0 [COLOR=blue]Then[/color]  
            [COLOR=blue]For Each[/color] sk [COLOR=blue]As[/color] Sketch [COLOR=blue]In[/color] sketchcol  
                [COLOR=blue]If[/color] (sk.Layer >39 [COLOR=blue]or[/color] sk.Layer <40)  
                ufs.Obj.SetLayer(sk.Tag, sketchlayer)  
             End [COLOR=blue]If[/color]  
            [COLOR=blue]Next[/color]  
        End [COLOR=blue]If[/color]  
	  
        [COLOR=blue]Dim[/color] coniccol(-1) [COLOR=blue]As[/color] Tag  
        [COLOR=blue]Dim[/color] conictype [COLOR=blue]As Integer =[/color] 6  
        [COLOR=blue]Dim[/color] conictag [COLOR=blue]As[/color] Tag [COLOR=blue]=[/color] Tag.Null  
        [COLOR=blue]Dim[/color] count [COLOR=blue]As Integer =[/color] 0  

        ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)  
        [COLOR=blue]While[/color] conictag <> Tag.Null  
            [COLOR=blue]ReDim Preserve[/color] coniccol(count)  
            coniccol(count) [COLOR=blue]=[/color] conictag  
            count [COLOR=blue]+=[/color] 1  
            ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)  
        End [COLOR=blue]While[/color]  


        [COLOR=blue]If[/color] coniccol.Length > 0 [COLOR=blue]Then[/color]  
            [COLOR=blue]For[/color] i [COLOR=blue]As Integer =[/color] 0 [COLOR=blue]To[/color] coniccol.Length [COLOR=blue]-[/color] 1  
                ufs.Obj.SetLayer(coniccol(i), coniclayer)  
            [COLOR=blue]Next[/color]  
        End [COLOR=blue]If[/color]  
   
        [COLOR=blue]Dim[/color] csyscol(-1) [COLOR=blue]As[/color] Tag  
        [COLOR=blue]Dim[/color] csystype [COLOR=blue]As Integer =[/color] 45  

        [COLOR=blue]Dim[/color] csystag [COLOR=blue]As[/color] NXOpen.Tag [COLOR=blue]=[/color] Tag.Null  
        count [COLOR=blue]=[/color] 0  

        ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)  
        [COLOR=blue]While[/color] csystag <> Tag.Null  
            [COLOR=blue]ReDim Preserve[/color] csyscol(count)  
            csyscol(count) [COLOR=blue]=[/color] csystag  
            count [COLOR=blue]+=[/color] 1  
            ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)  
        End [COLOR=blue]While[/color]  
        [COLOR=blue]If[/color] csyscol.Length > 0 [COLOR=blue]Then[/color]  
            [COLOR=blue]For[/color] i [COLOR=blue]As Integer =[/color] 0 [COLOR=blue]To[/color] csyscol.Length [COLOR=blue]-[/color] 1  
                ufs.Obj.SetLayer(csyscol(i), csyslayer)  
            [COLOR=blue]Next[/color]  
        End [COLOR=blue]If[/color]  
     
[highlight #FCE94F]	[COLOR=green]'move symbolic thread arcs to layer 1[/color]
	For [COLOR=blue]each[/color] myFeature [COLOR=blue]as[/color] Feature [COLOR=blue]in[/color] workPart.Features  
	    if myFeature.FeatureType [COLOR=blue]=[/color] "SYMBOLIC_THREAD" [COLOR=blue]then[/color]  
	        for [COLOR=blue]each[/color] myEnt [COLOR=blue]as[/color] arc [COLOR=blue]in[/color] myFeature.GetEntities  
		    myEnt.Layer [COLOR=blue]=[/color] 1  
		    myEnt.RedisplayObject  
		next  
	    end [COLOR=blue]if[/color]  
	Next  
[/highlight]
        [COLOR=blue]Dim[/color] root [COLOR=blue]As[/color] Component [COLOR=blue]=[/color] s.Parts.Display.ComponentAssembly.RootComponent  
		If [COLOR=blue]Not[/color] IsNothing(root) [COLOR=blue]Then[/color]  
			getAllComponents2(root, allComp1)  
			Dim dispobj [COLOR=blue]As[/color] DisplayableObject [COLOR=blue]= Nothing[/color]  
			Dim cnt1 [COLOR=blue]As Integer =[/color] allComp1.Count  
			Dim objectArray1(cnt1 [COLOR=blue]-[/color] 1) [COLOR=blue]As[/color] DisplayableObject  
			Dim objlayer [COLOR=blue]As Integer = Nothing[/color]  
			Dim cnt2 [COLOR=blue]As Integer =[/color] 0  
			For i [COLOR=blue]As Integer =[/color] 0 [COLOR=blue]To[/color] cnt1 [COLOR=blue]-[/color] 1  
				dispobj [COLOR=blue]=[/color] DirectCast(allComp1(i), DisplayableObject)  
				objlayer [COLOR=blue]=[/color] dispobj.Layer  
				If objlayer > 19 [COLOR=blue]Then[/color]  
					ReDim [COLOR=blue]Preserve[/color] objectArray1(cnt2)  
					objectArray1(cnt2) [COLOR=blue]=[/color] allComp1(i)  
					cnt2 [COLOR=blue]+=[/color] 1  
				End [COLOR=blue]If[/color]  
			Next  
			If cnt2 > 0 [COLOR=blue]Then[/color]  
				displaypart.Layers.MoveDisplayableObjects(1, objectArray1)  
			End [COLOR=blue]If[/color]  
		End [COLOR=blue]If[/color]  
      
    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Sub[/color] getAllComponents2(ByVal comp [COLOR=blue]As[/color] Component, [COLOR=blue]ByRef[/color] allComp [COLOR=blue]As[/color] ArrayList)  
        [COLOR=blue]Dim[/color] child [COLOR=blue]As[/color] Component [COLOR=blue]= Nothing[/color]  
        [COLOR=blue]Dim[/color] space [COLOR=blue]As String = Nothing[/color]  
        [COLOR=blue]For Each[/color] child [COLOR=blue]In[/color] comp.GetChildren()  
            allComp.Add(child)  
            getAllComponents2(child, allComp)  
        [COLOR=blue]Next[/color]  
        End [COLOR=blue]Sub[/color]  


    [COLOR=blue]Public Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As String[/color]) [COLOR=blue]As Integer[/color]  

 [COLOR=green]'Unloads the image immediately after execution within NX[/color]
        GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.Immediately  

    End [COLOR=blue]Function[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
HI COWSKI,

Layers loop for threads are working fine.
Thanks for your help, sorry for late reply..

I will come back with another issue..I hope you support me..

Thanks & Regards,
Sam
 
Hi cowski,

I am back with new issues...

1. I am using journal to find out Entire part reference set (which was in attachments). It will find out and show a dialogue box which contains reference set Entire part. Is there is any possibility to get the (dailogue box or listing window) with the above layers journal. So, that after moving the components to respective layers. It should show the listing window, which component is moved from 'X' layer to 'Y' layer. Please suggest me..


2. I was created a new toolbar (.tbr file) and loaded to nx interface using toolbar customization. But when I close and open the NX. Again, I need to reload that toolbar. Is there any suggestion from you to avoid it. ( Is there is any procedure..to make that toolbar always available. Even though I tried with properties of toolbar by checking the option always available. But it is not available after reopening the NX.)

3. can we show any prompt window for the above journals...? Like, after clicking the Icon it should show the options like whether to proceed or not with Yes / No Options. Is it possible with NX 7.5.

Thank for your patience cowski....

Thanks & Regards,
Sam
 
 http://files.engineering.com/getfile.aspx?folder=2166568d-ff3b-46b3-aba1-cbf4d7555ac6&file=ENTIRE-PART.vb
#2: Search the NX help files (menu script) and this site for specifics, but from memory - you'll need to create a certain directory structure and create an environment variable and/or edit your .dat file to point to it. Place the .tbr file in the Startup folder and it will be loaded every time NX starts.

#1: yes it is possible
#3: also possible, but I'm unclear on what you want to verify. Should it prompt before each and every item it moves (lines, arcs, sketches, etc) or only certain items (e.g. only components)?

www.nxjournaling.com
 
Yeah...Sorry for that.
Any way thanks for your immediate reply.....
#3. I need only when I click on that certain icon. (It is enough to prompt on every first instant..No need separately for arcs, lines and components...etc).

Can you help me in editing the below journal for causes #1 and #3.



Code:
Option Strict Off  
Imports System  
Imports System.Collections  
Imports NXOpen  
Imports NXOpen.UF  
Imports NXOpen.Utilities  
Imports NXOpen.Assemblies  
Imports NXOpen.Features

Module layermove  

    Sub Main()  

        Dim s As Session = Session.GetSession()  
        Dim lw As ListingWindow = s.ListingWindow  
        Dim ufs As UFSession = UFSession.GetUFSession()  
        Dim workPart As Part = s.Parts.Work  
          
        Dim displaypart As Part = s.Parts.Display  

        Dim pointcol As PointCollection = workPart.Points  
        Dim linecol As LineCollection = workPart.Lines  
        Dim arccol As ArcCollection = workPart.Arcs  
        Dim splinecol As SplineCollection = workPart.Splines  
        Dim sketchcol As SketchCollection = workpart.Sketches  
	   Dim bodycol As BodyCollection = workpart.Bodies  
        Dim allComp1 As ArrayList = New ArrayList  
	  
	Dim objArray(0) As DisplayableObject  

	Dim pointslayer As Integer = 90  
        Dim linelayer As Integer = 90  
        Dim arclayer As Integer = 90  
        Dim coniclayer As Integer = 90  
        Dim splinelayer As Integer = 90  
        Dim csyslayer As Integer = 40  
        Dim daxislayer As Integer = 40  
        Dim dplanelayer As Integer = 40  
        Dim bodylayer As Integer = 1  
        Dim sketchlayer As Integer = 40  

        If pointcol.ToArray().Length > 0 Then  
            For Each pt As Point In pointcol  
                If (pt.Layer >79 or pt.Layer <60)  
                ufs.Obj.SetLayer(pt.Tag, pointslayer)  
              End If  
            Next  
        End If  

        If linecol.ToArray().Length > 0 Then  
            For Each ln As Line In linecol  
                If ((ln.Layer >79 or ln.Layer <60) and (ln.Layer >256 or ln.Layer <241) and ln.Layer >1)  
                ufs.Obj.SetLayer(ln.Tag, linelayer)  
	      End If  
            Next  
        End If  

        If arccol.ToArray().Length > 0 Then  
            For Each arc1 As Arc In arccol  
                If (arc1.Layer >79 or arc1.Layer <60)  
                ufs.Obj.SetLayer(arc1.Tag, arclayer)  
              End If  
            Next  
        End If  

        If splinecol.ToArray().Length > 0 Then  
            For Each sp As Spline In splinecol  
                If (sp.Layer >79 or sp.Layer <60)  
                ufs.Obj.SetLayer(sp.Tag, splinelayer)  
               End If  
            Next  
        End If  

         If bodycol.ToArray().Length > 0 Then  
            For Each sb As Body In bodycol  
		If sb.Layer >19 Then  
                ufs.Obj.SetLayer(sb.Tag,bodylayer)  
		End If  
	    Next  
	End If  

          
          For Each obj As DisplayableObject In workPart.Datums  
            If TypeOf obj Is DatumPlane Then  
                objArray(0) = obj  
                workPart.Layers.MoveDisplayableObjects(dplanelayer, objArray)  
            End If  

            If TypeOf obj Is DatumAxis Then  
                objArray(0) = obj  
                workPart.Layers.MoveDisplayableObjects(daxislayer, objArray)  
            End If  
        Next  
	  
	 If sketchcol.ToArray().Length > 0 Then  
            For Each sk As Sketch In sketchcol  
                If (sk.Layer >39 or sk.Layer <40)  
                ufs.Obj.SetLayer(sk.Tag, sketchlayer)  
             End If  
            Next  
        End If  
	  
        Dim coniccol(-1) As Tag  
        Dim conictype As Integer = 6  
        Dim conictag As Tag = Tag.Null  
        Dim count As Integer = 0  

        ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)  
        While conictag <> Tag.Null  
            ReDim Preserve coniccol(count)  
            coniccol(count) = conictag  
            count += 1  
            ufs.Obj.CycleObjsInPart(workPart.Tag, conictype, conictag)  
        End While  


        If coniccol.Length > 0 Then  
            For i As Integer = 0 To coniccol.Length - 1  
                ufs.Obj.SetLayer(coniccol(i), coniclayer)  
            Next  
        End If  
   
        Dim csyscol(-1) As Tag  
        Dim csystype As Integer = 45  

        Dim csystag As NXOpen.Tag = Tag.Null  
        count = 0  

        ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)  
        While csystag <> Tag.Null  
            ReDim Preserve csyscol(count)  
            csyscol(count) = csystag  
            count += 1  
            ufs.Obj.CycleObjsInPart(workPart.Tag, csystype, csystag)  
        End While  
        If csyscol.Length > 0 Then  
            For i As Integer = 0 To csyscol.Length - 1  
                ufs.Obj.SetLayer(csyscol(i), csyslayer)  
            Next  
        End If  
     
	'move symbolic thread arcs to layer 1
	For each myFeature as Feature in workPart.Features  
	    if myFeature.FeatureType = "SYMBOLIC_THREAD" then  
	        for each myEnt as arc in myFeature.GetEntities  
		    myEnt.Layer = 1  
		    myEnt.RedisplayObject  
		next  
	    end if  
	Next  

        Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent  
		If Not IsNothing(root) Then  
			getAllComponents2(root, allComp1)  
			Dim dispobj As DisplayableObject = Nothing  
			Dim cnt1 As Integer = allComp1.Count  
			Dim objectArray1(cnt1 - 1) As DisplayableObject  
			Dim objlayer As Integer = Nothing  
			Dim cnt2 As Integer = 0  
			For i As Integer = 0 To cnt1 - 1  
				dispobj = DirectCast(allComp1(i), DisplayableObject)  
				objlayer = dispobj.Layer  
				If objlayer > 19 Then  
					ReDim Preserve objectArray1(cnt2)  
					objectArray1(cnt2) = allComp1(i)  
					cnt2 += 1  
				End If  
			Next  
			If cnt2 > 0 Then  
				displaypart.Layers.MoveDisplayableObjects(1, objectArray1)  
			End If  
		End If  
      
    End Sub  

    Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList)  
        Dim child As Component = Nothing  
        Dim space As String = Nothing  
        For Each child In comp.GetChildren()  
            allComp.Add(child)  
            getAllComponents2(child, allComp)  
        Next  
        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



Thanks & Regards,
Sam
 
Here is some code that demonstrates the use of a message box that asks the user a yes/no question and shows how to write to the listing window. You can modify this and add it in to your code as needed to prompt the user as necessary.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
 
Module Module1
 
    Sub Main()
 
        Dim theSession As Session = Session.GetSession()
		Dim lw as ListingWindow = theSession.ListingWindow
        Dim theUISession As UI = UI.GetUI
        Dim response As Integer
        Dim answer As String = "" 
 
		lw.Open
 
        response = theUISession.NXMessageBox.Show("Question", NXMessageBox.DialogType.Question, "Move objects to layer?")
        '1 = Yes
        '2 = No
 
        If response = 1 Then
			'code to run in response to "yes" answer
            answer = "Yes"
			lw.WriteLine("moving objects from layer X to layer Y...")
        Else
			'code to run in response to "no" answer
            answer = "No"
        End If
		
		lw.WriteLine("user answered: " & answer)
  
 
    End Sub
 
 
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
 
        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
 
    End Function
 
End Module

www.nxjournaling.com
 
Thanks Cowski..

I will try and come back to you...

We would like to interact with you directly through phone or web ex...Are you interested ..?


Thanks & Regards,
Sam
 
E-mail works best for code questions. If I don't know the answer off the top of my head, it gives me a chance to consult the help files and try things out first.

www.nxjournaling.com
 
Hi Cowski..
Thanks for your reply..
I would like to chat with you now regarding my issues..can you chat with from any social network sites..

Thanks & Regards,
Sam
 
Thanks Cowski...

It is working fine with the code..for message box (with Yes / No ) options..and for listing window ( information window ), it is showing the same message..that objects moved from layer X to Y..what should I do now ?

Please advice

Thanks & Regards,
Sam
 
You'll need to customize the message.

Code:
lw.WriteLine("moving objects from layer X to layer Y...")

Let's assume you are moving an arc object; your code may look something like:

Code:
lw.WriteLine("moving objects from layer: " & arc1.Layer.ToString & " to layer: " & arclayer.ToString)

The "&" operator concatenates the strings; "string1" & "string2" becomes "string1string2". The arc1.Layer property is an integer as is the arclayer variable; the .ToString method will convert these to strings so they can be added to your message.

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor