Cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Zone value of SectionLine?

Valued Contributor
Valued Contributor

Hello,

 

I have created a few section view.

 

Now I am trying to find the zone value of section View and also the section Lines.

I am able to find the correct zone value of Section View but not able to get zone value for Section Line.

 

Below is the code, Please correct me where I am doing wrong?

 

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 dwgShtBld As Drawings.DrawingSheetBuilder
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If
        ZoneSet()
        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
                'Adding Note to the ParentView
                theSheet = AskDrawingSheet(parentView)
                theSheet.Open()
                AddNoteRelativeToView(temp, parentView)


                'Adding Not the Sectin View
                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


    Sub ZoneSet()


        Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
        Dim workPart As NXOpen.Part = theSession.Parts.Work

        Dim displayPart As NXOpen.Part = theSession.Parts.Display

        ' ----------------------------------------------
        '   Menu: Tools->Drawing Format->Borders and Zones...
        ' ----------------------------------------------

        Dim nullNXOpen_Drawings_BordersAndZones As NXOpen.Drawings.BordersAndZones = Nothing

        Dim bordersAndZonesBuilder1 As NXOpen.Drawings.BordersAndZonesBuilder = Nothing
        bordersAndZonesBuilder1 = workPart.Drafting.BordersAndZonesObjects.CreateBordersAndZonesBuilder(nullNXOpen_Drawings_BordersAndZones)

        bordersAndZonesBuilder1.BorderAndZoneStyle.SheetBorderSettingsStyle.Method = NXOpen.Drawings.Method.Custom


        bordersAndZonesBuilder1.BorderAndZoneStyle.SheetBorderSettingsStyle.CreateBorders = False

        bordersAndZonesBuilder1.BorderAndZoneStyle.SheetBorderSettingsStyle.CreateTrimmingMarks = False

        bordersAndZonesBuilder1.BorderAndZoneStyle.SheetZoneSettingsStyle.CreateZoneLabels = False

        bordersAndZonesBuilder1.BorderAndZoneStyle.SheetZoneSettingsStyle.CreateZoneMarkings = False

        bordersAndZonesBuilder1.BorderAndZoneStyle.SheetZoneSettingsStyle.CreateZones = True

        bordersAndZonesBuilder1.BorderAndZoneStyle.SheetZoneSettingsStyle.HorizontalSize = 50.0

        bordersAndZonesBuilder1.BorderAndZoneStyle.SheetZoneSettingsStyle.VerticalSize = 50.0

        Dim nXObject1 As NXOpen.NXObject = Nothing
        nXObject1 = bordersAndZonesBuilder1.Commit()


        bordersAndZonesBuilder1.Destroy()


    End Sub


    
End Module

 

 

9 REPLIES

Re: How to get Zone value of SectionLine?

Phenom
Phenom

I cannot see in your code anywhere where you are querying the zone for a section line.

Suresh
Production: NX10.0.3 Developing: NX11.0.2.7, NX12.0.1
Development: C++, C# .Net, VB .Net, KF
Highlighted

Re: How to get Zone value of SectionLine?

Valued Contributor
Valued Contributor

Hi,

 

Yes, it is not there in the code.

 

I am asking how to get the zone for section line.

Re: How to get Zone value of SectionLine?

Phenom
Phenom

It cannot be done interactively, so looks like you can only get the zone value for a view.

Suresh
Production: NX10.0.3 Developing: NX11.0.2.7, NX12.0.1
Development: C++, C# .Net, VB .Net, KF

Re: How to get Zone value of SectionLine?

Valued Contributor
Valued Contributor

Hello,

 

is there any other method to get the zone value?

Re: How to get Zone value of SectionLine?

Phenom
Phenom
I think, you can get the objects of section line, query their position in
drawing space and calculate the zone value.

Regards,
Suresh
Suresh
Production: NX10.0.3 Developing: NX11.0.2.7, NX12.0.1
Development: C++, C# .Net, VB .Net, KF

Re: How to get Zone value of SectionLine?

Valued Contributor
Valued Contributor

Thanks for the help.

 

I will try to find solution.

Re: How to get Zone value of SectionLine?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

*I think* there should be API to get the zone positions/sizes for the sheet.

Then (as Suresh said) get the positions of the geometry, figure out which "point" on the "object" should be used, and then you can determine the zone.

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP16/TC11.2
I'd rather be e-steamed than e-diseaseled


Re: How to get Zone value of SectionLine?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

FWIW: there is some code here that will calculate the sheet zone given a coordinate on the sheet.

Re: How to get Zone value of SectionLine?

Valued Contributor
Valued Contributor

Hello,

 

I got the coordinates of the section line.

Thanks to all for the support and guidance.

Below is the code I have used to get the value.

  Sub SectionLineCoOrdinates(ByVal v As Drawings.DraftingView)


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

        Dim theSectionLine As Drawings.SectionLine
        theSectionLine = Utilities.NXObjectManager.Get(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 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

        Dim returnTags As New List(Of Tag)

        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
                '   Return Nothing

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

        End Select

       

        'get the underlying curve tag from the segment
        For Each temp As Tag In segmentTags
            Dim segInfo As UFDraw.SxsegInfo
            Dim curveTag As Tag = Tag.Null
            Dim obj() As UFDrf.Object = Nothing
            theUfSession.Draw.AskSxlineSxseg(temp, segInfo, curveTag, obj)
            MsgBox(CStr(obj(0).assoc_dwg_pos(0)))
            X = obj(0).assoc_dwg_pos(0)
            Y = obj(0).assoc_dwg_pos(1)
        Next
       
    End Sub