×
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 Create text on face

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?


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

The extractFace1 variable isn't used anywhere else except in line 82; try commenting out that line and test to see what happens.

www.nxjournaling.com

RE: Journal Create text on face

(OP)
I noticed that and commented it but nothing changed, I can't move the component. I believe it is there to link the text to the linked body/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

(OP)
I tried the DrawText and looking into that but could not find anything conclusive that would be useful to me.
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

Are you running the code on solids in a part file, components in an assembly, or what?

www.nxjournaling.com

RE: Journal Create text on face

(OP)
This is being run on "comp_rev1" which has a linked body from "comp". These are components in an assembly.

Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17

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