×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Error after running journal..

Error after running journal..

Error after running journal..

(OP)
Hi all,

Can any one help me on the following issue..

I am using the below journal in moving the features and lines and arcs and components...etc to respective layers. This journal is working very fine in respective of moving those objects to specified layers...But, after completing the action of journal the hidden datum's and csys`s are coming out...I have attached the snap shots of the model, how it looks after running the journal....

Please help me..
Thanks in Advance..


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

RE: Error after running journal..

Here's what I think is happening:
The datum csys objects start on a layer that you have made invisible, the journal moves them to your specified layer which is visible.

I'd suggest updating your journal to make the datum layer(s) invisible.

www.nxjournaling.com

RE: Error after running journal..

(OP)
Yes Cowski,

This is major problem Which i am facing...Can you give me the solution...
I am thinking that..it is the problem with collection type which we have coded in journal..Am I right...?

This journal is collecting all the virtual datum planes and datum csys. But, it is enough to change the layers of datum`s which are visible in part navigator in NX. How can I do this..


Please advice....

Thanks & Regards,
Sam

RE: Error after running journal..

Quote (shanmuk44)

I am thinking that..it is the problem with collection type which we have coded in journal..Am I right...?

Well... no, not really.
I think the easiest solution here is to make your datum layers invisible.

Open a part, turn on a few layers then record a journal and turn off one or more layers. Incorporate that code into your journal to turn off the datum layers after you move objects.

www.nxjournaling.com

RE: Error after running journal..

(OP)
Yeah..
It would be better...
Nice suggestion (Thank you Cowski)

Thanks & Regards,
Sam

RE: Error after running journal..

(OP)
Hi cowski..

I tried what you said in our previous conversation. Suppose I am moving all the datums and csys to layer 40. I have created the journal which turn off the layer 40 and merged with main layer journal, working fine. But if that is revised in future and the person who is working on that file may on the layer 40, then again those datums are visible..(even i tried this). But in our view, we are asking your help in eliminating those virtual datum`s in journal collection. so, that it will only move the datums which are visible in part navigator..

Thanks & Regards,
Sam

RE: Error after running journal..

Try this:

CODE

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

www.nxjournaling.com

RE: Error after running journal..

(OP)
Thanks Cowski, It is working..

But, It is working only for sketches..I tried to put the code in the same way for datums and csys, lines and arcs. Then it is showing an error..Please see the example how I tried for..lines.

CODE -->

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  
    ln.Activate(False)
    ln.UpdateGeometryDisplay()
    ln.Deactivate(False, Line.UpdateLevel.LineOnly)
  Next
End If 



after running the code which you have given for sketches..It is working fine..But, datum planes and coordinate systems are visible. I think you have to edit the below code like you have done for sketches..

CODE -->

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

Thanks & Regards,
Sam

RE: Error after running journal..

If you have geometry (lines, arcs, etc) showing up after you run the journal, it is because the geometry was on an invisible layer and the journal moved it to a visible layer. Play with the journal recorder to see how to turn a layer on/off, then incorporate that into your journal code to turn off any layers you don't want to see.

www.nxjournaling.com

RE: Error after running journal..

(OP)
Thank you Cowski,

The Idea is good. But, the parts which we model here..It will surround to other users also. So, If that particular layer (generally we use to move all datumplanes and datumaxis to layer 40) was "ON" on their interface then, again all datums will visible.. Before we have a issue about sketches, datums and points. By using your code for sketches that issue was resolved for sketches only. Now, we are asking you to help us in the same way for datums and points too. Basing on your code I tried like below..If my approach is wrong please let me know..


CODE -->

If datumplanecol.ToArray().Length > 0 Then
            For Each dplane As datumplane In datumplanecol
		If (dplane.Layer >49 or dplane.layer <40 and (dplane.layer >199 or dplane.layer <80)) Then
                ufs.Obj.SetLayer(dplane.Tag, dplanelayer)
		End If
	    Next
	End If
         
	
         If datumaxiscol.ToArray().Length > 0 Then
            For Each daxis As datumaxis In datumaxiscol
		If (daxis.Layer >49 or daxis.layer <40 and (daxis.layer >199 or daxis.layer <80)) Then
                ufs.Obj.SetLayer(daxis.Tag, daxislayer)
		End If
	    Next
	End If 


and at the top I kept like this..

CODE -->

Dim datumplanecol As datumplaneCollection = workpart.Datums
	Dim datumaxiscol As datumaxisCollection = workpart.Datums 

But finally it showing " datumplaneCollection and datumaxisCollection is not defined"

I am not sure whether it is right or wrong..I just tried. If I succeeded then I can put the code below which you have given to sketches..

I am not familiar with journal coding. That`s why I am asking each and every thing. Thanks a lot for your patience. We are trying to customize our daily needs in to single click with your help.

Thanks & Regards,
Sam

RE: Error after running journal..

Quote (shanmuk44)

So, If that particular layer (generally we use to move all datumplanes and datumaxis to layer 40) was "ON" on their interface then, again all datums will visible.

That's why I suggested turning the layer off in the journal (make it invisible). If the part is saved after the journal is run, the layer will be invisible for anyone that opens the part.

www.nxjournaling.com

RE: Error after running journal..

(OP)
Hi cowski,

I tried as per your comments..(please see attachments)

I created a journal to turnoff the layer 40, and this makes all datums invisible. The same part i opened in another user, even it is invisible.
But, When we turn on layer 40 it looks like in image which is in attachment.

We created one datum which was highlighted in part navigator. If you see the image there are other virtual datums marked in black color which are made visible by journal..and these virtual datums also moving to layer 40. But, my question is why it is not collecting datums which are in part navigator ?.
If it is doing so then this issue wont arise. Please correct me if I am wrong. How can we resolve this issue ?

we are eagerly Waiting for your reply with a great solution.



Thanks & Regards,
Sam

RE: Error after running journal..

One solution to this problem is to check the parent of the datum plane before you move it. If the parent is a tab feature, don't move it. This code will solve the problem for sheet metal tab features. You may find other features that lead to similar results. If/when that happens, you'll have to add them as an exception similar to what this code does for tab features.

There is probably a more elegant way to handle this situation, but this is the first that came to mind.

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
        lw.Open()

        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 = 100
        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) Then
                    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) Then
                    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) Then
                    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) Then
                    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

                Dim junk As DatumPlane = obj
                If junk.Feature.FeatureType.ToString = "DATUM_PLANE" Then
                    Try
                        Dim parentFeat As Features.Feature() = junk.Feature.GetParents
                        If parentFeat(0).GetFeatureName.Contains("SB Tab") Then
                            Continue For
                        End If
                    Catch ex As Exception

                    End Try
                End If


                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) Then
                    ufs.Obj.SetLayer(sk.Tag, sketchlayer)
                End If
                sk.Activate(False)
                sk.UpdateGeometryDisplay()
                sk.Deactivate(False, Sketch.UpdateLevel.SketchOnly)
            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

        lw.Close()
        'msgbox("done")

    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

RE: Error after running journal..

(OP)
Hi Cowski,

Thanks for your effort. It is just awesome. Thank you very much.

After running your code.. Still we faced that problem for flanges. Later we tried trail and error method. Just only small change we have done.
Now it is working fine.. Really thank you very much.

Quote (cowski)



Dim parentFeat As Features.Feature() = junk.Feature.GetParents
If parentFeat(0).GetFeatureName.Contains("SB Tab") Then


This we changed to:

CODE -->

Dim parentFeat As Features.Feature() = junk.Feature.GetParents
                        If parentFeat(0).GetFeatureName.Contains(" ") Then 

Thanks & Regards,
Sam

RE: Error after running journal..

In my response dated: 17 Apr 13 9:38 in thread561-341877: how to avoid popup, I gave you some code demonstrating how to use both the listing window and message boxes. If you like the message boxes and want more info on them, see the article at: http://www.nxjournaling.com/?q=content/using-messa...

Try out some code and work through it; post back with specific questions (and the code you have so far), I'll be happy to answer them.

www.nxjournaling.com

RE: Error after running journal..

(OP)
Hi cowski,

This is another issue. We are using the below journal for finding entire part reference set and replacing that entire part with s reference set. In any top level assembly.
And this journal search for child components also..

Now, I need to remove child components from this journal. Means it is enough to replace the entire part reference set at that level. No need to
search for child components.

CODE -->

Option Strict Off

Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpenUI


Module ReportReferenceSet



    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = s.ListingWindow
    Dim displaypart As Part = s.Parts.Display
    Dim theUISession As UI = UI.GetUI
    Dim response As Integer
    Dim answer As String = "" 
         

    Sub Main()
        Dim allComp1 As ArrayList = New ArrayList
        Dim displaypart As Part = s.Parts.Display
        lw.Open()
        Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent
        getAllComponents2(root, allComp1)
        Dim referenceSet1 As String = "Entire Part"
        Dim referenceSet2 As String = "S"
        reportComponentReferenceSet(allComp1, referenceSet1)
        ChangeComponentReferenceSet(allComp1, referenceSet1, referenceSet2)
    End Sub
    Sub reportComponentReferenceSet(ByVal allComp1 As ArrayList, ByVal referenceSet1 As String)
        For Each comp As Component In allComp1
            If comp.ReferenceSet = referenceSet1 Then
                lw.WriteLine(comp.Name & " " & comp.ReferenceSet)
            End If
        Next
    End Sub
    Sub ChangeComponentReferenceSet(ByVal allComp1 As ArrayList, ByVal referenceSet1 As String, _
                                    ByVal referenceSet2 As String)
        Dim errorList1 As ErrorList
        Dim comp1(0) As Component
        For Each comp As Component In allComp1

            If comp.ReferenceSet = referenceSet1 Then
                comp1(0) = comp
                errorList1 = displaypart.ComponentAssembly.ReplaceReferenceSetInOwners(referenceSet2, comp1)
            End If
        Next
    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 when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
 
    End Function
 
End Module 

Thanks & Regards,
Sam

RE: Error after running journal..

Comment out or delete the highlighted line of code.

CODE

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 

www.nxjournaling.com

RE: Error after running journal..

(OP)
Hi Cowski,

May I know what skills required to be familiar with UGNX Customization.

Thanks & Regards,
Sam

RE: Error after running journal..

NX customization is a large topic that covers everything from installation to custom applications. You should open that question up to the entire forum for a good cross section of answers...

In the context of this thread, I assume you are asking specifically about journal programming. A basic understanding of programming concepts is required: variables, arrays, conditional testing, branching, and loops. The next step is breaking your code into manageable chunks (functions and/or subroutines) and beyond that - object oriented programming (OOP). A good understanding of what NX is capable of helps as does knowing where the help files are for the NXOpen API as well as a good reference for your language of choice.

www.nxjournaling.com

RE: Error after running journal..

(OP)
Thank you

Thanks & Regards,
Sam

RE: Error after running journal..

(OP)
Hi cowski,

For child parts it is working..
And,

From the code for layers which you responded on 9 May 13 8:49

I want to add a loop for every curve geometry not to touch the layers which are in between 240 to 256.

How can i do this..Please advice...

Thanks & Regards,
Sam

RE: Error after running journal..

You can add an additional check to the object's current layer before you move it. Perhaps something like:

CODE

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

Any lines on layer 240 or above will be ignored.

www.nxjournaling.com

RE: Error after running journal..

(OP)
Hi cowski,

This is new issue on layers journal..

Till now we have not implemented and coding for artwork and trammel points. Generally we will move those artwork to 230 layer and trammel points to 231 layer. If there are many artworks in one drawing..then we move alternative layers. eg: artwork 1 to 230, artwork 1 trammel points to 231 and similarly artwork 2 to 232 and artwork 2 trammel points to 233. So, my question is, whether it is possible to move those artwork to respective layers using journal?

Please advice us.

Thanks & Regards,
Sam

RE: Error after running journal..

What exactly is this artwork? Imported raster images? sketches? dumb curves?

Assuming it is dumb curves (lines, arcs, splines, etc like those from an imported dxf file), you will need some way to distinguish the artwork vs. other curves. One way to do this is with named groups. The journal could then look for these artwork groups and move the group (objects and all) to the specified layer.

www.nxjournaling.com

RE: Error after running journal..

(OP)
Thanks for your reply,

Artwork is something like to show on the part after manufacturing. It may be a text or labels or anything.

I will upload the sample artwork shortly.
Please see the part

There you can find two things.

1. The outer boundary we call as trammel points which import them as a part.
2. The text which we call as artwork and it should be shown on the model after manufacturing.

Thanks & Regards,
Sam

RE: Error after running journal..

(OP)
Hi cowski,

If you not understand my need on our previous conversation. Please let me know I will try to explain you in different.

Thanks & Regards,
Sam

RE: Error after running journal..

(OP)
Hi cowski,

Please forget about artwork which was posted in our previous conversation for time being.
The below code is our final journal to use for layers. But, we have some issues in it.

1. The first coordinate system in the part navigator is moving to layer 61 and remaining datum axiss is moving to layer 40 only.
2. Symbolic thread is also moving to layer 61. But, after changing the window, again it is coming back to layer 1.
3. By executing this journal multiple times on the same model or part. Datum planes and datum axis are moving to layer 61. Not only datum's even some features also moving to layers 61 or 1.
4. As we coded in to move saved csys to 100. If we save csys at any location that csys is moving to layer 100 and some reference lines are creating through default datum axis(for this issue please see attachment)



We hope, you can treat this as high priority.


CODE -->

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

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 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"
       Exit Sub
       End If
		
		lw.WriteLine("user answered: " & answer)
          

        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 = 61
        Dim linelayer As Integer = 61
        Dim arclayer As Integer = 61
        Dim coniclayer As Integer = 61
        Dim splinelayer As Integer = 61
        Dim csyslayer As Integer = 100
        Dim daxislayer As Integer = 40
        Dim dplanelayer As Integer = 40
        Dim bodylayer As Integer = 1
        Dim sketchlayer As Integer = 20

        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 < 240 Then
                If ((ln.Layer >79 or ln.Layer <60) and (ln.Layer >256 or ln.Layer <241) and ln.Layer >1 and (ln.layer >199 or ln.layer <80))
                ufs.Obj.SetLayer(ln.Tag, linelayer)
	      	End If
	      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 and (arc1.layer >199 or arc1.layer <80))
                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 and (sp.layer >199 or sp.layer <80))
                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 and (sb.layer >199 or sb.layer <80)) 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

                Dim junk As DatumPlane = obj
                If junk.Feature.FeatureType.ToString = "DATUM_PLANE" Then
                    Try
                        Dim parentFeat As Features.Feature() = junk.Feature.GetParents
                        If parentFeat(0).GetFeatureName.Contains(" ") Then
                            Continue For
                        End If
                    Catch ex As Exception

                    End Try
                End If


                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 <20) and (sk.layer >199 or sk.layer <80))
                ufs.Obj.SetLayer(sk.Tag, sketchlayer)
             End If
		sk.Activate(False)
		sk.UpdateGeometryDisplay()
		sk.Deactivate(False, Sketch.UpdateLevel.SketchOnly)
            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 and (objlayer >199 or objlayer <80))  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 when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
 
    End Function
 
End Module 

Thanks & Regards,
Sam

RE: Error after running journal..

I'll give you a hint.
The csys in the attached picture didn't move because of this line of code:

CODE

If parentFeat(0).GetFeatureName.Contains(" ") Then 

Spoiler:

The parent feature name of the datum planes is "Datum Coordinate System". Notice the spaces in the parent feature name. The code in the if block skips the rest of the entities, leaving the csys behind.

www.nxjournaling.com

RE: Error after running journal..

(OP)
OKAY.
What code to be inserted in this journal to avoid that...

Thanks & Regards,
Sam

RE: Error after running journal..

There are multiple strategies that would work...
add an additional conditional test on the parent feature name, or
use elseif statements or a select case block to test for different feature names, or
.
.
.

www.nxjournaling.com

RE: Error after running journal..

(OP)
If you are free.

Please give me the code.
I dont know anything about nx journal.

Thanks & Regards,
Sam

RE: Error after running journal..

(OP)
Hi cowski,

Can you give me the code for layers

Thanks & Regards,
Sam

RE: Error after running journal..

(OP)
HI COWSKI,

Please try to give me the code. If you have a free time.

Thanks & Regards,
Sam

RE: Error after running journal..

I've not found a consistent method to get the coordinate system object of the datum csys.

www.nxjournaling.com

RE: Error after running journal..

Ok, I found a method that works.

CODE

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

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 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"
       Exit Sub
       End If
		
		lw.WriteLine("user answered: " & answer)
          

        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 = 61
        Dim linelayer As Integer = 61
        Dim arclayer As Integer = 61
        Dim coniclayer As Integer = 61
        Dim splinelayer As Integer = 61
        Dim csyslayer As Integer = 100
        Dim daxislayer As Integer = 40
        Dim dplanelayer As Integer = 40
        Dim bodylayer As Integer = 1
        Dim sketchlayer As Integer = 20

        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 < 240 Then
                If ((ln.Layer >79 or ln.Layer <60) and (ln.Layer >256 or ln.Layer <241) and ln.Layer >1 and (ln.layer >199 or ln.layer <80))
                ufs.Obj.SetLayer(ln.Tag, linelayer)
	      	End If
	      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 and (arc1.layer >199 or arc1.layer <80))
                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 and (sp.layer >199 or sp.layer <80))
                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 and (sb.layer >199 or sb.layer <80)) 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

                Dim junk As DatumPlane = obj
                If junk.Feature.FeatureType.ToString = "DATUM_PLANE" Then
                    Try
                        Dim parentFeat As Features.Feature() = junk.Feature.GetParents
                        If parentFeat(0).GetFeatureName.Contains(" ") Then
                            Continue For
                        End If
                    Catch ex As Exception

                    End Try
                End If


                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 <20) and (sk.layer >199 or sk.layer <80))
                ufs.Obj.SetLayer(sk.Tag, sketchlayer)
             End If
		sk.Activate(False)
		sk.UpdateGeometryDisplay()
		sk.Deactivate(False, Sketch.UpdateLevel.SketchOnly)
            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
		
		If (myFeature.FeatureType = "DATUM_CSYS") AndAlso (Not myFeature.IsInternal) Then
			Dim DBuilder As DatumCsysBuilder
			DBuilder = workPart.Features.CreateDatumCsysBuilder(myFeature)
			Dim DCObj() As NXObject = DBuilder.GetCommittedObjects
		
			For Each temp As DisplayableObject In DCObj
			temp.Layer = dplanelayer
			temp.RedisplayObject()
			Next
			DBuilder.Destroy()
		
			Dim updateMark As Session.UndoMarkId
			updateMark = s.SetUndoMark(Session.MarkVisibility.Invisible, "update")
			Try
				s.UpdateManager.LogForUpdate(myFeature)
				s.UpdateManager.DoUpdate(updateMark)
			Catch ex As Exception
		
			End Try
		
		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 and (objlayer >199 or objlayer <80))  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 when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
 
    End Function
 
End Module 

www.nxjournaling.com

RE: Error after running journal..

(OP)
Thank you very much for your response Cowski,

I will try this code and let you know the results.

Thanks & Regards,
Sam

RE: Error after running journal..

(OP)
HI COWSKI,

THANK YOU VERY MUCH. THIS CODE IS WORKING FINE.

Symbolic thread is moving to layer 1 only but it is showing as it is in layer 61.

Thanks & Regards,
Sam

RE: Error after running journal..

Update for symbolic thread.

CODE

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

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 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"
       Exit Sub
       End If
		
		lw.WriteLine("user answered: " & answer)
          

        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 = 61
        Dim linelayer As Integer = 61
        Dim arclayer As Integer = 61
        Dim coniclayer As Integer = 61
        Dim splinelayer As Integer = 61
        Dim csyslayer As Integer = 100
        Dim daxislayer As Integer = 40
        Dim dplanelayer As Integer = 40
        Dim bodylayer As Integer = 1
        Dim sketchlayer As Integer = 20

        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 < 240 Then
                If ((ln.Layer >79 or ln.Layer <60) and (ln.Layer >256 or ln.Layer <241) and ln.Layer >1 and (ln.layer >199 or ln.layer <80))
                ufs.Obj.SetLayer(ln.Tag, linelayer)
	      	End If
	      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 and (arc1.layer >199 or arc1.layer <80))
                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 and (sp.layer >199 or sp.layer <80))
                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 and (sb.layer >199 or sb.layer <80)) 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

                Dim junk As DatumPlane = obj
                If junk.Feature.FeatureType.ToString = "DATUM_PLANE" Then
                    Try
                        Dim parentFeat As Features.Feature() = junk.Feature.GetParents
                        If parentFeat(0).GetFeatureName.Contains(" ") Then
                            Continue For
                        End If
                    Catch ex As Exception

                    End Try
                End If


                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 <20) and (sk.layer >199 or sk.layer <80))
                ufs.Obj.SetLayer(sk.Tag, sketchlayer)
             End If
		sk.Activate(False)
		sk.UpdateGeometryDisplay()
		sk.Deactivate(False, Sketch.UpdateLevel.SketchOnly)
            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()

                    Dim updateMark As Session.UndoMarkId
                    updateMark = s.SetUndoMark(Session.MarkVisibility.Invisible, "update")
                    Try
                        s.UpdateManager.LogForUpdate(myFeature)
                        s.UpdateManager.DoUpdate(updateMark)
                    Catch ex As Exception

                    End Try

                Next
            End If

            If (myFeature.FeatureType = "DATUM_CSYS") AndAlso (Not myFeature.IsInternal) Then
                Dim DBuilder As DatumCsysBuilder
                DBuilder = workPart.Features.CreateDatumCsysBuilder(myFeature)
                Dim DCObj() As NXObject = DBuilder.GetCommittedObjects

                For Each temp As DisplayableObject In DCObj
                    temp.Layer = dplanelayer
                    temp.RedisplayObject()
                Next
                DBuilder.Destroy()

                Dim updateMark As Session.UndoMarkId
                updateMark = s.SetUndoMark(Session.MarkVisibility.Invisible, "update")
                Try
                    s.UpdateManager.LogForUpdate(myFeature)
                    s.UpdateManager.DoUpdate(updateMark)
                Catch ex As Exception

                End Try

            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 and (objlayer >199 or objlayer <80))  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 when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
 
    End Function
 
End Module 

www.nxjournaling.com

RE: Error after running journal..

(OP)
YES, NOW THIS IS WORKING FINE..

In our previous quires you have given the below hint for listing window in layers journal . But, we did`t understood where that code line is to be placed in the above layers journal.

Quote:




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)


Thanks & Regards,
Sam

RE: Error after running journal..

(OP)
We placed the code as below.
But the information is showing as "moving objects from layer: 61 to 61". It is not showing before layer.



CODE -->

If arccol.ToArray().Length > 0 Then
            For Each arc1 As Arc In arccol
                If (arc1.Layer >79 or arc1.Layer <60 and (arc1.layer >199 or arc1.layer <80))
                ufs.Obj.SetLayer(arc1.Tag, arclayer)
                lw.WriteLine("moving objects from layer: " & arc1.Layer.FromString & " to layer: " & arclayer.ToString) 
              End If
            Next
        End If 

Thanks & Regards,
Sam

RE: Error after running journal..

Quote (shanmuk)

CODE

ufs.Obj.SetLayer(arc1.Tag, arclayer)
lw.WriteLine("moving objects from layer: " & arc1.Layer.FromString & " to layer: " & arclayer.ToString) 

In the code above, you have already moved the arc to the new layer before reporting what layer it is on. Switch the 2 lines of code to report the arc layer first, then move it.


CODE

lw.WriteLine("moving objects from layer: " & arc1.Layer.FromString & " to layer: " & arclayer.ToString)
ufs.Obj.SetLayer(arc1.Tag, arclayer) 

www.nxjournaling.com

RE: Error after running journal..

(OP)
Hi cowski,

This is the actual code that we tested for arcs.

CODE -->

lw.WriteLine("moving objects from layer: " & arc1.Layer.ToString & " to layer: " & arclayer.ToString) 
ufs.Obj.SetLayer(arc1.Tag, arclayer) 


We tried by changing the arc layer to 25 and then executed the journal
even though it showing the message shown below.

Quote:



moving objects from layer X to layer Y...
user answered: Yes
moving objects from layer: 61 to layer: 61

Thanks & Regards,
Sam

RE: Error after running journal..

(OP)
Hi cowski,

as per my previous quire. Still it is not showing right information about layers

Quote (shanmuk)



This is the actual code that we tested for arcs.

CODE -->

lw.WriteLine("moving objects from layer: " & arc1.Layer.ToString & " to layer: " & arclayer.ToString)
ufs.Obj.SetLayer(arc1.Tag, arclayer)



We tried by changing the arc layer to 25 and then executed the journal
even though it showing the message shown below.

Quote (shanmuk)




moving objects from layer X to layer Y...
user answered: Yes
moving objects from layer: 61 to layer: 61


Thanks & Regards,
Sam

RE: Error after running journal..

Can you post your current code in full?

I tried making the change to your previously posted code, but I don't get the same message you report...

www.nxjournaling.com

RE: Error after running journal..

(OP)
Hi cowski,
How are you. ?
After a long time.

Here is the full code.
This code is showing information for geometry's. But, we need the same as well for components and datums.

Pleas help us...


CODE --> VB

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

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 theUISession As UI = UI.GetUI
	Dim response As Integer
        Dim answer As String = "" 

		lw.Open
 
        response = theUISession.NXMessageBox.Show("Question", NXMessageBox.DialogType.Question, " POINTS WILL MOVE TO LAYER 60")
        '1 = Yes
        '2 = No
 
        If response = 1 Then
			'code to run in response to "yes" answer
            answer = "Yes"
			lw.WriteLine("OPERATION HAS DONE")
        Else
			'code to run in response to "no" answer
            answer = "No"
       Exit Sub
       End If
		
		lw.WriteLine("user answered: " & answer)
          

        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 = 61
        Dim linelayer As Integer = 61
        Dim arclayer As Integer = 61
        Dim coniclayer As Integer = 61
        Dim splinelayer As Integer = 61
        Dim csyslayer As Integer = 100
        Dim daxislayer As Integer = 40
        Dim dplanelayer As Integer = 40
        Dim bodylayer As Integer = 1
        Dim sketchlayer As Integer = 20

        If pointcol.ToArray().Length > 0 Then
            For Each pt As Point In pointcol
                If (pt.Layer >79 or pt.Layer <60)
                lw.WriteLine("Points Moved: " & pt.Layer.ToString & " to layer: " & pointslayer.ToString) 
                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 < 240 Then
                 If ((ln.Layer >79 or ln.Layer <60) and (ln.Layer >256 or ln.Layer <241) and ln.Layer >1 and (ln.layer >199 or ln.layer <80))
                 lw.WriteLine("Lines Moved: " & ln.Layer.ToString & " to layer: " & linelayer.ToString)
                 ufs.Obj.SetLayer(ln.Tag, linelayer)
	      	End If
	      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 and (arc1.layer >199 or arc1.layer <80)) 
                lw.WriteLine("arcs Moved: " & arc1.Layer.ToString & " to layer: " & arclayer.ToString) 
                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 and (sp.layer >199 or sp.layer <80))
                lw.WriteLine("SPlines Moved: " & sp.Layer.ToString & " to layer: " & splinelayer.ToString)
                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 and (sb.layer >199 or sb.layer <80)) Then
                lw.WriteLine("All Bodies Moved: " & sb.Layer.ToString & " to layer: " & bodylayer.ToString) 
		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

                Dim junk As DatumPlane = obj
                If junk.Feature.FeatureType.ToString = "DATUM_PLANE" Then
                    Try
                        Dim parentFeat As Features.Feature() = junk.Feature.GetParents
                        If parentFeat(0).GetFeatureName.Contains(" ") Then
                            Continue For
                        End If
                    Catch ex As Exception

                    End Try
                End If


                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 <20) and (sk.layer >199 or sk.layer <80))
                lw.WriteLine("All Sketches Moved: " & sk.Layer.ToString & " to layer: " & sketchlayer.ToString)
                ufs.Obj.SetLayer(sk.Tag, sketchlayer)
             End If
		sk.Activate(False)
		sk.UpdateGeometryDisplay()
		sk.Deactivate(False, Sketch.UpdateLevel.SketchOnly)
            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
		
		If (myFeature.FeatureType = "DATUM_CSYS") AndAlso (Not myFeature.IsInternal) Then
			Dim DBuilder As DatumCsysBuilder
			DBuilder = workPart.Features.CreateDatumCsysBuilder(myFeature)
			Dim DCObj() As NXObject = DBuilder.GetCommittedObjects
		
			For Each temp As DisplayableObject In DCObj
			temp.Layer = dplanelayer
			temp.RedisplayObject()
			Next
			DBuilder.Destroy()
		
			Dim updateMark As Session.UndoMarkId
			updateMark = s.SetUndoMark(Session.MarkVisibility.Invisible, "update")
			Try
				s.UpdateManager.LogForUpdate(myFeature)
				s.UpdateManager.DoUpdate(updateMark)
			Catch ex As Exception
		
			End Try
		
		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 and (objlayer >199 or objlayer <80))  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 when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
 
    End Function
 
End Module 

Thanks & Regards,
Sam

RE: Error after running journal..

I create an arc on layer 25 and run your journal, I get the message:
"arcs Moved: 25 to layer: 61"

I check the arc properties and it is now on layer 61. I run the journal again and get no message about moving arcs. Is there a certain series of steps I need to take to see the same message you see?

Side note: you may want to revisit your layer test for arcs -

CODE

If (arc1.Layer >79 or arc1.Layer <60 and (arc1.layer >199 or arc1.layer <80)) 

As it is currently written, it will move all arcs except those on layers 60-79. If this is your intent, the code can be simplified. If it is not your intent, you will need to fix it.

www.nxjournaling.com

RE: Error after running journal..

(OP)
Yes cowski,

My intent is that all arcs should be in between layers 60 to 79 as per our standards. Because of this reason that code has been written.
So, How can we proceed now..?

Thanks & Regards,
Sam

RE: Error after running journal..

In that case, your test can be simplified to:

CODE

If (arc1.Layer >79 or arc1.Layer <60) Then 


Are you still getting the message about the arc moving from layer 61 to layer 61? I wasn't able to reproduce the unexpected message...

www.nxjournaling.com

RE: Error after running journal..

(OP)
1.

Quote (COWSKI)



If (arc1.Layer >79 or arc1.Layer <60 and (arc1.layer >199 or arc1.layer <80))


I am sorry for not giving clear information. As we have some standards, In that arcs should be in between 60 to 79 layers. In the same way we have some empty layers (i.e from 80 to 199) we can keep any type of geometry`s or bodies in these layers.

2.

CODE --> cowski

Are you still getting the message about the arc moving from layer 61 to layer 61? I wasn't able to reproduce the unexpected message... 

No, we are not getting that message. It is showing in a right way (eg: if arcs are in 25 after running journal it showing that "arcs moved: 25 to 61" as you already tested. But, we need the same information for datums and assembly components also. If you see the code we didn't kept any lw.lines for datums and components (we don`t know how to do it). For arcs and line we have done by basing on your suggestion.



Thanks & Regards,
Sam

RE: Error after running journal..

If you have arcs on layers 80 to 199, your current journal will move them.

www.nxjournaling.com

RE: Error after running journal..

(OP)
No, It wont move the arcs which are in layers 80 to 199.

Thanks & Regards,
Sam

RE: Error after running journal..

Quote (shanmuk44)

No, It wont move the arcs which are in layers 80 to 199.

And you know this because you have tested it??

www.nxjournaling.com

RE: Error after running journal..

(OP)
Yes absolutely right.

Thanks & Regards,
Sam

RE: Error after running journal..

In that case, you may want to retest the code you most recently posted...

www.nxjournaling.com

RE: Error after running journal..

(OP)
Cowski,

Please let us know about information window for datums and components

Quote (shanmuk)



It is showing in a right way (eg: if arcs are in 25 after running journal it showing that "arcs moved: 25 to 61" as you already tested. But, we need the same information for datums and assembly components also. If you see the code we didn't kept any lw.lines for datums and components (we don`t know how to do it). For arcs and line we have done by basing on your suggestion.

Thanks & Regards,
Sam

RE: Error after running journal..

(OP)

Quote (cowski)



In that case, you may want to retest the code you most recently posted...


ok, I will test and let you know the results

Thanks & Regards,
Sam

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources