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..
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..
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..
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..
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..
It would be better...
Nice suggestion (Thank you Cowski)
Thanks & Regards,
Sam
RE: Error after running journal..
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..
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 Ifwww.nxjournaling.com
RE: Error after running journal..
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 Ifafter 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 IfThanks & Regards,
Sam
RE: Error after running journal..
www.nxjournaling.com
RE: Error after running journal..
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 Ifand at the top I kept like this..
CODE -->
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..
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..
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..
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 Modulewww.nxjournaling.com
RE: Error after running journal..
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.
This we changed to:
CODE -->
Dim parentFeat As Features.Feature() = junk.Feature.GetParents If parentFeat(0).GetFeatureName.Contains(" ") ThenThanks & Regards,
Sam
RE: Error after running journal..
We are expecting your solution for below thread also..
http://www.eng-tips.com/viewthread.cfm?qid=344151
Thanks & Regards,
Sam
RE: Error after running journal..
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..
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 ModuleThanks & Regards,
Sam
RE: Error after running journal..
CODE
www.nxjournaling.com
RE: Error after running journal..
May I know what skills required to be familiar with UGNX Customization.
Thanks & Regards,
Sam
RE: Error after running journal..
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..
Thanks & Regards,
Sam
RE: Error after running journal..
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..
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 IfAny lines on layer 240 or above will be ignored.
www.nxjournaling.com
RE: Error after running journal..
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..
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..
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..
Please see the attachment.
Thanks & Regards,
Sam
RE: Error after running journal..
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..
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 ModuleThanks & Regards,
Sam
RE: Error after running journal..
The csys in the attached picture didn't move because of this line of code:
CODE
If parentFeat(0).GetFeatureName.Contains(" ") ThenSpoiler:
www.nxjournaling.com
RE: Error after running journal..
What code to be inserted in this journal to avoid that...
Thanks & Regards,
Sam
RE: Error after running journal..
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..
Please give me the code.
I dont know anything about nx journal.
Thanks & Regards,
Sam
RE: Error after running journal..
Can you give me the code for layers
Thanks & Regards,
Sam
RE: Error after running journal..
Please try to give me the code. If you have a free time.
Thanks & Regards,
Sam
RE: Error after running journal..
www.nxjournaling.com
RE: Error after running journal..
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 Modulewww.nxjournaling.com
RE: Error after running journal..
I will try this code and let you know the results.
Thanks & Regards,
Sam
RE: Error after running journal..
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..
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 Modulewww.nxjournaling.com
RE: Error after running journal..
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.
Thanks & Regards,
Sam
RE: Error after running journal..
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 IfThanks & Regards,
Sam
RE: Error after running journal..
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..
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.
Thanks & Regards,
Sam
RE: Error after running journal..
as per my previous quire. Still it is not showing right information about layers
Thanks & Regards,
Sam
RE: Error after running journal..
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..
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 ModuleThanks & Regards,
Sam
RE: Error after running journal..
"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
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..
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..
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...
www.nxjournaling.com
RE: Error after running journal..
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
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..
www.nxjournaling.com
RE: Error after running journal..
Thanks & Regards,
Sam
RE: Error after running journal..
And you know this because you have tested it??
www.nxjournaling.com
RE: Error after running journal..
Thanks & Regards,
Sam
RE: Error after running journal..
www.nxjournaling.com
RE: Error after running journal..
Please let us know about information window for datums and components
Thanks & Regards,
Sam
RE: Error after running journal..
ok, I will test and let you know the results
Thanks & Regards,
Sam