Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Journal - Select objects to change layer

Status
Not open for further replies.

DavidQ

Industrial
Oct 11, 2012
53
Hello Eng-Tips

Attached you will find a journal that move Datums/Curves/Sketch & Sheets to differents layers. The main idea for this journal is to organize any objects in the view. There is an issue I can't find a solution (or a clue at least), after the objects have been move and trying to uncheck the Show/Hide checkbox in "Layer Settings" (Ctrl+L) the objects are still in View; these can be fixed by closing/opening the file but it would be annoying.

BestRegards
 
Replies continue below

Recommended for you

Try the following:

Code:
[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  

[COLOR=blue]Module[/color] NXJournal  
[COLOR=blue]Sub[/color] Main  

[COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
[COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  

[COLOR=blue]Const[/color] DatumLayer [COLOR=blue]as Integer =[/color] 62  
[COLOR=blue]Const[/color] CurveLayer [COLOR=blue]as Integer =[/color] 42  
[COLOR=blue]Const[/color] SketchLayer [COLOR=blue]as Integer =[/color] 22  
[COLOR=blue]Const[/color] SheetLayer [COLOR=blue]as Integer =[/color] 12  

[COLOR=green]'move datums[/color]
[COLOR=blue]for each[/color] datumObj [COLOR=blue]as[/color] DisplayableObject [COLOR=blue]in[/color] workPart.Datums  
	if typeof(datumObj) [COLOR=blue]is[/color] DatumPlane [COLOR=blue]then[/color]  
		datumObj.Layer [COLOR=blue]=[/color] DatumLayer  
		datumObj.RedisplayObject  
	end [COLOR=blue]if[/color]  
[COLOR=blue]next[/color]  

[COLOR=green]'move curves[/color]
[COLOR=blue]for each[/color] curveObj [COLOR=blue]as[/color] Curve [COLOR=blue]in[/color] workPart.Curves  
	curveObj.Layer [COLOR=blue]=[/color] CurveLayer  
	curveObj.RedisplayObject  
[COLOR=blue]next[/color]  

[COLOR=green]'move sketches[/color]
[COLOR=green]'do this after moving curves, sketch curves will update to sketch layer[/color]
[COLOR=blue]for each[/color] sketchObj [COLOR=blue]as[/color] Sketch [COLOR=blue]in[/color] workPart.Sketches  
	sketchObj.Activate(False)  
	sketchObj.Layer [COLOR=blue]=[/color] SketchLayer  
	sketchObj.RedisplayObject  
	sketchObj.Deactivate(False, Sketch.UpdateLevel.SketchOnly)  
[COLOR=blue]next[/color]  

[COLOR=green]'move sheet bodies[/color]
[COLOR=blue]for each[/color] bodyObj [COLOR=blue]as[/color] Body [COLOR=blue]in[/color] workPart.Bodies  
	if bodyObj.IsSheetBody [COLOR=blue]then[/color]  
		bodyObj.Layer [COLOR=blue]=[/color] SheetLayer  
		bodyObj.RedisplayObject  
	end [COLOR=blue]if[/color]  
[COLOR=blue]next[/color]  

End [COLOR=blue]Sub[/color]  
End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
Hellos cowski,

Thanks for your response. A few questions, I made some modification to the original code adding some "If Type" sentence to test if the tempObj is Datum Plane, Datum Axis, Datum Point or Datum Coordinate System, all four belong to DatumCollection Class.
I try to declared as such "If TypeOf tempObj Is DatumCOllection Then" and then change the layer but in response I get an error (I found out that layer is not a property of DatumCollection Class); so how could be the code to use DatumCollection to avoid doing four "IF TYPE" check or four "For Each /Next" check as you suggest.

BestRegards
 
In your code you were looking for datum planes only, so I replicated that in my code. If you want all the datums to move to the same layer you can skip the type check altogether.

Code:
'move datums
for each datumObj as DisplayableObject in workPart.Datums
	[s]if typeof(datumObj) is DatumPlane then[/s]
		datumObj.Layer = DatumLayer
		datumObj.RedisplayObject
	[s]end if[/s]
next

This will move all the datum types (plane, axis, point, csys) to the same layer.

However, if you want to separate datum planes to one layer, datum axes to another layer, etc; you'll have to check the type before moving them.

www.nxjournaling.com
 
Hi Cowski,
Asper your coding all Sketches, Datums, Curves etc will move in respective Layer. But My question is If I have used 5 sketches in my model, All 5 sketches has to move in different layer like 22,23,24,25 & 26. so, for this how to write coding.
Thanking you.
 
Cowski,
As ou suggested, I comment only "If Type" and "EndIf" lines and it only works with planes and axis but not with point and csys. I'm trying to move them separately but not luck so far. Attached you
 
Attached you will find the original code (final version) with some lines added to redisplay the layer (don't work). In this journal csys and point move to the indicated layer.
 
DavidQ,
I don't see an attachment...

holyghost,
One strategy would be to increment the sketch layer variable each time through the loop:

Code:
[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  

[COLOR=blue]Module[/color] NXJournal  
[COLOR=blue]Sub[/color] Main  

[COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
[COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  

[COLOR=blue]Const[/color] SketchLayerStart [COLOR=blue]as Integer =[/color] 22  
[COLOR=blue]dim[/color] i [COLOR=blue]as integer =[/color] 0  


[COLOR=green]'move sketches[/color]
[COLOR=blue]for each[/color] sketchObj [COLOR=blue]as[/color] Sketch [COLOR=blue]in[/color] workPart.Sketches  
	sketchObj.Activate(False)  
	sketchObj.Layer [COLOR=blue]=[/color] SketchLayer [COLOR=blue]+[/color] i  
	sketchObj.RedisplayObject  
	sketchObj.Deactivate(False, Sketch.UpdateLevel.SketchOnly)  
	i [COLOR=blue]+=[/color] 1  
[COLOR=blue]next[/color]  


End [COLOR=blue]Sub[/color]  
End [COLOR=blue]Module[/color]

www.nxjournaling.com
 
A [tt]CoordinateSystem[/tt] and a [tt]DatumCsys[/tt] are two different entities: the [tt]DatumCsys[/tt] is a feature that encapsulates 3 datum planes, 3 datum axes, and a point; the [tt]CoordinateSystem[/tt] is a saved csys, ie the result when you "save" the WCS (Format -> WCS -> Save).

I strongly suggest working with the collections of objects that the [tt]Part[/tt] gives you access to. This has several advantages:
[ul]
[li]it will eliminate the need for many of the [tt]If TypeOf...[/tt] statements[/li]
[li]it returns both visible and hidden objects[/li]
[li]you can control the order the types of objects are processed[/li]
[/ul]
The last point is especially important because the system does not differentiate between sketch curves and non-sketch curves. If you move a sketch object then later move a curve object that happens to belong to the sketch, it will remain out of sync until the sketch updates (the sketch will belong to one layer and its curves may belong to another).

www.nxjournaling.com
 
Looks like that line should read:

Code:
sketchObj.Layer = SketchLayerStart + i

 
Hi,
Its working fine , But those are not going to under Sketch Category those are going under Curve Category why? How to fix this problem
Thanks
 
holyghost said:
But those are not going to under Sketch Category those are going under Curve Category why? How to fix this problem

There are multiple ways to "fix" it, two of which are:
[ul]
[li]change the "22" in the following line to be the first "sketch" layer in your file (I used 22 because that is the number you mentioned in your original post)
[tt]Const SketchLayerStart as Integer = 22[/tt][/li]
[li]edit your layer categories to match[/li]
[/ul]


good catch, kfraysur, I didn't test the code before posting it. [smile]

www.nxjournaling.com
 
Hi
Everything is fine, But I fixed 15 layers only for sketchs like 21 to 35. Then how to write that ifany sketchs more than 15 , It should popup that sketch limit is crossed.
Thanks.
 
Something like this should work:

Code:
Const SketchLayerStart as Integer = 21

'Make 'MaxLayer' the last layer you are willing to move a sketch to
Const MaxLayer as Integer = 35  
dim i as integer = 0
dim j as integer = SketchLayerStart  


'move sketches
for each sketchObj as Sketch in workPart.Sketches  
	If j <= MaxLayer
             sketchObj.Activate(False)  
	     sketchObj.Layer = SketchLayerStart + i  
	     sketchObj.RedisplayObject  
	     sketchObj.Deactivate(False, Sketch.UpdateLevel.SketchOnly)  
	     i += 1
             j += 1
        Else
             Msgbox("The maximum sketch layer value of: " & MaxLayer & " has been exceeded)
        End If
next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor