Journal Create text on face
Journal Create text on face
(OP)
I am trying to put text on a new revision part I made. I need to put an string of text on all of our revision parts.
I haven't been able to find any journals for this so I just recorded it. I do not know how to take care of line 82. This buttons should be universal for my parts but I do not know how to have it extract faces correctly. Any ideas?
I haven't been able to find any journals for this so I just recorded it. I do not know how to take care of line 82. This buttons should be universal for my parts but I do not know how to have it extract faces correctly. Any ideas?
CODE --> vb
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Annotations
Module NXJournal
Dim theSession As Session = Session.GetSession()
Sub Main
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim nullFeatures_Text As Features.Text = Nothing
If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw(New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If
Dim textBuilder1 As Features.TextBuilder
textBuilder1 = workPart.Features.CreateTextBuilder(nullFeatures_Text)
Dim origin1 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim normal1 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
Dim plane1 As Plane
plane1 = workPart.Planes.CreatePlane(origin1, normal1, SmartObject.UpdateOption.WithinModeling)
textBuilder1.SectionPlane = plane1
Dim section1 As Section
section1 = workPart.Sections.CreateSection(0.00095, 0.001, 0.5)
Dim unit1 As Unit
unit1 = textBuilder1.PlanarFrame.Length.Units
Dim expression1 As Expression
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim section2 As Section
section2 = workPart.Sections.CreateSection(0.00095, 0.001, 0.5)
Dim expression2 As Expression
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim coordinates1 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim point1 As Point
point1 = workPart.Points.CreatePoint(coordinates1)
textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "50"
textBuilder1.Script = Features.TextBuilder.ScriptOptions.Oem
textBuilder1.PlanarFrame.AnchorLocation = GeometricUtilities.RectangularFrameBuilder.AnchorLocationType.MiddleCenter
textBuilder1.PlanarFrame.Length.RightHandSide = "0.400726318359375"
textBuilder1.PlanarFrame.Height.RightHandSide = "0.125"
textBuilder1.PlanarFrame.WScale = 100.0
textBuilder1.PlanarFrame.Shear.RightHandSide = "0"
textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "25"
textBuilder1.FrameOnPath.Offset.RightHandSide = "0.25"
textBuilder1.FrameOnPath.Length.RightHandSide = "0.60308837890625"
textBuilder1.FrameOnPath.Height.RightHandSide = "0.25"
textBuilder1.SelectFont("Modern", Features.TextBuilder.ScriptOptions.Oem)
Dim face1 As Face
If Not select_a_face("Select Face", face1) = Selection.Response.Ok Then
Exit Sub
End If
Dim extractFace1 As Features.ExtractFace = CType(workPart.Features.FindObject("LINKED_BODY(3)"), Features.ExtractFace)
Dim xform1 As Xform
xform1 = workPart.Xforms.CreateXform(face1, SmartObject.UpdateOption.WithinModeling)
Dim cartesianCoordinateSystem1 As CartesianCoordinateSystem
cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, SmartObject.UpdateOption.WithinModeling)
textBuilder1.PlanarFrame.CoordinateSystem = cartesianCoordinateSystem1
textBuilder1.PlanarFrame.UpdateOnCoordinateSystem()
Dim coordinates2 As Point3d = New Point3d(-5.58837348662433e-008, 13.5, 3.625)
Dim point2 As Point
point2 = workPart.Points.CreatePoint(coordinates2)
workPart.Points.DeletePoint(point1)
textBuilder1.PlanarFrame.Length.RightHandSide = "0.484039306640625"
textBuilder1.TextString = "My Revision Part Name"
textBuilder1.PlanarFrame.Height.RightHandSide = "0.125"
textBuilder1.PlanarFrame.WScale = 100.0
Dim nXObject1 As NXObject
nXObject1 = textBuilder1.Commit()
Dim expression3 As Expression = textBuilder1.PlanarFrame.Shear
Dim expression4 As Expression = textBuilder1.PlanarFrame.Length
Dim expression5 As Expression = textBuilder1.PlanarFrame.Height
textBuilder1.Destroy()
Try
' Expression is still in use.
workPart.Expressions.Delete(expression2)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
section2.Destroy()
Try
' Expression is still in use.
workPart.Expressions.Delete(expression1)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try
Dim objects1(0) As NXObject
objects1(0) = plane1
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1)
section1.Destroy()
End Sub
Function select_a_face(ByVal prompt As String, ByRef obj As Face)
Dim ui As UI = GetUI()
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_solid_type
.Subtype = UFConstants.UF_solid_face_subtype
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
End With
Dim cursor As Point3d = Nothing
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject(prompt , prompt , _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, obj, cursor)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
return Selection.Response.Ok
Else
return Selection.Response.Cancel
End If
End Function
End Module Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17





RE: Journal Create text on face
www.nxjournaling.com
RE: Journal Create text on face
I am going to try to edit the DrawText file from the SampleNXOpenApplications folder for this purpose.
I receive 2 error messages.
The first one states "There is an object which depends on itself."
The second states "Error recovery failed because: Undo mark is missing. This occurred attempting to recover the following error:'There is an object which depends on itself.'. Parts in this session may be corrupt. Do not save your parts."
Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17
RE: Journal Create text on face
For the code above, I recorded it again and didn't edit it. I can select the face but I would not know how to check the Part Navigator for a linked body.
If I comment out the "extractFace" line I don't get anywhere. Any ideas?
CODE --> vb
Dim extractFace1 As Features.ExtractFace = CType(workPart.Features.FindObject("LINKED_BODY(3)"), Features.ExtractFace) Dim face1 As Face = CType(extractFace1.FindObject("FACE 2 {(-0.0000000558837,15.5,-1.0625) LINKED_BODY(3)}"), Face)Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17
RE: Journal Create text on face
www.nxjournaling.com
RE: Journal Create text on face
Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17