Assigning Specific Feature Name

Hello,
Here below my recorded code. I want the feature name something like "abc123456" but it always assign automatic name to feature such as: ENLARGE(84), ENLARGE(85), ENLARGE(86), etc.

Thanks in advance

Dim enlargeBuilder1 As Features.EnlargeBuilder
enlargeBuilder1 = workPart.Features.CreateEnlargeBuilder(nullFeatures_Enlarge)

enlargeBuilder1.ResizeParameters.UStart.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.UStart.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.UEnd.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.UEnd.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.VStart.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.VStart.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.VEnd.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.VEnd.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.AnchorPosition = GeometricUtilities.SurfaceRangeBuilder.AnchorPositionType.Vertex1

enlargeBuilder1.ResizeParameters.UStart.Expression.RightHandSide = "1.41"

enlargeBuilder1.ResizeParameters.UEnd.Expression.RightHandSide = "1.81"

enlargeBuilder1.ResizeParameters.VStart.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.VEnd.Expression.RightHandSide = "0"

enlargeBuilder1.ExtensionType = Features.EnlargeBuilder.ExtensionTypes.Natural

enlargeBuilder1.IsCopy = True

enlargeBuilder1.ResizeParameters.UStart.Expression.RightHandSide = "0"

enlargeBuilder1.ResizeParameters.UEnd.Expression.RightHandSide = "0"

theSession.SetUndoMarkName(markId1, "Enlarge Dialog")

enlargeBuilder1.ResizeParameters.UStart.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.UEnd.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.VStart.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.VEnd.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

Dim brep1 As Features.Brep = CType(workPart.Features.FindObject("UNPARAMETERIZED_FEATURE(0)"), Features.Brep)

Dim face1 As Face = CType(brep1.FindObject("FACE 1 {(-0,-22.6103518143634,63.9619994617531) UNPARAMETERIZED_FEATURE(0)}"), Face)

enlargeBuilder1.Face.Value = face1

enlargeBuilder1.ResizeParameters.UStart.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.UEnd.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.VStart.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.VEnd.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.UStart.Expression.RightHandSide = "1"

enlargeBuilder1.ResizeParameters.UStart.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.UEnd.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.VStart.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.VEnd.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.UEnd.Expression.RightHandSide = "1"

enlargeBuilder1.ResizeParameters.UStart.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.UEnd.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.VStart.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

enlargeBuilder1.ResizeParameters.VEnd.Update(GeometricUtilities.OnPathDimensionBuilder.UpdateReason.Path)

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Enlarge")

Dim nXObject1 As NXObject
nXObject1 = enlargeBuilder1.Commit()

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()

displayModification1.ApplyToAllFaces = False

displayModification1.SetNewGrid(0, 0)

displayModification1.PoleDisplayState = False

displayModification1.KnotDisplayState = False

Dim objects1(0) As DisplayableObject
Dim enlarge1 As Features.Enlarge = CType(nXObject1, Features.Enlarge)

Dim face2 As Face = CType(enlarge1.FindObject("FACE 1 {(0,-22.6103518143634,63.9619994617531) ENLARGE(84)}"), Face)

objects1(0) = face2
displayModification1.Apply(objects1)

face2.Color = 32767

theSession.DeleteUndoMark(markId2, Nothing)

theSession.SetUndoMarkName(markId1, "Enlarge")

Dim expression1 As Expression = enlargeBuilder1.ResizeParameters.VStart.Expression

Dim expression2 As Expression = enlargeBuilder1.ResizeParameters.VEnd.Expression

Dim expression3 As Expression = enlargeBuilder1.ResizeParameters.UStart.Expression

Dim expression4 As Expression = enlargeBuilder1.ResizeParameters.UEnd.Expression

enlargeBuilder1.Destroy()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

After you have a reference to the feature, the "enlarge1" variable in your code above, you can use the .SetName() method to rename the feature. There is a setting in NX that will control how the custom name will appear in the part navigator; it can be found in the customer defaults at Gateway -> part navigator -> Name display. There are three options for the name display:

  • System and user
  • System only
  • user replaces system

For illustration, let's say the feature is ENLARGE(85) and you want to name it "abc123". If the option is set to system and user, the result will appear as ENLARGE(85) "abc123" in the part navigator. System only will ignore the custom name and user replaces system will show only the custom name.


enlarge1.SetName("abc123")

Following code will search for that specific name. Is it possible code to find "abc123" feature?
Thanks

A similar question was posted a while back, you can find sample code to find a specific named feature here:
http://nxjournaling.com/comment/1766#comment-1766

My aim is to enlarge some surfaces, then trimming them. The trimming code should find those enlarged surfaces. But how?
Thanks

Giving the feature a custom name is a good way to find it again. Alternatively, you could assign a custom attribute to the feature; this would not show up in the part navigator, but could be used in the future to find the feature.

Could you share an example please?

An example of finding a feature by name can be found here:
http://nxjournaling.com/comment/1766#comment-1766

The following code will loop through all the dimensions in the workpart, checking each to see if it has an attribute named "offset". The logic for finding a feature with a given attribute would be very similar.

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

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

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

For Each tempDim As Annotations.Dimension In workPart.Dimensions

Dim myAttributeInfo As NXObject.AttributeInformation
Try
lw.WriteLine("dim: " & tempDim.Tag.ToString)
myAttributeInfo = tempDim.GetUserAttribute("offset", NXObject.AttributeType.Real, -1)
lw.WriteLine("offset: " & myAttributeInfo.RealValue.ToString)
Catch ex As NXException
'lw.WriteLine(ex.ErrorCode & ": " & ex.Message)
End Try

Next

lw.Close()

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

Thank you very much for the answers.

Above code can work just once in my case, because when you several time run this code there will be many features having same attribute. So finding yields many item.

I found a solution for my case. The code was already creates the feature that will be searched. So here below:
Dim added1 As Boolean

'added1 = sewBuilder1.TargetBodies.Add(body1)
added1 = sewBuilder1.TargetBodies.Add(nSidedSurface1.getbodies)

'Dim body2 As Body = CType(workPart.Bodies.FindObject("THRU_CURVE(49)"), Body)

Dim added2 As Boolean
added2 = sewBuilder1.ToolBodies.Add(throughCurves1.getbodies)

using GetBodies solved...

How ever now it is not working in revolved features. Because there is no revolveBuilder1.GetBodies .GetBodies is not belonged to it...
Do you have any idea a class instead of .GetBodies for the revolveBuilder?
Thanks

The initial questions led me to believe that you wanted to name the feature on the first run of the journal then use the name to find the same feature on subsequent runs of the journal. I see now that you just want to get the bodies created by the feature. Good news, this is pretty easy to do.

In the revolve builder code, the revolve feature is created when the builder's .CommitFeature (or .Commit) method is called. At this point it will return a reference to the newly created feature. The revolve feature, like all of the BodyFeatures, has a .GetBodies method that will return the body(ies) created by the feature. The code snippet below shows how to use the reference returned from the builder to get the feature bodies.

'code for creating the revolveBuilder1 and setting its properties omitted for clarity
Dim feature1 As Features.Feature
feature1 = revolveBuilder1.CommitFeature()

revolveBuilder1.Destroy()

Dim theRevolveBodies() as Body
theRevolveBodies = feature1.GetBodies

Thank you very much but how could I think that way?

When digging into something new, my strategy is to use a combination of the journal recorder and the API reference document. So, if I wanted to create a revolve feature, then do something with the resulting body; I would first record a journal while creating a revolve feature. The resulting code would show me that I need to use something called a "RevolveBuilder". I'd then open up the API reference, click on the "index" tab and type in "revolvebuilder". This would lead me to the "RevolveBuilder class" topic which would list all the properties and methods available through this object. Reading through the recorded journal, I'd find this bit of interesting code:

Dim feature1 As Features.Feature
feature1 = revolveBuilder1.CommitFeature()

Back to the API reference, I see the .CommitFeature method "commits the feature parameters and creates the feature". The "feature1" variable must be the reference to my new feature. In the API reference, typing "feature" in the index would lead me to the "Feature class"; interesting stuff, but I don't immediately see anything about getting the bodies of the feature, maybe .GetEntities? At this point I may write some code to try out the .GetEntities method to see what it does, or I could poke around the API reference some more to see what I turn up. Since I know I have a "revolve feature", I type in "revolve" in the index; this leads me to the "Revolve class" which, according to the top of the page, "represents a revolve feature". Wonderful! just what I need. Reading through the list I would find the .GetBodies method - "returns the bodies created by the feature". Clicking the link shows me the syntax of the method:

Public Function GetBodies As Body()

This tells me that it will return an array of Body objects (the parentheses after the type, Body, indicates it is an array).

Now I can write code to process the bodies of my new revolve feature (look up "Body" in the API index to see what properties and methods Body objects offer):

For Each temp as Body in feature1.GetBodies
lw.writeline("layer: " & temp.Layer.ToString)
lw.writeline("is solid: " & temp.IsSolidBody.ToString)
lw.writeline("color number: " & temp.Color.ToString)
Next

Great! Thanks a lot!