Showing results for 
Search instead for 
Did you mean: 

Help on Journal 'link_exterior.vb'



I've found an interesting journal in the Solution Center. Using, it appears very usefull, but I need :

1) Comment the code where export to parasolid

2) Give the opportunity to link exterior slected component via NX selection UI interface


Option Strict Off

Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module create_linked_exterior_and_export_parasolid_result

    Dim theSession As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()

    Sub Main()
        Dim dPart As Part = theSession.Parts.Display
        Dim bodies() As Body = GetBodies(dPart)
        Dim comps(bodies.Length - 1) As Assemblies.Component
        Dim xforms(bodies.Length - 1) As NXOpen.Tag
        Dim body_tags(bodies.Length - 1) As NXOpen.Tag
        Dim proto As NXObject

        For ii As Integer = 0 To bodies.Length - 1
            If bodies(ii).IsOccurrence() Then
                comps(ii) = bodies(ii).OwningComponent
                proto = bodies(ii).Prototype
                body_tags(ii) = proto.Tag
                ufs.So.CreateXformAssyCtxt(comps(ii).Tag, _
                    comps(ii).Tag, NXOpen.Tag.Null, xforms(ii))
                comps(ii) = Nothing
                body_tags(ii) = bodies(ii).Tag
                xforms(ii) = NXOpen.Tag.Null
            End If

        Dim directions(,) As Double = _
            {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}
        Dim n_faces As Integer
        Dim faces() As Tag = Nothing
        Dim comp_index() As Integer = Nothing

        ufs.Modl.IdentifyExteriorUsingHl(bodies.Length, body_tags, _
            xforms, 6, directions, _
            dPart.Preferences.Modeling.DistanceToleranceData, _
            UFConstants.UF_LINKED_HL_RES_COARSE, n_faces, faces, comp_index)

        Dim extData As UFModl.LinkedExt
        With extData
            .at_timestamp = False
            .bodies = body_tags
            .delete_openings = True
            .faces = faces
            .group_results = UFConstants.UF_LINKED_EXT_GROUP_SINGLE
            .mass_props = True
            .num_bodies = bodies.Length
            .num_faces = n_faces
            .xform_index = comp_index
            .xforms = xforms
        End With

        Dim extFeat As NXOpen.Tag = Nothing
        Dim mark As Session.UndoMarkId = theSession.SetUndoMark( _
            Session.MarkVisibility.Visible, "Create Linked Exterior")

        ufs.Modl.CreateLinkedExterior(extData, extFeat)
        Dim n_groups As Integer
        Dim groups() As NXOpen.Tag = Nothing
        Dim n_subfeats As Integer
        Dim subfeats() As NXOpen.Tag = Nothing
        Dim mass_props(46) As Double

        ufs.Modl.AskLinkedExterior(extFeat, extData, n_groups, groups, _
            n_subfeats, subfeats, mass_props)

        Dim bList As ArrayList = New ArrayList
        Dim bTag As NXOpen.Tag

        For ii As Integer = 0 To n_subfeats - 1
            ufs.Modl.AskFeatBody(subfeats(ii), bTag)

        Dim bTags() As NXOpen.Tag = bList.ToArray(GetType(NXOpen.Tag))
        ufs.Ps.ExportData(bTags, "C:\temp\export_test.x_t")

    End Sub

    ' The Part Class BodyCollection does not include occurrences
    ' This function will return them as well as any local bodies

    Function GetBodies(ByVal in_part As Part) As Body()
        Dim a_body As Tag = NXOpen.Tag.Null
        Dim type, subtype As Integer
        Dim bList As ArrayList = New Arraylist

            ufs.Obj.CycleObjsInPart(in_part.Tag, _
                UFConstants.UF_solid_type, a_body)
            If Not a_body.Equals(NXOpen.Tag.Null) Then
                ufs.Obj.AskTypeAndSubtype(a_body, type, subtype)
                If subtype = UFConstants.UF_solid_body_subtype Then
                End If
            End If
        Loop While Not a_body.Equals(NXOpen.Tag.Null)

        Return bList.ToArray(GetType(Body))

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
    End Function

End Module
Thank you...

Using NX 11 / RuleDesigner PDM


Re: Help on Journal 'link_exterior.vb'

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

This is the line that exports the data to a parasolid file:

ufs.Ps.ExportData(bTags, "C:\temp\export_test.x_t")

Re: Help on Journal 'link_exterior.vb'




I am getting this failure message when I use the code and it is about the line who is mentioed above.

Can somebody help me why the code doesn't work?


Thank you