View zone

Hello,
I would like to get the zone information (Sheet, ) of a selected drafting item such as a detail view.
Is there an example code for this?
Thanks

The code below illustrates how to report the sheet zone of the drafting views. The code will only work in NX 8 or above and the drawing sheet(s) must have zones defined.

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "report drafting view zone"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

For Each dwgSheet As Drawings.DrawingSheet In workPart.DrawingSheets

Dim dwgBorders As Drawings.BordersAndZones
dwgBorders = dwgSheet.BordersAndZones
If IsNothing(dwgBorders) Then
'no zones defined
lw.WriteLine("no zones defined for drawingsheet: " & dwgSheet.Name)
End If

For Each tempView As Drawings.DraftingView In dwgSheet.SheetDraftingViews
lw.WriteLine(tempView.Name & ": " & dwgSheet.GetZoneReference(tempView))
Next

Next

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

Nx makes associated note components consisting of a specified view component's zone information.
As I recorded a journal the related command line is "" I would like to automate this.

Click Note,
Click Symbols,
category->select relationship
->insert sheet zone
goes on

I recorded a journal and it gave me something like this:

Dim associativeText1 As Annotations.AssociativeText
associativeText1 = workPart.Annotations.CreateAssociativeText()

Dim text3(0) As String
text3(0) = associativeText1.GetObjectPropertyText(baseView1, Annotations.AssociativeText.PropertyType.DrawingSheetZone)

associativeText1.Dispose()

In place of "baseView1", use the view that you are interested in. The variable "text3(0)" will contain the necessary text for the associative note. You can do something similar for "sheet number", "sheet name", or other sheet variables.

is it possible to put a selection dialog for the targeted view?

The code below illustrates one way of interactively selecting a view.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim theDrftView As Drawings.DraftingView
If SelectDraftingView("select drafting view", theDrftView) = Selection.Response.Cancel Then
Return
End If

lw.WriteLine("view selected: " & theDrftView.Name)

lw.Close()

End Sub

Function SelectDraftingView(ByVal prompt As String, ByRef selView As Drawings.DraftingView) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a drafting view"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj As TaggedObject

With selectionMask_array(0)
.Type = UFConstants.UF_view_type
.Subtype = UFConstants.UF_all_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
selView = CType(selObj, Drawings.DraftingView)
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

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