×
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

workPart.CoordinateSystems.CreateCoordinateSystem() and ufs.Obj.DeleteObject()

workPart.CoordinateSystems.CreateCoordinateSystem() and ufs.Obj.DeleteObject()

workPart.CoordinateSystems.CreateCoordinateSystem() and ufs.Obj.DeleteObject()

(OP)
When I use

CODE --> vb

cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.WithinModeling) 

the coordinate system can be successfully deleted with ufs.Obj.DeleteObject(). But when I change to

CODE --> vb

cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(pnt3d, v1, v2) 

the coordinate system remains in the graphics window. Why is that?

Here is full code:


CODE --> vb

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


Module Text_on_planar_face


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

    ' Dim s As Session = Session.GetSession()
    Dim ui As UI = UI.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()

    Sub Main()

        Dim response As Selection.Response = Selection.Response.Cancel
        Dim prompt As String = "Select Position on Face"
        Dim temptag As Tag = Tag.Null
        Dim cp(2) As Double
        Dim face1 As Face = Nothing
        Dim facetag As Tag = Tag.Null
        Dim pointC As Point = Nothing
        Dim displayPart As NXOpen.Part = theSession.Parts.Display



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


Start1:
        facetag = select_point_on_face(prompt, cp)

        If facetag = Tag.Null Then GoTo End1
        face1 = NXObjectManager.Get(facetag)
        Dim pnt3d As Point3d = New Point3d(cp(0), cp(1), cp(2))




        ' ----------------------------------------------
        '   Menu: Insert->Curve->Text...
        ' ----------------------------------------------
        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

        Dim nullNXOpen_Features_Text As NXOpen.Features.Text = Nothing

        Dim textBuilder1 As NXOpen.Features.TextBuilder = Nothing
        textBuilder1 = workPart.Features.CreateTextBuilder(nullNXOpen_Features_Text)

        Dim origin1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
        Dim normal1 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
        Dim plane1 As NXOpen.Plane = Nothing
        plane1 = workPart.Planes.CreatePlane(origin1, normal1, NXOpen.SmartObject.UpdateOption.WithinModeling)

        textBuilder1.SectionPlane = plane1

        Dim unit1 As NXOpen.Unit = Nothing
        unit1 = textBuilder1.PrintMarkThickness.Units

        Dim expression1 As NXOpen.Expression = Nothing
        expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

        Dim expression2 As NXOpen.Expression = Nothing
        expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

        Dim coordinates1 As NXOpen.Point3d = New NXOpen.Point3d(50.0, 50.0, 100.0)
        Dim point1 As NXOpen.Point = Nothing
        point1 = workPart.Points.CreatePoint(coordinates1)

        textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "50"

        textBuilder1.CanReferenceText = True

        textBuilder1.Script = NXOpen.Features.TextBuilder.ScriptOptions.CentralEuropean

        textBuilder1.PlanarFrame.AnchorLocation = NXOpen.GeometricUtilities.RectangularFrameBuilder.AnchorLocationType.MiddleCenter

        textBuilder1.PlanarFrame.Length.RightHandSide = "25.1931440266053"

        textBuilder1.PlanarFrame.Height.RightHandSide = "10"

        textBuilder1.PlanarFrame.WScale = 100.0

        textBuilder1.PlanarFrame.Shear.RightHandSide = "0"

        textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "44"

        textBuilder1.FrameOnPath.Offset.RightHandSide = "59"

        textBuilder1.FrameOnPath.Length.RightHandSide = "25.1931440266053"

        textBuilder1.FrameOnPath.Height.RightHandSide = "10"

        textBuilder1.PrintMarkThickness.RightHandSide = "1"

        textBuilder1.PrintMarkUsageLabel = "Mark 3"

        textBuilder1.SelectFont("Arial", NXOpen.Features.TextBuilder.ScriptOptions.CentralEuropean)

        textBuilder1.PrintMarkUsageLabel = "Mark 1"

        textBuilder1.TextString = "Text"

        theSession.SetUndoMarkName(markId1, "Text Dialog")

        plane1.SetMethod(NXOpen.PlaneTypes.MethodType.FixedZ)

        Dim geom1(-1) As NXOpen.NXObject
        plane1.SetGeometry(geom1)

        Dim origin2 As NXOpen.Point3d = New NXOpen.Point3d(50.0, 50.0, 100.0)
        plane1.Origin = origin2

        Dim matrix1 As NXOpen.Matrix3x3 = Nothing
        matrix1.Xx = 1.0
        matrix1.Xy = 0.0
        matrix1.Xz = 0.0
        matrix1.Yx = 0.0
        matrix1.Yy = 1.0
        matrix1.Yz = 0.0
        matrix1.Zx = 0.0
        matrix1.Zy = 0.0
        matrix1.Zz = 1.0
        plane1.Matrix = matrix1

        plane1.SetAlternate(NXOpen.PlaneTypes.AlternateType.One)

        plane1.Evaluate()

        plane1.SetMethod(NXOpen.PlaneTypes.MethodType.FixedZ)




        Dim faceA As NXOpen.Face = face1

        theSession.UpdateManager.ClearErrorList()
        Dim markId4 As Session.UndoMarkId
        markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")



        Dim xform1 As NXOpen.Xform = Nothing
        xform1 = workPart.Xforms.CreateXform(faceA, NXOpen.SmartObject.UpdateOption.WithinModeling)

        Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem = Nothing

        Dim v1 As NXOpen.Vector3d = New NXOpen.Vector3d(1.0, 0.0, 0.0)
        Dim v2 As NXOpen.Vector3d = New NXOpen.Vector3d(1.0, 1.0, 1.0)


        '-------------------------------------------------

        'cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.WithinModeling)
        cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(pnt3d, v1, v2)


        '-------------------------------------------------

        textBuilder1.PlanarFrame.CoordinateSystem = cartesianCoordinateSystem1

        textBuilder1.PlanarFrame.UpdateOnCoordinateSystem()

        Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(50.0, 100.0, 50.0)
        Dim point2 As NXOpen.Point = Nothing
        point2 = workPart.Points.CreatePoint(coordinates2)

        Dim expression3 As NXOpen.Expression = Nothing
        expression3 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

        Dim scalar1 As NXOpen.Scalar = Nothing
        scalar1 = workPart.Scalars.CreateScalar(0.086846488585013162, NXOpen.Scalar.DimensionalityType.None, NXOpen.SmartObject.UpdateOption.WithinModeling)

        Dim scalar2 As NXOpen.Scalar = Nothing
        scalar2 = workPart.Scalars.CreateScalar(0.86125397811750781, NXOpen.Scalar.DimensionalityType.None, NXOpen.SmartObject.UpdateOption.WithinModeling)

        Dim point3 As NXOpen.Point = Nothing
        point3 = workPart.Points.CreatePoint(face1, scalar1, scalar2, NXOpen.SmartObject.UpdateOption.WithinModeling)

        Dim nXObject1 As NXOpen.NXObject = Nothing
        Dim xform2 As NXOpen.Xform = Nothing
        xform2 = workPart.Xforms.CreateExtractXform(face1, NXOpen.SmartObject.UpdateOption.WithinModeling, False, nXObject1)

        Dim scalar3 As NXOpen.Scalar = Nothing
        scalar3 = workPart.Scalars.CreateScalar(0.086846488585013176, NXOpen.Scalar.DimensionalityType.None, NXOpen.SmartObject.UpdateOption.WithinModeling)

        Dim scalar4 As NXOpen.Scalar = Nothing
        scalar4 = workPart.Scalars.CreateScalar(0.86125397811750781, NXOpen.Scalar.DimensionalityType.None, NXOpen.SmartObject.UpdateOption.WithinModeling)

        Dim face2 As NXOpen.Face = CType(nXObject1, NXOpen.Face)

        Dim point4 As NXOpen.Point = Nothing
        point4 = workPart.Points.CreatePoint(face2, scalar3, scalar4, NXOpen.SmartObject.UpdateOption.WithinModeling)

        point4.RemoveViewDependency()

        Dim origin3 As NXOpen.Point3d = New NXOpen.Point3d(86.125397811750787, 100.0, 8.6846488585013191)

        '----------

        Dim vector1 As NXOpen.Vector3d = New NXOpen.Vector3d(1.0, 0.0, 0.0)
        Dim direction1 As NXOpen.Direction = Nothing
        direction1 = workPart.Directions.CreateDirection(origin3, vector1, NXOpen.SmartObject.UpdateOption.WithinModeling)

        Dim origin4 As NXOpen.Point3d = New NXOpen.Point3d(86.125397811750787, 100.0, 8.6846488585013191)

        '---------------

        Dim vector2 As NXOpen.Vector3d = New NXOpen.Vector3d(-0.0, 1.0, 0.0)
        Dim direction2 As NXOpen.Direction = Nothing
        direction2 = workPart.Directions.CreateDirection(origin4, vector2, NXOpen.SmartObject.UpdateOption.WithinModeling)

        Dim xform3 As NXOpen.Xform = Nothing
        xform3 = workPart.Xforms.CreateXformByPointXDirZDir(point4, direction1, direction2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0)

        Dim cartesianCoordinateSystem2 As NXOpen.CartesianCoordinateSystem = Nothing
        cartesianCoordinateSystem2 = workPart.CoordinateSystems.CreateCoordinateSystem(xform3, NXOpen.SmartObject.UpdateOption.WithinModeling)

        cartesianCoordinateSystem1.ReplaceParameters(cartesianCoordinateSystem2)

        cartesianCoordinateSystem1.Evaluate()

        textBuilder1.PlanarFrame.UpdateOnCoordinateSystem()


        theSession.UpdateManager.ClearErrorList()

        Dim markId5 As Session.UndoMarkId
        markId5 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")

        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.AddToDeleteList(cartesianCoordinateSystem1)

        Dim nErrs2 As Integer
        nErrs2 = theSession.UpdateManager.DoUpdate(markId5)


        Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Text")

        theSession.DeleteUndoMark(markId2, Nothing)

        Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Text")

        Dim nXObject2 As NXOpen.NXObject = Nothing
        nXObject2 = textBuilder1.Commit()

        theSession.DeleteUndoMark(markId3, Nothing)

        theSession.SetUndoMarkName(markId1, "Text")

        Dim expression4 As NXOpen.Expression = textBuilder1.PlanarFrame.Shear

        Dim expression5 As NXOpen.Expression = textBuilder1.PlanarFrame.Length

        Dim expression6 As NXOpen.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

        Try
            ' Expression is still in use.
            workPart.Expressions.Delete(expression1)
        Catch ex As NXException
            ex.AssertErrorCode(1050029)
        End Try

        plane1.DestroyPlane()

        workPart.Expressions.Delete(expression3)

        workPart.Points.DeletePoint(point3)

        ufs.Obj.DeleteObject(cartesianCoordinateSystem1.Tag)
        ' ----------------------------------------------
        '   Menu: Tools->Journal->Stop Recording
        ' ----------------------------------------------


        GoTo Start1
End1:



    End Sub



    Public Sub map_view2abs(ByRef c() As Double)
        Dim vname As String = ""
        Dim abs_mx() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
        Dim vw() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim mx() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim irc As Integer = 0
        ufs.Ui.AskLastPickedView(vname)
        Dim wp As Part = theSession.Parts.Work
        Dim lastViewPicked As View = CType(wp.ModelingViews.FindObject(vname), ModelingView)
        Dim vmx As Matrix3x3 = lastViewPicked.Matrix()
        vw(3) = vmx.Xx
        vw(4) = vmx.Xy
        vw(5) = vmx.Xz
        vw(6) = vmx.Yx
        vw(7) = vmx.Yy
        vw(8) = vmx.Yz
        vw(9) = vmx.Zx
        vw(10) = vmx.Zy
        vw(11) = vmx.Zz
        ufs.Trns.CreateCsysMappingMatrix(vw, abs_mx, mx, irc)
        ufs.Trns.MapPosition(c, mx)
    End Sub

    Public Sub map_abs2view(ByRef c() As Double)
        Dim vname As String = ""
        Dim abs_mx() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
        Dim vw() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim mx() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim irc As Integer = 0
        ufs.Ui.AskLastPickedView(vname)
        Dim wp As Part = theSession.Parts.Work
        Dim lastViewPicked As View =
            CType(wp.ModelingViews.FindObject(vname), ModelingView)
        Dim vmx As Matrix3x3 = lastViewPicked.Matrix()
        vw(3) = vmx.Xx
        vw(4) = vmx.Xy
        vw(5) = vmx.Xz
        vw(6) = vmx.Yx
        vw(7) = vmx.Yy
        vw(8) = vmx.Yz
        vw(9) = vmx.Zx
        vw(10) = vmx.Zy
        vw(11) = vmx.Zz
        ufs.Trns.CreateCsysMappingMatrix(abs_mx, vw, mx, irc)
        ufs.Trns.MapPosition(c, mx)

    End Sub

    Public Sub ask_pos_on_obj(ByVal obj As NXOpen.Tag, ByVal loc() As Double)
        Dim aLine As NXOpen.Tag = NXOpen.Tag.Null
        Dim cp() As Double = {0, 0, 0}
        Dim dist As Double = 0
        Dim lp As UFCurve.Line
        Dim sp(2) As Double
        Dim ep(2) As Double
        lp.start_point = sp
        lp.end_point = ep
        map_abs2view(loc)
        lp.start_point(0) = loc(0)
        lp.start_point(1) = loc(1)
        lp.start_point(2) = loc(2) + 10000
        lp.end_point(0) = loc(0)
        lp.end_point(1) = loc(1)
        lp.end_point(2) = loc(2) - 10000
        map_view2abs(lp.start_point)
        map_view2abs(lp.end_point)
        ufs.Curve.CreateLine(lp, aLine)
        ufs.Modl.AskMinimumDist(obj, aLine, 0, cp, 0, cp, dist, loc, cp)
        ufs.Obj.DeleteObject(aLine)
    End Sub

    Public Function mask_for_face(ByVal select_ As IntPtr, ByVal userdata As IntPtr) As Integer

        Dim num_triples As Integer = 1
        Dim mask_triples(0) As UFUi.Mask
        mask_triples(0).object_type = UFConstants.UF_solid_type
        mask_triples(0).object_subtype = 0
        mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
        ufs.Ui.SetSelMask(select_,
                UFUi.SelMaskAction.SelMaskClearAndEnableSpecific,
                                          num_triples, mask_triples)
        Return UFConstants.UF_UI_SEL_SUCCESS
    End Function

    Public Function select_point_on_face(ByVal prompt As String, ByRef cp() As Double) As NXOpen.Tag
        Dim resp As Integer = 0
        Dim thing As NXOpen.Tag = NXOpen.Tag.Null
        Dim face1 As Face = Nothing
        Dim theView As NXOpen.Tag = NXOpen.Tag.Null
        Dim mask_face As UFUi.SelInitFnT = AddressOf mask_for_face
        Dim facetag As Tag = Tag.Null
        ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        ufs.Ui.SelectWithSingleDialog("Select a face", prompt,
                    UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY,
                     mask_face, Nothing, resp, facetag, cp, theView)
        ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        If resp = UFConstants.UF_UI_OBJECT_SELECTED Or
           resp = UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
            ask_pos_on_obj(facetag, cp)
            ufs.Disp.SetHighlight(facetag, 0)
            Return facetag
        End If
        Return Tag.Null
    End Function

    Public Function PointFeatureOnFace(ByVal where As Point3d) As Point
        Dim markId1 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Point")
        Dim point1 As Point
        point1 = workPart.Points.CreatePoint(where)
        Dim nullFeatures_Feature As Features.Feature = Nothing
        Dim pointFeatureBuilder1 As Features.PointFeatureBuilder
        pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)
        pointFeatureBuilder1.Point = point1
        Dim nXObject1 As NXObject = pointFeatureBuilder1.Commit()
        pointFeatureBuilder1.Destroy()
        Return point1
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module 

RE: workPart.CoordinateSystems.CreateCoordinateSystem() and ufs.Obj.DeleteObject()

It is getting deleted. But the display is not being updated.

Add workPart.Views.WorkView.Regenerate() at the end.

Also, I see that you are deleting cartesianCoordinateSystem1 in two places.

Suresh
www.technisites.com.au

RE: workPart.CoordinateSystems.CreateCoordinateSystem() and ufs.Obj.DeleteObject()

(OP)
Thanks Suresh

I did some code clean-up and I can make it work.When I use only one coordinate system, I cannot delete it afterwards. When I try to replace parameters {cartesianCoordinateSystem1.ReplaceParameters(cartesianCoordinateSystem2)} the journal throws an error.
The idea is to place text on planar face with given point and two vectors. What is the best solution to make it work?

CODE --> vb

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports MiniSnap


Module Text_on_face


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

    ' Dim s As Session = Session.GetSession()
    Dim ui As UI = UI.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()

    Sub Main()

        Dim response As Selection.Response = Selection.Response.Cancel
        Dim prompt As String = "Select Position on Face"
        Dim temptag As Tag = Tag.Null
        Dim cp(2) As Double
        Dim face1 As Face = Nothing
        Dim facetag As Tag = Tag.Null
        Dim pointC As Point = Nothing
        Dim displayPart As NXOpen.Part = theSession.Parts.Display



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


Start1:
        facetag = select_point_on_face(prompt, cp)

        If facetag = Tag.Null Then GoTo End1
        face1 = NXObjectManager.Get(facetag)
        Dim pnt3d As Point3d = New Point3d(cp(0), cp(1), cp(2))

        ' ----------------------------------------------
        Dim ufmodl As UFModl = theUfSession.Modl
        Dim faceType As Integer
        Dim facePt As Double() = New Double(2) {}
        Dim faceDir As Double() = New Double(2) {}
        Dim bbox As Double() = New Double(5) {}
        Dim faceRadius As Double
        Dim faceRadData As Double
        Dim normDirection As Integer
        ufmodl.AskFaceData(facetag, faceType, facePt, faceDir, bbox, faceRadius, faceRadData, normDirection)
        Dim dir As Vector = faceDir
        Dim uvminmax As Double() = New Double(3) {}
        ufmodl.AskFaceUvMinmax(facetag, uvminmax)
        Dim umin As Double = uvminmax(0)
        Dim vmin As Double = uvminmax(2)
        Dim surfaceValue As NXOpen.UF.ModlSrfValue = New NXOpen.UF.ModlSrfValue()
        Dim mode As Integer = NXOpen.UF.UFConstants.UF_MODL_EVAL_UNIT_NORMAL
        ufmodl.EvaluateFace(facetag, mode, New Double() {umin, vmin}, surfaceValue)
        Dim u As Vector = surfaceValue.srf_du
        Dim v As Vector = Vector.Cross(dir, u)
        Dim oriview As Orientation = New Orientation(workPart.ModelingViews.WorkView.Matrix)
        Dim a0 As Double = u * oriview.AxisX + v * oriview.AxisY
        Dim a1 As Double = v * oriview.AxisX - u * oriview.AxisY
        Dim a2 As Double = -u * oriview.AxisX - v * oriview.AxisY



        ' ----------------------------------------------
        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

        Dim nullNXOpen_Features_Text As NXOpen.Features.Text = Nothing

        Dim textBuilder1 As NXOpen.Features.TextBuilder = Nothing
        textBuilder1 = workPart.Features.CreateTextBuilder(nullNXOpen_Features_Text)

        Dim unit1 As NXOpen.Unit = Nothing
        unit1 = textBuilder1.PrintMarkThickness.Units

        textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "50"
        textBuilder1.CanReferenceText = True
        textBuilder1.Script = NXOpen.Features.TextBuilder.ScriptOptions.CentralEuropean
        textBuilder1.PlanarFrame.AnchorLocation = NXOpen.GeometricUtilities.RectangularFrameBuilder.AnchorLocationType.MiddleCenter
        textBuilder1.PlanarFrame.Length.RightHandSide = "25.1931440266053"
        textBuilder1.PlanarFrame.Height.RightHandSide = "10"
        textBuilder1.PlanarFrame.WScale = 100.0
        textBuilder1.PlanarFrame.Shear.RightHandSide = "0"
        textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "44"
        textBuilder1.FrameOnPath.Offset.RightHandSide = "59"
        textBuilder1.FrameOnPath.Length.RightHandSide = "25.1931440266053"
        textBuilder1.FrameOnPath.Height.RightHandSide = "10"
        textBuilder1.PrintMarkThickness.RightHandSide = "1"
        textBuilder1.PrintMarkUsageLabel = "Mark 3"
        textBuilder1.SelectFont("Arial", NXOpen.Features.TextBuilder.ScriptOptions.CentralEuropean)
        textBuilder1.PrintMarkUsageLabel = "Mark 1"
        textBuilder1.TextString = "Text"
        theSession.SetUndoMarkName(markId1, "Text Dialog")



        Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem = Nothing

        '-------------------------------------------------

        Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(10.0, 10.0, 10.0)
        Dim vector1 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, -1.0)
        Dim vector2 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, -1.0, 0.0)
        cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(coordinates2, vector1, vector2)
        'cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(pnt3d, u, v)

        '-------------------------------------------------



        textBuilder1.PlanarFrame.CoordinateSystem = cartesianCoordinateSystem1
        textBuilder1.PlanarFrame.UpdateOnCoordinateSystem()

        Dim cartesianCoordinateSystem2 As NXOpen.CartesianCoordinateSystem = Nothing


        cartesianCoordinateSystem2 = workPart.CoordinateSystems.CreateCoordinateSystem(pnt3d, u, v)
        cartesianCoordinateSystem1.ReplaceParameters(cartesianCoordinateSystem2)

        cartesianCoordinateSystem1.Evaluate()

        textBuilder1.PlanarFrame.UpdateOnCoordinateSystem()

        ufs.Obj.DeleteObject(cartesianCoordinateSystem1.Tag)

        Dim nXObject2 As NXOpen.NXObject = Nothing
        nXObject2 = textBuilder1.Commit()
        textBuilder1.Destroy()

        ' ----------------------------------------------

        ' ----------------------------------------------
        workPart.Views.WorkView.Regenerate()
        theSession.SetUndoMarkName(markId1, "Text")

        GoTo Start1
End1:



    End Sub



    Public Sub map_view2abs(ByRef c() As Double)
        Dim vname As String = ""
        Dim abs_mx() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
        Dim vw() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim mx() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim irc As Integer = 0
        ufs.Ui.AskLastPickedView(vname)
        Dim wp As Part = theSession.Parts.Work
        Dim lastViewPicked As View = CType(wp.ModelingViews.FindObject(vname), ModelingView)
        Dim vmx As Matrix3x3 = lastViewPicked.Matrix()
        vw(3) = vmx.Xx
        vw(4) = vmx.Xy
        vw(5) = vmx.Xz
        vw(6) = vmx.Yx
        vw(7) = vmx.Yy
        vw(8) = vmx.Yz
        vw(9) = vmx.Zx
        vw(10) = vmx.Zy
        vw(11) = vmx.Zz
        ufs.Trns.CreateCsysMappingMatrix(vw, abs_mx, mx, irc)
        ufs.Trns.MapPosition(c, mx)
    End Sub

    Public Sub map_abs2view(ByRef c() As Double)
        Dim vname As String = ""
        Dim abs_mx() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
        Dim vw() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim mx() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim irc As Integer = 0
        ufs.Ui.AskLastPickedView(vname)
        Dim wp As Part = theSession.Parts.Work
        Dim lastViewPicked As View =
            CType(wp.ModelingViews.FindObject(vname), ModelingView)
        Dim vmx As Matrix3x3 = lastViewPicked.Matrix()
        vw(3) = vmx.Xx
        vw(4) = vmx.Xy
        vw(5) = vmx.Xz
        vw(6) = vmx.Yx
        vw(7) = vmx.Yy
        vw(8) = vmx.Yz
        vw(9) = vmx.Zx
        vw(10) = vmx.Zy
        vw(11) = vmx.Zz
        ufs.Trns.CreateCsysMappingMatrix(abs_mx, vw, mx, irc)
        ufs.Trns.MapPosition(c, mx)

    End Sub

    Public Sub ask_pos_on_obj(ByVal obj As NXOpen.Tag, ByVal loc() As Double)
        Dim aLine As NXOpen.Tag = NXOpen.Tag.Null
        Dim cp() As Double = {0, 0, 0}
        Dim dist As Double = 0
        Dim lp As UFCurve.Line
        Dim sp(2) As Double
        Dim ep(2) As Double
        lp.start_point = sp
        lp.end_point = ep
        map_abs2view(loc)
        lp.start_point(0) = loc(0)
        lp.start_point(1) = loc(1)
        lp.start_point(2) = loc(2) + 10000
        lp.end_point(0) = loc(0)
        lp.end_point(1) = loc(1)
        lp.end_point(2) = loc(2) - 10000
        map_view2abs(lp.start_point)
        map_view2abs(lp.end_point)
        ufs.Curve.CreateLine(lp, aLine)
        ufs.Modl.AskMinimumDist(obj, aLine, 0, cp, 0, cp, dist, loc, cp)
        ufs.Obj.DeleteObject(aLine)
    End Sub

    Public Function mask_for_face(ByVal select_ As IntPtr, ByVal userdata As IntPtr) As Integer

        Dim num_triples As Integer = 1
        Dim mask_triples(0) As UFUi.Mask
        mask_triples(0).object_type = UFConstants.UF_solid_type
        mask_triples(0).object_subtype = 0
        mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
        ufs.Ui.SetSelMask(select_,
                UFUi.SelMaskAction.SelMaskClearAndEnableSpecific,
                                          num_triples, mask_triples)
        Return UFConstants.UF_UI_SEL_SUCCESS
    End Function

    Public Function select_point_on_face(ByVal prompt As String, ByRef cp() As Double) As NXOpen.Tag
        Dim resp As Integer = 0
        Dim thing As NXOpen.Tag = NXOpen.Tag.Null
        Dim face1 As Face = Nothing
        Dim theView As NXOpen.Tag = NXOpen.Tag.Null
        Dim mask_face As UFUi.SelInitFnT = AddressOf mask_for_face
        Dim facetag As Tag = Tag.Null
        ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        ufs.Ui.SelectWithSingleDialog("Select a face", prompt,
                    UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY,
                     mask_face, Nothing, resp, facetag, cp, theView)
        ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        If resp = UFConstants.UF_UI_OBJECT_SELECTED Or
           resp = UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
            ask_pos_on_obj(facetag, cp)
            ufs.Disp.SetHighlight(facetag, 0)
            Return facetag
        End If
        Return Tag.Null
    End Function

    Public Function PointFeatureOnFace(ByVal where As Point3d) As Point
        Dim markId1 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Point")
        Dim point1 As Point
        point1 = workPart.Points.CreatePoint(where)
        Dim nullFeatures_Feature As Features.Feature = Nothing
        Dim pointFeatureBuilder1 As Features.PointFeatureBuilder
        pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)
        pointFeatureBuilder1.Point = point1
        Dim nXObject1 As NXObject = pointFeatureBuilder1.Commit()
        pointFeatureBuilder1.Destroy()
        Return point1
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module 

RE: workPart.CoordinateSystems.CreateCoordinateSystem() and ufs.Obj.DeleteObject()

You cannot delete the CSYS because the Text depends on it. You can make it invisible. Below is the updated code.

CODE -->

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports MiniSnap


Module Text_on_face


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

    ' Dim s As Session = Session.GetSession()
    Dim ui As UI = UI.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()

    Sub Main()

        Dim response As Selection.Response = Selection.Response.Cancel
        Dim prompt As String = "Select Position on Face"
        Dim temptag As Tag = Tag.Null
        Dim cp(2) As Double
        Dim face1 As Face = Nothing
        Dim facetag As Tag = Tag.Null
        Dim pointC As Point = Nothing
        Dim displayPart As NXOpen.Part = theSession.Parts.Display



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


Start1:
        facetag = select_point_on_face(prompt, cp)

        If facetag = Tag.Null Then GoTo End1
        face1 = NXObjectManager.Get(facetag)
        Dim pnt3d As Point3d = New Point3d(cp(0), cp(1), cp(2))

        ' ----------------------------------------------
        Dim ufmodl As UFModl = theUfSession.Modl
        Dim faceType As Integer
        Dim facePt As Double() = New Double(2) {}
        Dim faceDir As Double() = New Double(2) {}
        Dim bbox As Double() = New Double(5) {}
        Dim faceRadius As Double
        Dim faceRadData As Double
        Dim normDirection As Integer
        ufmodl.AskFaceData(facetag, faceType, facePt, faceDir, bbox, faceRadius, faceRadData, normDirection)
        Dim dir As Vector = faceDir
        Dim uvminmax As Double() = New Double(3) {}
        ufmodl.AskFaceUvMinmax(facetag, uvminmax)
        Dim umin As Double = uvminmax(0)
        Dim vmin As Double = uvminmax(2)
        Dim surfaceValue As NXOpen.UF.ModlSrfValue = New NXOpen.UF.ModlSrfValue()
        Dim mode As Integer = NXOpen.UF.UFConstants.UF_MODL_EVAL_UNIT_NORMAL
        ufmodl.EvaluateFace(facetag, mode, New Double() {umin, vmin}, surfaceValue)
        Dim u As Vector = surfaceValue.srf_du
        Dim v As Vector = Vector.Cross(dir, u)
        Dim oriview As Orientation = New Orientation(workPart.ModelingViews.WorkView.Matrix)
        Dim a0 As Double = u * oriview.AxisX + v * oriview.AxisY
        Dim a1 As Double = v * oriview.AxisX - u * oriview.AxisY
        Dim a2 As Double = -u * oriview.AxisX - v * oriview.AxisY



        ' ----------------------------------------------
        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

        Dim nullNXOpen_Features_Text As NXOpen.Features.Text = Nothing

        Dim textBuilder1 As NXOpen.Features.TextBuilder = Nothing
        textBuilder1 = workPart.Features.CreateTextBuilder(nullNXOpen_Features_Text)

        Dim unit1 As NXOpen.Unit = Nothing
        unit1 = textBuilder1.PrintMarkThickness.Units

        textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "50"
        textBuilder1.CanReferenceText = True
        textBuilder1.Script = NXOpen.Features.TextBuilder.ScriptOptions.CentralEuropean
        textBuilder1.PlanarFrame.AnchorLocation = NXOpen.GeometricUtilities.RectangularFrameBuilder.AnchorLocationType.MiddleCenter
        textBuilder1.PlanarFrame.Length.RightHandSide = "25.1931440266053"
        textBuilder1.PlanarFrame.Height.RightHandSide = "10"
        textBuilder1.PlanarFrame.WScale = 100.0
        textBuilder1.PlanarFrame.Shear.RightHandSide = "0"
        textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "44"
        textBuilder1.FrameOnPath.Offset.RightHandSide = "59"
        textBuilder1.FrameOnPath.Length.RightHandSide = "25.1931440266053"
        textBuilder1.FrameOnPath.Height.RightHandSide = "10"
        textBuilder1.PrintMarkThickness.RightHandSide = "1"
        textBuilder1.PrintMarkUsageLabel = "Mark 3"
        textBuilder1.SelectFont("Arial", NXOpen.Features.TextBuilder.ScriptOptions.CentralEuropean)
        textBuilder1.PrintMarkUsageLabel = "Mark 1"
        textBuilder1.TextString = "Text"
        theSession.SetUndoMarkName(markId1, "Text Dialog")



        Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem = Nothing

        '-------------------------------------------------

        'Dim coordinates2 As NXOpen.Point3d = New NXOpen.Point3d(10.0, 10.0, 10.0)
        'Dim vector1 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, -1.0)
        'Dim vector2 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, -1.0, 0.0)
        cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(pnt3d, u, v)

        '-------------------------------------------------



        textBuilder1.PlanarFrame.CoordinateSystem = cartesianCoordinateSystem1
        textBuilder1.PlanarFrame.UpdateOnCoordinateSystem()

        cartesianCoordinateSystem1.SetVisibility(SmartObject.VisibilityOption.Invisible)
        cartesianCoordinateSystem1.Evaluate()

        Dim nXObject2 As NXOpen.NXObject = Nothing
        nXObject2 = textBuilder1.Commit()
        textBuilder1.Destroy()

        ' ----------------------------------------------

        ' ----------------------------------------------
        theSession.SetUndoMarkName(markId1, "Text")

        GoTo Start1
End1:



    End Sub



    Public Sub map_view2abs(ByRef c() As Double)
        Dim vname As String = ""
        Dim abs_mx() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
        Dim vw() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim mx() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim irc As Integer = 0
        ufs.Ui.AskLastPickedView(vname)
        Dim wp As Part = theSession.Parts.Work
        Dim lastViewPicked As View = CType(wp.ModelingViews.FindObject(vname), ModelingView)
        Dim vmx As Matrix3x3 = lastViewPicked.Matrix()
        vw(3) = vmx.Xx
        vw(4) = vmx.Xy
        vw(5) = vmx.Xz
        vw(6) = vmx.Yx
        vw(7) = vmx.Yy
        vw(8) = vmx.Yz
        vw(9) = vmx.Zx
        vw(10) = vmx.Zy
        vw(11) = vmx.Zz
        ufs.Trns.CreateCsysMappingMatrix(vw, abs_mx, mx, irc)
        ufs.Trns.MapPosition(c, mx)
    End Sub

    Public Sub map_abs2view(ByRef c() As Double)
        Dim vname As String = ""
        Dim abs_mx() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
        Dim vw() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim mx() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
        Dim irc As Integer = 0
        ufs.Ui.AskLastPickedView(vname)
        Dim wp As Part = theSession.Parts.Work
        Dim lastViewPicked As View =
            CType(wp.ModelingViews.FindObject(vname), ModelingView)
        Dim vmx As Matrix3x3 = lastViewPicked.Matrix()
        vw(3) = vmx.Xx
        vw(4) = vmx.Xy
        vw(5) = vmx.Xz
        vw(6) = vmx.Yx
        vw(7) = vmx.Yy
        vw(8) = vmx.Yz
        vw(9) = vmx.Zx
        vw(10) = vmx.Zy
        vw(11) = vmx.Zz
        ufs.Trns.CreateCsysMappingMatrix(abs_mx, vw, mx, irc)
        ufs.Trns.MapPosition(c, mx)

    End Sub

    Public Sub ask_pos_on_obj(ByVal obj As NXOpen.Tag, ByVal loc() As Double)
        Dim aLine As NXOpen.Tag = NXOpen.Tag.Null
        Dim cp() As Double = {0, 0, 0}
        Dim dist As Double = 0
        Dim lp As UFCurve.Line
        Dim sp(2) As Double
        Dim ep(2) As Double
        lp.start_point = sp
        lp.end_point = ep
        map_abs2view(loc)
        lp.start_point(0) = loc(0)
        lp.start_point(1) = loc(1)
        lp.start_point(2) = loc(2) + 10000
        lp.end_point(0) = loc(0)
        lp.end_point(1) = loc(1)
        lp.end_point(2) = loc(2) - 10000
        map_view2abs(lp.start_point)
        map_view2abs(lp.end_point)
        ufs.Curve.CreateLine(lp, aLine)
        ufs.Modl.AskMinimumDist(obj, aLine, 0, cp, 0, cp, dist, loc, cp)
        ufs.Obj.DeleteObject(aLine)
    End Sub

    Public Function mask_for_face(ByVal select_ As IntPtr, ByVal userdata As IntPtr) As Integer

        Dim num_triples As Integer = 1
        Dim mask_triples(0) As UFUi.Mask
        mask_triples(0).object_type = UFConstants.UF_solid_type
        mask_triples(0).object_subtype = 0
        mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
        ufs.Ui.SetSelMask(select_,
                UFUi.SelMaskAction.SelMaskClearAndEnableSpecific,
                                          num_triples, mask_triples)
        Return UFConstants.UF_UI_SEL_SUCCESS
    End Function

    Public Function select_point_on_face(ByVal prompt As String, ByRef cp() As Double) As NXOpen.Tag
        Dim resp As Integer = 0
        Dim thing As NXOpen.Tag = NXOpen.Tag.Null
        Dim face1 As Face = Nothing
        Dim theView As NXOpen.Tag = NXOpen.Tag.Null
        Dim mask_face As UFUi.SelInitFnT = AddressOf mask_for_face
        Dim facetag As Tag = Tag.Null
        ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        ufs.Ui.SelectWithSingleDialog("Select a face", prompt,
                    UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY,
                     mask_face, Nothing, resp, facetag, cp, theView)
        ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        If resp = UFConstants.UF_UI_OBJECT_SELECTED Or
           resp = UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
            ask_pos_on_obj(facetag, cp)
            ufs.Disp.SetHighlight(facetag, 0)
            Return facetag
        End If
        Return Tag.Null
    End Function

    Public Function PointFeatureOnFace(ByVal where As Point3d) As Point
        Dim markId1 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Point")
        Dim point1 As Point
        point1 = workPart.Points.CreatePoint(where)
        Dim nullFeatures_Feature As Features.Feature = Nothing
        Dim pointFeatureBuilder1 As Features.PointFeatureBuilder
        pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)
        pointFeatureBuilder1.Point = point1
        Dim nXObject1 As NXObject = pointFeatureBuilder1.Commit()
        pointFeatureBuilder1.Destroy()
        Return point1
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module 

Suresh
www.technisites.com.au

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! Already a Member? Login


Resources

White Paper - Considerations for choosing a 3D printing technology
The adoption of 3D printing into major companies’ product development life cycles is a testament to the technology’s incredible benefits to consumers, designers, engineers and manufacturers. While traditional production methods have limitations in manufacturability, 3D printing provides unparalleled design freedom due to the additive method of building parts layer by layer. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close