Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Error after running journal..

Status
Not open for further replies.

DesEngineer4

Mechanical
Feb 19, 2013
181
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
 
Replies continue below

Recommended for you

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.
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
 
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
 
shanmuk said:
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
 
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.

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

Thanks & Regards,
Sam
 
Hi cowski,

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

shanmuk said:
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.

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

Thanks & Regards,
Sam
 
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
 
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:
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
 
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
 
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
 
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
 
1.
COWSKI said:
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:
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
 
No, It wont move the arcs which are in layers 80 to 199.

Thanks & Regards,
Sam
 
Cowski,

Please let us know about information window for datums and components

shanmuk said:
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
 
cowski said:
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor