Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NxOpen How to get ViewAlignment.Name of a specific view 1

Status
Not open for further replies.

Halasox

Civil/Environmental
Jun 5, 2016
16
I am trying to get the view alignment names of a view and then delete the associated alignments. I am currently doing it by known names but would like to avoid this due to possible issues if the views numbering changes ...

I understand that I need to use ViewAlignment.Name to get it, but not sure how!

Code:
    Dim viewAlignmentBuilder1 As NXOpen.Drawings.ViewAlignmentBuilder = Nothing
    viewAlignmentBuilder1 = workPart.ViewAlignments.CreateViewAlignmentBuilder()
    
    Try
        Dim viewAlignment1 As NXOpen.Drawings.ViewAlignment = CType(workPart.ViewAlignments.FindObject("ViewAlignment 1"), NXOpen.Drawings.ViewAlignment)
        viewAlignmentBuilder1.SelectedAlignment = viewAlignment1
        viewAlignmentBuilder1.DeleteCurrentAlignment()
        nXObject1 = viewAlignmentBuilder1.Commit()
    
        Dim viewAlignment3 As NXOpen.Drawings.ViewAlignment = CType(workPart.ViewAlignments.FindObject("ViewAlignment 3"), NXOpen.Drawings.ViewAlignment)
        viewAlignmentBuilder1.SelectedAlignment = viewAlignment3
        viewAlignmentBuilder1.DeleteCurrentAlignment()
        
        nXObject1 = viewAlignmentBuilder1.Commit()
        viewAlignmentBuilder1.Destroy()
    
        Catch ex As Exception
    End Try
 
Replies continue below

Recommended for you

The ViewAlignment.Name will be blank unless you have specifically given a name to the object. The "ViewAlignment 1" and "ViewAlignment 3" shown in your code above is probably coming from the journal identifier.

The part has a .ViewAlignments collection that you can iterate over and get each alignment object.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module report_view_alignments

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = ufsession.GetUFSession
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        If IsNothing(theSession.Parts.BaseDisplay) Then
            'need at least 1 open part
            Return
        End If

        lw.Open()

        For Each tempAlignment As Drawings.ViewAlignment In theSession.Parts.Work.ViewAlignments
            lw.WriteLine(tempAlignment.JournalIdentifier.ToString)
        Next
        lw.WriteLine("")


        lw.Close()

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

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

Part and Inventory Search

Sponsor