Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Create surface finish symbol - journal

Status
Not open for further replies.

rafl

Mechanical
May 30, 2011
41
0
0
PL
Hi
I have wrote a journal ( by editing some code I found) that creates surface finish symbol. The problem is it only selects drafting edges. Can some help me add also dimension selection.

Here's the code :
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Drawings

Module create_surface_finish_symbol

    Private theSession As Session = Session.GetSession()
    Private ufs As UFSession = UFSession.GetUFSession()
    Private theUI As UI = UI.GetUI()
    Private workPart As Part = theSession.Parts.Work
    Private displayPart As Part = theSession.Parts.Display
    Private lw As ListingWindow = theSession.ListingWindow

    Sub Main(ByVal args() As String)

        Dim edge1 As DisplayableObject = Nothing
        Dim view1 As DraftingView = Nothing
        Dim vwname As String = Nothing
        Dim cursor As Point3d = Nothing
        Dim obj_coords As Point3d = Nothing
        Dim cur_coords As Point3d = Nothing
        Dim nr As Integer = 1

        lw.Open()


        While select_a_curve_in_view("Select an edge in drafting view", edge1, cursor) = Selection.Response.Ok
            ufs.Ui.AskLastPickedView(vwname)
            view1 = CType(workPart.DraftingViews.FindObject(vwname), Drawings.DraftingView)
            obj_coords = get_position_on_object(edge1, view1, cursor)

            Dim screen_pos As Point3d
            If select_screen_pos(screen_pos) <> Selection.Response.Ok Then
                Return
            End If

            create_sf_symbol(edge1, obj_coords, screen_pos, view1)

        End While

    End Sub

    Function get_position_on_object(ByVal obj As DisplayableObject, ByVal aView As View, ByRef coords As Point3d)

        Dim guess1 As Double() = New Double(2) {}
        Dim pt1 As Double() = New Double(2) {}
        Dim pt2 As Double() = New Double(2) {}
        Dim min_dist As Double

        Dim loc_view As Point3d = MapAbs2View(aView, coords)

        Dim sp_view As New Point3d(loc_view.X, loc_view.Y, loc_view.Z + 1000)
        Dim ep_view As New Point3d(loc_view.X, loc_view.Y, loc_view.Z - 1000)
        Dim sp_abs As Point3d = MapView2Abs(aView, sp_view)
        Dim ep_abs As Point3d = MapView2Abs(aView, ep_view)

        Dim line1 As Line = theSession.Parts.Work.Curves.CreateLine(sp_abs, ep_abs)
        line1.SetVisibility(NXOpen.SmartObject.VisibilityOption.Visible)
        line1.RedisplayObject()

        ufs.Modl.AskMinimumDist(obj.Tag, line1.Tag, 0, guess1, 0, guess1, min_dist, pt1, pt2)

        Dim markId2 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
        theSession.UpdateManager.AddToDeleteList(line1)
        theSession.UpdateManager.DoUpdate(markId2)

        get_position_on_object = New Point3d(pt1(0), pt1(1), pt1(2))
    End Function

    Function MapView2Abs(ByVal aView As View, ByVal coords As Point3d)
        Dim vmx As Matrix3x3 = aView.Matrix
        Dim vw() As Double = {0, 0, 0, vmx.Xx, vmx.Xy, vmx.Xz, vmx.Yx, vmx.Yy, vmx.Yz}
        Dim abs() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
        Dim mx(11) As Double
        Dim irc As Integer
        Dim c() As Double = {coords.X, coords.Y, coords.Z}

        ufs.Trns.CreateCsysMappingMatrix(vw, abs, mx, irc)
        ufs.Trns.MapPosition(c, mx)

        MapView2Abs = New Point3d(c(0), c(1), c(2))
    End Function

    Function MapAbs2View(ByVal aView As View, ByVal coords As Point3d)
        Dim vmx As Matrix3x3 = aView.Matrix
        Dim vw() As Double = {0, 0, 0, vmx.Xx, vmx.Xy, vmx.Xz, vmx.Yx, vmx.Yy, vmx.Yz}
        Dim abs() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
        Dim mx(11) As Double
        Dim irc As Integer
        Dim c() As Double = {coords.X, coords.Y, coords.Z}

        ufs.Trns.CreateCsysMappingMatrix(abs, vw, mx, irc)
        ufs.Trns.MapPosition(c, mx)

        MapAbs2View = New Point3d(c(0), c(1), c(2))
    End Function

    Function create_sf_symbol(ByVal edge1 As DisplayableObject, ByVal origin As Point3d, _
        ByVal screen_pos As Point3d, ByVal view1 As DraftingView)



        Dim nullAnDrafSF As Annotations.DraftingSurfaceFinish = Nothing
        Dim SurfFinish As Annotations.DraftingSurfaceFinishBuilder
        Dim LeaderData As Annotations.LeaderData = workPart.Annotations.CreateLeaderData()
        Dim nullView As View = Nothing
        Dim model_pt As Double() = {origin.X, origin.Y, origin.Z}
        Dim map_pt As Double() = New Double(1) {}
        ufs.View.MapModelToDrawing(view1.Tag, model_pt, map_pt)


        SurfFinish = workPart.Annotations.DraftingSurfaceFinishSymbols.CreateDraftingSurfaceFinishBuilder(nullAnDrafSF)

        SurfFinish.Finish = Annotations.DraftingSurfaceFinishBuilder.FinishType.ModifierMaterialRemovalRequired
        SurfFinish.Origin.SetInferRelativeToGeometry(True)
        SurfFinish.A2 = "0.32"
        SurfFinish.Style.LetteringStyle.GeneralTextSize = 2.5


        If map_pt(1) < screen_pos.Y Then

            SurfFinish.InvertText = False
            SurfFinish.InvertSymbol = False


        ElseIf map_pt(0) < screen_pos.X Then

            SurfFinish.InvertText = True
            SurfFinish.InvertSymbol = True



        ElseIf map_pt(1) > screen_pos.Y Then

            SurfFinish.InvertText = True
            SurfFinish.InvertSymbol = True


        ElseIf map_pt(0) > screen_pos.X Then

            SurfFinish.InvertText = False
            SurfFinish.InvertSymbol = False

        End If

        LeaderData.TerminatorType = Annotations.LeaderData.LeaderType.Flag
        LeaderData.Leader.SetValue(edge1, view1, origin)
        SurfFinish.Leader.Leaders.Append(LeaderData)
        SurfFinish.Origin.Origin.SetValue(Nothing, nullView, screen_pos)


        Dim nXObject1 As NXObject
        nXObject1 = SurfFinish.Commit()
        SurfFinish.Destroy()



    End Function

    Function select_a_curve_in_view(ByVal prompt As String, ByRef obj As DisplayableObject, ByRef cursor As Point3d)
        Dim mask(3) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_line_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With
        With mask(1)
            .Type = UFConstants.UF_section_edge_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With
        With mask(2)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_EDGE
        End With
        With mask(3)
            .Type = UFConstants.UF_solid_silhouette_type
            .Subtype = 0
            .SolidBodySubtype = 0
        End With
    
        'With mask(4)
        ' .Type = UFConstants.UF_conic_type
        '  .Subtype = 0
        '   .SolidBodySubtype = 0
        'End With
        'With mask(5)
        ' .Type = UFConstants.UF_spline_type
        '  .Subtype = 0
        '   .SolidBodySubtype = 0
        'End With

        ' With mask(6)
        '.Type = UFConstants.UF_circle_type
        '.Subtype = 0
        '.SolidBodySubtype = 0
        'End With

        Dim ufs As UFSession = UFSession.GetUFSession()
        ufs.Ui.SetCursorView(0)

        Dim resp As Selection.Response = _
        theUI.SelectionManager.SelectTaggedObject(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

    Function select_screen_pos(ByRef loc As Point3d) As Selection.Response

        Dim resp As Selection.DialogResponse = Selection.DialogResponse.None
        Dim localView As View
        ufs.Ui.SetCursorView(1)

        resp = theUI.SelectionManager.SelectScreenPosition("Screen Position:", _
                                                             localView, loc)
        If resp <> Selection.DialogResponse.Back And _
           resp <> Selection.DialogResponse.Cancel Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        Return Session.LibraryUnloadOption.Immediately

    End Function

End Module
 
Replies continue below

Recommended for you

Modifying your "select_a_curve_in_view" function to add another selection mask will allow you to select dimensions.

Code:
With mask(4)
    .Type = UFConstants.UF_dimension_type
    .Subtype = UFConstants.UF_all_subtype
End With

However, other changes will need to be made to accommodate the new selection.

www.nxjournaling.com
 
Thanks, dimension selection works. What else do I need to change if I want to attach the symbol to selected dimension?
 
I see your code uses the .AskLastPickedView function and attempts to convert the view to a drafting view. Most dimensions are placed on the drawing sheet itself; the view for the sheet is NOT a drafting view, you might get an error when trying to convert the drawing sheet view to a drafting view. If this is the case, the code will need to be modified to handle both view types.

www.nxjournaling.com
 
Status
Not open for further replies.
Back
Top