Finding the zone of a letter in a note by Visualbasic

Hi Everybody
Assume that there are lots of views in a drawing and each view has a note where under it specifies View Name(for example View A, or Section B-B). I need to find the location of "A" or "B-B". (Drawing sheet has been seperated zones as horizontal "1...8" and vertical "A...J").
Thanks in advance

In the other hand, we can explain this problem like that: There are letters which have bigger height as "-c1.5625- A,B,C,....Z -c- " and a view or section label is specified in its detail view like "VIEW -c1.5625-F-c- SH 2 (D6)" and in the place where view or section is comes from there is a label like "-c1.5625-F-c- SH 3 (A6)". As you can see I need to specify all the zones as cross referenced eachother. I only need to find big letter's zones and write the cross zone informations in their labels automaticly.

What version of NX? If you are using NX 8.5 or later, you can create a note that associatively reports the sheet zone of a drawing view.

You can calculate the zone that a note is in with a journal, but the result will not be associative (if/when the note moves, your info will be out of date).

I am using NX 9, It is not important to be associatively, when we think that smt is changed, we can rerun the macro and it can refresh all the cross reference zones, how could it be?

There is some code in the following thread that reports the sheet zone of a dimension. Using the same principles, you could get it to report the zone of a note object.

http://nxjournaling.com/content/getting-x-and-y-coordinates-dimensions

I would like to show a picture about that, how can I upload it in this portal?

We don't currently allow picture uploads, but you are welcome to send it to info@nxjournaling.com.

I should also note that my previous suggestion will only work if you have the "borders & zones" activated in your drawing.

I have sent a mail to you, could you please help me?

Hello, could you please help me?

I'll look into it as I have time. Unfortunately, my current schedule does not allow much time for writing journal code.

I am looking forward to see the codes, it is very big problem for me, thanks for help

For a preview, here is how you can create the notes in interactive NX:
Find a section view and the corresponding parent view.
Start the note command, in the 'symbols' section of the dialog choose "insert sheet zone". Choose "sheet number" and select the parent view. Insert sheet zone again, pick "zone reference" and again select the parent view. Place the note under the section view label and associate the note to the view (or view label if you prefer).
Follow a similar process to note the section view location and associate the note to the parent view.

The journal code will simply automate the process of finding the section views and creating the notes.

Hi,

I've been reading your answers on creating journals, but as I'm new to this I can't edit much. Can you please help me with a journal for creating a Note with Sheet Zone Reference of Custom Symbol. Our client requires their custom symbols for View/Section Labels and Arrows. We need to place view label zone ref below view arrow and vice-versa. The normal method in NX lets me select Zone Ref for View and not for custom symbols. Can you help me with this?

Thanks in advance.

Regards,
Achintya

Achintya Paradkar
Design Engineer
Tata Technologies

A journal can be made that will find the custom symbols and create notes that report the sheet zone, but these notes will NOT be associative (i.e. the note will not update if/when the custom symbol is moved on the sheet).

Would a non-associative note work in your situation?

Hi,

Yes, the non-associative journal will definitely serve the purpose.
Can you kindly me share the code with me or provide any link for it?

Thanks for your help and efforts.

Regards,
Achintya

Achintya Paradkar
Design Engineer
Tata Technologies

When you have a reference to a part object, you can access the .Annotations.CustomSymbols collection. A DraftingCustomSymbolBuilder can be used to query the .Origin of the symbol. With the origin location, the sheet zone can be calculated as in the following thread (see the ReportDimensionSheetZone function):
http://nxjournaling.com/comment/1458#comment-1458

well, i did it. It works for sheet name but not for zone information, when I write the label shows "??" characters(zones are open). the second think is to automate that thing. I think that if I would be able to list all the nx code of the parent views and the child views and also their zone informations, then I would be able to write zone info of the parent to the child, and vica versa. By that way, I would be able to match the zone informations of parent and child eachother. Could we go further?

If the zone note shows "??", that indicates that the zone option is not set up correctly and NX can't find the zone information.

Very good, what about automating that? I mean how can program find all the zones for the view letters and to match parent zone info to child and vica versa ? Eventually program should edit label of parent view and write zone info of child view next to its letter, and vica versa?

The code below is a crude implementation of the process that I described. The journal will create a note associated to the view and place it below the view. If the view has multiple sections created from it, the notes will overlap; this is something that would need to be fixed for production use.

The code below was written/tested on NX 9 native. The NX borders & zones tool needs to be used to define the borders; it won't work if the zones are manually created in your drawing template file.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work

Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

lw.Open()

Dim allZonesDefined As Boolean = True
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)
allZonesDefined = False
End If
Next

If Not allZonesDefined Then
Return
End If

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

For Each temp As Drawings.DraftingView In workPart.DraftingViews

If TypeOf (temp) Is Drawings.SectionView Then

Dim parentView As Drawings.DraftingView
parentView = SectionViewParent(temp)

If IsNothing(parentView) Then
Continue For
End If

Dim theSheet As Drawings.DrawingSheet
theSheet = AskDrawingSheet(parentView)
theSheet.Open()

AddNoteRelativeToView(temp, parentView)

theSheet = AskDrawingSheet(temp)
theSheet.Open()
AddNoteRelativeToView(parentView, temp)

End If

Next

lw.Close()

End Sub

Function SectionViewParent(ByVal sxView As Drawings.SectionView) As Drawings.DraftingView

Dim sectionLineTag As Tag = Tag.Null
theUfSession.Draw.AskSxlineOfSxview(sxView.Tag, sectionLineTag)

Dim sectionLineType As UFDraw.SxlineType
theUfSession.Draw.AskSxlineType(sectionLineTag, sectionLineType)

Dim stepDir(2) As Double
Dim arrowDir(2) As Double
Dim parentViewTag As Tag = Tag.Null
Dim parentView As Drawings.DraftingView
Dim numSxViews As Integer
Dim sxViewTags() As Tag = Nothing
Dim numSegments As Integer
Dim segmentTags() As Tag = Nothing
Dim status As UFDraw.SxlineStatus
Dim rotationPtObj As UFDrf.Object = Nothing
Dim numLeg1Segments As Integer
Dim cutPlaneLeg As UFDraw.SxlineLeg

Select Case sectionLineType
Case Is = UFDraw.SxlineType.SimpleSxline
theUfSession.Draw.AskSimpleSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, numSxViews, sxViewTags, numSegments, segmentTags, status)

Case Is = UFDraw.SxlineType.SteppedSxline
theUfSession.Draw.AskSteppedSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, numSxViews, sxViewTags, numSegments, segmentTags, status)

Case Is = UFDraw.SxlineType.RevolvedSxline
theUfSession.Draw.AskRevolvedSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, rotationPtObj, numSxViews, sxViewTags, numSegments, numLeg1Segments, cutPlaneLeg, segmentTags, status)

Case Is = UFDraw.SxlineType.HalfSxline
theUfSession.Draw.AskHalfSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, numSxViews, sxViewTags, numSegments, segmentTags, status)

Case Is = UFDraw.SxlineType.UnfoldedSxline
theUfSession.Draw.AskUnfoldedSxline(sectionLineTag, stepDir, arrowDir, parentViewTag, numSxViews, sxViewTags, numSegments, segmentTags, status)

Case Is = UFDraw.SxlineType.FoldedSxline

Case Is = UFDraw.SxlineType.Breakline
'the view with the break is the section view itself

End Select

If parentViewTag = Tag.Null Then
Return Nothing
End If

parentView = Utilities.NXObjectManager.Get(parentViewTag)
Return parentView

End Function

Sub AddNoteRelativeToView(ByVal viewZoneInfo As Drawings.DraftingView, ByVal noteView As Drawings.DraftingView)

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Note")

Dim nullAnnotations_SimpleDraftingAid As Annotations.SimpleDraftingAid = Nothing

Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(nullAnnotations_SimpleDraftingAid)

draftingNoteBuilder1.Origin.Anchor = Annotations.OriginBuilder.AlignmentPosition.MidCenter

draftingNoteBuilder1.Origin.Plane.PlaneMethod = Annotations.PlaneBuilder.PlaneMethodType.XyPlane

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

Dim text4 As String
text4 = associativeText1.GetObjectPropertyText(viewZoneInfo, Annotations.AssociativeText.PropertyType.DrawingSheetName)

associativeText1.Dispose()

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

Dim text6 As String
text6 = associativeText2.GetObjectPropertyText(viewZoneInfo, Annotations.AssociativeText.PropertyType.DrawingSheetZone)

associativeText2.Dispose()

Dim text7(0) As String
text7(0) = "SEE " & text4 & " " & text6

draftingNoteBuilder1.Text.TextBlock.SetText(text7)

Dim assocOrigin1 As Annotations.Annotation.AssociativeOriginData
assocOrigin1.OriginType = Annotations.AssociativeOriginType.RelativeToView
assocOrigin1.View = noteView
Dim nullView As View = Nothing

draftingNoteBuilder1.Origin.SetAssociativeOrigin(assocOrigin1)

Dim viewSize(3) As Double
'retrieve the size of the view
theUfSession.Draw.AskViewBorders(noteView.Tag, viewSize)
Dim viewLength As Double = viewSize(2) - viewSize(0)
Dim viewHeight As Double = viewSize(3) - viewSize(1)

'midpoint of view location (X value)
Dim viewX As Double = viewLength / 2 + viewSize(0)

Dim point1 As Point3d = New Point3d(viewX, viewSize(1), 0.0)
draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, nullView, point1)

draftingNoteBuilder1.Origin.SetInferRelativeToGeometry(True)

Dim nXObject3 As NXObject
nXObject3 = draftingNoteBuilder1.Commit()

draftingNoteBuilder1.Destroy()

End Sub

' 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
Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet

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

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

I open drawing zones using "Drafting Tools>Borders and Zones> check in(Creater Borders, Create Zone Markings and Create Zone Labels)" but when I run the code, it gives an error "no zones defined for drawingsheet: SHT1" , how can I open zones correctly?

It sounds like you are on the right track. Make sure all the entries contain valid numbers and OK the dialog when done. You will know when it worked because it will draw the border and zone information around the edges of the sheet.

In order to fix overlaping, we need to put associative texts next to their parent labels, for example we have a section line and letter of the sect, we need to put zone info label next to parent section label. For childs, the zone info labels should be below of the child view.

There are multiple strategies that one could employ to fix the overlapping problem of the previously posted code. I'll leave it to you to implement the version that meets your needs. My intention was to show how to create and add the notes to the views. You will notice that the notes placed by the journal are associative to the view; when a view moves, the note moves with it and the zone information updates accordingly.

Borders are drawn, but it does not work for zones, may be I can take help for that from my colleagues, thank you for your considerable help, by the way where can I find a training pdf for basic code examples? I downloaded Siemens NX OPEN .NET Help but it does not contain examples

Some examples can be found in the NX install directory:
{NX install dir}\UGOPEN\Sample\NXOpenApplications

Of course some examples and explanation can also be found on this site.

Hi,

How to avoid overlapping of texts(when running tool 2nd time),
I tried to read all notes present store it in array & compare with the new notes.(text7) in your case
text7[0].gettext() will give you something -
& array of notes is reading something -
Any help Appreciated.

Thanks

This is Solved.
Thanks