Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

DatumFeature move to layer 2

Status
Not open for further replies.

niedzviedz

Mechanical
Apr 1, 2012
307
Hello everyone,

Is there a simple way to move DatumFeature to specific layer? Right now I created something based on recorded journal:

Code:
For Each myFeature As Feature In workPart.Features

	If TypeOf (myFeature) Is DatumPlaneFeature Then

		Dim myDatum as Features.DatumPlaneFeature = myFeature
		myDatum.DatumPlane.Layer = DatumLayer
		myDatum.DatumPlane.RedisplayObject
		
	ElseIf TypeOf (myFeature) Is DatumFeature Then

		Dim objectArray1(0) As NXOpen.DisplayableObject
		Dim datumPlane1 As NXOpen.DatumPlane
		datumPlane1	= CType(workPart.Datums.FindObject(myFeature.GetFeatureName), NXOpen.DatumPlane)
		objectArray1(0) = datumPlane1
		workPart.Layers.MoveDisplayableObjects(DatumLayer, objectArray1)

	End If

DatumFeature doesn't have DatumPlane.Layer or Layer properties.

With best regards
Michael
 
Replies continue below

Recommended for you

In general, features don't have layer information - the displayable objects that they create have the layer information. Currently, only 2 feature types inherit from DatumFeature (DatumAxisFeature and DatumPlaneFeature); I'd suggest testing for DatumAxisFeature and DatumPlaneFeature then getting the layer info from the Axis or Plane.

Note that the code above would not affect a DatumCsys feature (which inherits from NXOpen.Features.Feature). If you want to move a datum csys feature, you will need to get all the components (planes, axes, csys, and point) and move them to the desired layer. If you search this site, you will find some code to help with that.

Also note that some features may be internal to other features (datums internal to a sketch or a sketch internal to an extrude, for instance); you can test for these with the feature's .IsInternal property or the .IsBrowseableFeature method.

www.nxjournaling.com
 
What I figured out is when plane is fixed, the type is DatumPlaneFeature, but when I create associative plane, i.e. offset plane the type is DatumFeature. That's why I added exception for DatumFeature. For the DatumCsys feature, Yes I know, some time ago I asked about moving some object for specifics layers. Right now I encountered problem with planes, that not each of them moved to desired layer.

With best regards
Michael
 
Hmmm, that isn't how it works for me. I started a new file in NX 12, created a fixed datum plane, then created an offset plane from the fixed plane. Code that loops through the features reported both as .DatumPlaneFeatures.

What version of NX are you using? Can you post an example file?

datum_plane_test_snyrqu.png


www.nxjournaling.com
 
The old style dialogs appear if you double click datum plane 6, 7, or 8. I suspect these older features are handled differently. If you need to work directly with the features, you might want to contact GTAC to see if they have a work-around.

If you don't need to work with the feature, you can iterate through the part's .Datums collection and work with the planes and axes directly.

Code:
For Each temp As TaggedObject In theSession.Parts.Work.Datums
    If TypeOf (temp) Is DatumAxis Then
        Dim theDatumAxis As DatumAxis = temp
        lw.WriteLine("Datum axis found, layer: " & theDatumAxis.Layer.ToString)
        lw.WriteLine("  created by feature: " & theDatumAxis.Feature.GetFeatureName)
    End If

    If TypeOf (temp) Is DatumPlane Then
        Dim theDatumPlane As DatumPlane = temp
        lw.WriteLine("Datum plane found, layer: " & theDatumPlane.Layer.ToString)
        lw.WriteLine("  created by feature: " & theDatumPlane.Feature.GetFeatureName)
    End If
Next

www.nxjournaling.com
 
Thanks @Cowski for Your support. I finally had time to use it. Below is code based on Your solution, maybe it will be useful for someone.

Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.Features
Imports NXOpen.Utilities
Imports NXOpen.UF

Module NXJournal

Sub Main (ByVal args() As String) 

	Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
	Dim ufs As UFSession = UFSession.GetUFSession()
	Dim workPart As NXOpen.Part = theSession.Parts.Work
	Dim displayPart As NXOpen.Part = theSession.Parts.Display

	Dim lw As ListingWindow = theSession.ListingWindow

	lw.open 

	Dim DatumLayer As Integer = 60
	Dim AxisLayer as Integer = 80
	
	Dim markId1 As NXOpen.Session.UndoMarkId
	markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

	theSession.SetUndoMarkName(markId1, "Layer Settings Dialog")
	
	Dim stateArray0(0) As NXOpen.Layer.StateInfo
	stateArray0(0) = New NXOpen.Layer.StateInfo(1, NXOpen.Layer.State.WorkLayer)
	workPart.Layers.ChangeStates(stateArray0, False)

	theSession.SetUndoMarkName(markId1, "Layer Settings")
	theSession.DeleteUndoMark(markId1, Nothing)	
	erase stateArray0
	
	For Each temp As TaggedObject In theSession.Parts.Work.Datums
	
		If TypeOf (temp) Is DatumAxis Then
		
			Dim theDatumAxis As DatumAxis = temp
			Dim objectArray1(0) As NXOpen.DisplayableObject
			
			'lw.WriteLine("Datum axis found, layer: " & theDatumAxis.Layer.ToString)
			'lw.WriteLine("  created by feature: " & theDatumAxis.Feature.GetFeatureName)
			
			objectArray1(0) = thedatumAxis
			workPart.Layers.MoveDisplayableObjects(AxisLayer, objectArray1)
			
		End If

		If TypeOf (temp) Is DatumPlane Then
		
			Dim theDatumPlane As DatumPlane = temp
			Dim objectArray2(0) As NXOpen.DisplayableObject
			
			'lw.WriteLine("Datum plane found, layer: " & theDatumPlane.Layer.ToString)
			'lw.WriteLine("  created by feature: " & theDatumPlane.Feature.GetFeatureName)
			
			objectArray2(0) = thedatumPlane
			workPart.Layers.MoveDisplayableObjects(DatumLayer, objectArray2)
			
		End If
		
	Next 

	Dim stateArray1(0) As NXOpen.Layer.StateInfo
	stateArray1(0) = New NXOpen.Layer.StateInfo(DatumLayer, NXOpen.Layer.State.Hidden)
	workPart.Layers.ChangeStates(stateArray1, False)
	erase stateArray1
	
	Dim stateArray2(0) As NXOpen.Layer.StateInfo
	stateArray2(0) = New NXOpen.Layer.StateInfo(AxisLayer, NXOpen.Layer.State.Hidden)
	workPart.Layers.ChangeStates(stateArray2, False)
	erase stateArray2	

	lw.close

End Sub

End Module

With best regards
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor