×
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

Journal - Select objects to change layer

Journal - Select objects to change layer

Journal - Select objects to change layer

(OP)
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

RE: Journal - Select objects to change layer

Try the following:

CODE

Option Strict Off  
Imports System  
Imports NXOpen  

Module NXJournal  
Sub Main  

Dim theSession As Session = Session.GetSession()  
Dim workPart As Part = theSession.Parts.Work  

Const DatumLayer as Integer = 62  
Const CurveLayer as Integer = 42  
Const SketchLayer as Integer = 22  
Const SheetLayer as Integer = 12  

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

'move curves
for each curveObj as Curve in workPart.Curves  
	curveObj.Layer = CurveLayer  
	curveObj.RedisplayObject  
next  

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

'move sheet bodies
for each bodyObj as Body in workPart.Bodies  
	if bodyObj.IsSheetBody then  
		bodyObj.Layer = SheetLayer  
		bodyObj.RedisplayObject  
	end if  
next  

End Sub  
End Module 

www.nxjournaling.com

RE: Journal - Select objects to change layer

(OP)
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

RE: Journal - Select objects to change layer

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
	if typeof(datumObj) is DatumPlane then
		datumObj.Layer = DatumLayer
		datumObj.RedisplayObject
	end if
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

RE: Journal - Select objects to change layer

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.

RE: Journal - Select objects to change layer

(OP)
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

RE: Journal - Select objects to change layer

(OP)
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.

RE: Journal - Select objects to change 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

Option Strict Off  
Imports System  
Imports NXOpen  

Module NXJournal  
Sub Main  

Dim theSession As Session = Session.GetSession()  
Dim workPart As Part = theSession.Parts.Work  

Const SketchLayerStart as Integer = 22  
dim i as integer = 0  


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


End Sub  
End Module 

www.nxjournaling.com

RE: Journal - Select objects to change layer

A CoordinateSystem and a DatumCsys are two different entities: the DatumCsys is a feature that encapsulates 3 datum planes, 3 datum axes, and a point; the CoordinateSystem 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 Part gives you access to. This has several advantages:
  • it will eliminate the need for many of the If TypeOf... statements
  • it returns both visible and hidden objects
  • you can control the order the types of objects are processed
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

RE: Journal - Select objects to change layer

Looks like that line should read:

CODE -->

sketchObj.Layer = SketchLayerStart + i 

RE: Journal - Select objects to change layer

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

RE: Journal - Select objects to change layer

Quote (holyghost)

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:
  • 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)
    Const SketchLayerStart as Integer = 22
  • edit your layer categories to match

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

www.nxjournaling.com

RE: Journal - Select objects to change layer

Yep working
thanks

RE: Journal - Select objects to change layer

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.

RE: Journal - Select objects to change layer

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 

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