Hi
below is code which is available in this site for getting zone of drafting datum,
suppose The output will be like
Datum : A
Sheet number : 3
Zone: A10
Datum : A
Sheet number : 2
Zone: A1
Datum : A
Sheet number : 1
Zone: B12
etc
How to get zone for only first occurance of each datum
Datum : A
Sheet number : 1
Zone: B12
Datum : B
Sheet number : 2
Zone: C5
Datum : C
Sheet number : 1
Zone: D7
etc
Can you please help me in getting zone of first occurnce of each datum, Thanks in Advance,
Below is cide :
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module5
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Sub Main()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
For Each temp As NXObject In theSession.Parts.Work.Gdts
'lw.WriteLine(" type: "& temp.GetType.ToString)
If TypeOf (temp) Is Annotations.DraftingDatum Then
Dim myDraftingDatum As Annotations.DraftingDatum = temp
Dim myDraftingDatumZone As New NXJSheetZoneInfo
myDraftingDatumZone = ReportAnnotationSheetZone(AskDrawingSheet(myDraftingDatum), myDraftingDatum)
lw.WriteLine("Datum: "& myDraftingDatum.Label)
lw.WriteLine("Sheet number: "& myDraftingDatumZone.Sheet)
lw.WriteLine("Zone: "& myDraftingDatumZone.VerticalZone & myDraftingDatumZone.HorizontalZone)
lw.WriteLine("")
End If
Next
lw.Close()
End Sub
Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet
'Code written by Amy Webster of GTAC
' see nx_api4936 or nx_api4937
' This function will work for:
' an object which "Resides on drawing" or is "View Dependent In" a DraftingView
' a DraftingView
' a DrawingSheet.View
' Returns Nothing for all other (ie. model mode) objects
Dim theView As View = TryCast(theObject, View)
If Not theView Is Nothing Then
Dim sheetTag As Tag = Nothing
Try
theUfSession.Draw.AskDrawingOfView(theView.Tag, sheetTag)
Return Utilities.NXObjectManager.Get(sheetTag) ' the drawing it is on
Catch ex As NXException
Return Nothing ' it is a model view
End Try
End If
Dim viewName As String = Nothing
Dim status As Integer = Nothing
Try
theUfSession.View.AskViewDependentStatus(theObject.Tag, status, viewName)
Catch ex As NXException
Return Nothing
End Try
If status = 0 Then Return Nothing ' it is a model mode object
Dim viewTag As Tag = Nothing
theUfSession.View.AskTagOfViewName(viewName, viewTag)
Dim viewType As Integer = Nothing
Dim viewSubtype As Integer = Nothing
theUfSession.View.AskType(viewTag, viewType, viewSubtype)
If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view
Dim drawingTag As Tag = Nothing
theUfSession.Draw.AskDrawingOfView(viewTag, drawingTag)
Return Utilities.NXObjectManager.Get(drawingTag) ' the drawing it is on!
End Function
Function ReportAnnotationSheetZone(ByVal theSheet As Drawings.DrawingSheet, ByVal theAnnotation As Annotations.Annotation) As NXJSheetZoneInfo
Dim info As New NXJSheetZoneInfo
Dim borderBuilder As Drawings.BordersAndZonesBuilder
If IsNothing(theSheet.BordersAndZones) Then
Return Nothing
End If
borderBuilder = theSession.Parts.Work.Drafting.BordersAndZonesObjects.CreateBordersAndZonesBuilder(theSheet.BordersAndZones)
Dim numHorizontalZones As Integer = (theSheet.Length - borderBuilder.LeftMargin - borderBuilder.RightMargin) / borderBuilder.HorizontalSize
Dim numVerticalZones As Integer = (theSheet.Height - borderBuilder.BottomMargin - borderBuilder.TopMargin) / borderBuilder.VerticalSize
'calculate zone wrt bottom left of drawing (ZoneOrigin.BottomLeft)
Dim Hcell As Double = (theAnnotation.AnnotationOrigin.X - borderBuilder.LeftMargin) / borderBuilder.HorizontalSize
Dim Vcell As Double = (theAnnotation.AnnotationOrigin.Y - borderBuilder.BottomMargin) / borderBuilder.VerticalSize
Hcell = Math.Ceiling(Hcell)
Vcell = Math.Ceiling(Vcell)
Dim theZoneOrigin As Drawings.BordersAndZonesBuilder.ZoneOrigin = borderBuilder.Origin
borderBuilder.Destroy()
Dim verticalLetterNum As Integer
Dim verticalLetter As Char
Dim horizontalNum As Integer
If theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.BottomLeft Or theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.TopLeft Then
'origin on left side
horizontalNum = Hcell
Else
'origin on right side
horizontalNum = numHorizontalZones - Hcell + 1
End If
If theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.BottomLeft Or theZoneOrigin = Drawings.BordersAndZonesBuilder.ZoneOrigin.BottomRight Then
'origin on bottom
verticalLetterNum = Asc("A") + Vcell - 1
verticalLetter = Chr(verticalLetterNum)
Else
'origin on the top
verticalLetterNum = Asc("A") + numVerticalZones - Vcell
verticalLetter = Chr(verticalLetterNum)
End If
Dim theSheetNum As String = SheetNumber(theSheet)
info.Sheet = theSheetNum
info.VerticalZone = verticalLetter
info.HorizontalZone = horizontalNum
Return info
End Function
Function SheetNumber(ByVal theSheet As Drawings.DrawingSheet) As String
Dim sheetNum As Integer
Dim theSheetBuilder As Drawings.DrawingSheetBuilder = theSession.Parts.Work.DrawingSheets.DrawingSheetBuilder(theSheet)
sheetNum = theSheetBuilder.Number
theSheetBuilder.Destroy()
Return sheetNum.ToString
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
Public Class NXJSheetZoneInfo
Private _sheet As String = ""
Public Property Sheet() As String
Get
Return _sheet
End Get
Set(ByVal value As String)
_sheet = value
End Set
End Property
Private _horizontalZone As String = ""
Public Property HorizontalZone() As String
Get
Return _horizontalZone
End Get
Set(ByVal value As String)
_horizontalZone = value
End Set
End Property
Private _verticalZone As String = ""
Public Property VerticalZone() As String
Get
Return _verticalZone
End Get
Set(ByVal value As String)
_verticalZone = value
End Set
End Property
Public Sub New()
End Sub
End Class