Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Journal to change drafting entity colours

Status
Not open for further replies.

rmaddin

Mechanical
Aug 4, 2016
7
Hi,
I'm trying to write a journal that will select dimensions on an existing drawing and change their color.
I have recorded a journal that does what I would like but it won't work for other drawings as I know that I need to include a loop to select dimensions in a non-sticky way.
Once working my plan is to expand this to include other drafting entities such as centerlines, symbols etc..
Here's my code, any help greatly appreciated.

Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

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: Edit->Selection->Select All
' ----------------------------------------------
' Refer to the sample NXOpen application, Selection for "Select All" alternatives.
' ----------------------------------------------
' Menu: Edit->Object Display...
' ----------------------------------------------
' ----------------------------------------------
' Dialog Begin Color
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit Object Display")

Dim displayModification1 As NXOpen.DisplayModification = Nothing
displayModification1 = theSession.DisplayManager.NewDisplayModification()

displayModification1.ApplyToAllFaces = True

displayModification1.ApplyToOwningParts = False

displayModification1.NewColor = 103

Dim objects1(18) As NXOpen.DisplayableObject
Dim minorAngularDimension1 As NXOpen.Annotations.MinorAngularDimension = CType(workPart.FindObject("HANDLE R-9005"), NXOpen.Annotations.MinorAngularDimension)

objects1(0) = minorAngularDimension1
Dim perpendicularDimension1 As NXOpen.Annotations.PerpendicularDimension = CType(workPart.FindObject("HANDLE R-9049"), NXOpen.Annotations.PerpendicularDimension)

objects1(1) = perpendicularDimension1
Dim perpendicularDimension2 As NXOpen.Annotations.PerpendicularDimension = CType(workPart.FindObject("HANDLE R-9102"), NXOpen.Annotations.PerpendicularDimension)

objects1(2) = perpendicularDimension2
Dim perpendicularDimension3 As NXOpen.Annotations.PerpendicularDimension = CType(workPart.FindObject("HANDLE R-9133"), NXOpen.Annotations.PerpendicularDimension)

objects1(3) = perpendicularDimension3
Dim parallelDimension1 As NXOpen.Annotations.ParallelDimension = CType(workPart.FindObject("HANDLE R-9162"), NXOpen.Annotations.ParallelDimension)

objects1(4) = parallelDimension1
Dim cylindricalDimension1 As NXOpen.Annotations.CylindricalDimension = CType(workPart.FindObject("HANDLE R-9894"), NXOpen.Annotations.CylindricalDimension)

objects1(5) = cylindricalDimension1
Dim verticalDimension1 As NXOpen.Annotations.VerticalDimension = CType(workPart.FindObject("HANDLE R-9978"), NXOpen.Annotations.VerticalDimension)

objects1(6) = verticalDimension1
Dim verticalDimension2 As NXOpen.Annotations.VerticalDimension = CType(workPart.FindObject("HANDLE R-10010"), NXOpen.Annotations.VerticalDimension)

objects1(7) = verticalDimension2
Dim verticalDimension3 As NXOpen.Annotations.VerticalDimension = CType(workPart.FindObject("HANDLE R-10088"), NXOpen.Annotations.VerticalDimension)

objects1(8) = verticalDimension3
Dim verticalDimension4 As NXOpen.Annotations.VerticalDimension = CType(workPart.FindObject("HANDLE R-10116"), NXOpen.Annotations.VerticalDimension)

objects1(9) = verticalDimension4
Dim perpendicularDimension4 As NXOpen.Annotations.PerpendicularDimension = CType(workPart.FindObject("HANDLE R-10041"), NXOpen.Annotations.PerpendicularDimension)

objects1(10) = perpendicularDimension4
Dim verticalDimension5 As NXOpen.Annotations.VerticalDimension = CType(workPart.FindObject("HANDLE R-8479"), NXOpen.Annotations.VerticalDimension)

objects1(11) = verticalDimension5
Dim verticalDimension6 As NXOpen.Annotations.VerticalDimension = CType(workPart.FindObject("HANDLE R-8501"), NXOpen.Annotations.VerticalDimension)

objects1(12) = verticalDimension6
Dim perpendicularDimension5 As NXOpen.Annotations.PerpendicularDimension = CType(workPart.FindObject("HANDLE R-46410"), NXOpen.Annotations.PerpendicularDimension)

objects1(13) = perpendicularDimension5
Dim verticalDimension7 As NXOpen.Annotations.VerticalDimension = CType(workPart.FindObject("HANDLE R-60019"), NXOpen.Annotations.VerticalDimension)

objects1(14) = verticalDimension7
Dim cylindricalDimension2 As NXOpen.Annotations.CylindricalDimension = CType(workPart.FindObject("HANDLE R-55261"), NXOpen.Annotations.CylindricalDimension)

objects1(15) = cylindricalDimension2
Dim holeDimension1 As NXOpen.Annotations.HoleDimension = CType(workPart.FindObject("HANDLE R-45371"), NXOpen.Annotations.HoleDimension)

objects1(16) = holeDimension1
Dim horizontalDimension1 As NXOpen.Annotations.HorizontalDimension = CType(workPart.FindObject("HANDLE R-88071"), NXOpen.Annotations.HorizontalDimension)

objects1(17) = horizontalDimension1
Dim verticalDimension8 As NXOpen.Annotations.VerticalDimension = CType(workPart.FindObject("HANDLE R-72251"), NXOpen.Annotations.VerticalDimension)

objects1(18) = verticalDimension8
displayModification1.Apply(objects1)

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

displayModification1.Dispose()
theSession.CleanUpFacetedFacesAndEdges()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Regards,

Russell.
 
Replies continue below

Recommended for you

Each part has a .Dimensions collection that you can use to access the dimension objects. The display modification object expects an array of objects to be passed to it; you can pass in the entire collection by using the .ToArray method to convert the collection to an array.

Code:
Imports System
Imports NXOpen

Module Module123
    Sub Main(ByVal args() As String)

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

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

        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit Object Display")

        Dim displayModification1 As NXOpen.DisplayModification = Nothing
        displayModification1 = theSession.DisplayManager.NewDisplayModification()

        displayModification1.ApplyToAllFaces = True

        displayModification1.ApplyToOwningParts = False

        displayModification1.NewColor = 103

        displayModification1.Apply(workPart.Dimensions.ToArray)

        Dim nErrs1 As Integer = Nothing
        nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

        displayModification1.Dispose()
        theSession.CleanUpFacetedFacesAndEdges()

    End Sub
End Module

www.nxjournaling.com
 
Many thanks Cowski, it works a treat.
Do I follow the same logic for changing the colours of symbols and notes?
 
Yes, each part has collections for notes ({your part}.Notes), centerlines ({your part}.Annotations.Centerlines), and ID symbols ({your part}.Annotations.IdSymbols) among others.

www.nxjournaling.com
 
Is there any way to separate change color for text and different color for lines and arrows? Right now everything is changed to blue.

With best regards
Michael
 
niedzviedz said:
Is there any way to separate change color for text and different color for lines and arrows? Right now everything is changed to blue.

Yes; record a journal while making the desired changes and it will return some example code.

www.nxjournaling.com
 
Yes I recorded journal, and it uses editSettingsBuilder. I thinked if there is a way to use displaymodification method? Example:

Code:
Dim objects1(0) As NXOpen.DisplayableObject
Dim perpendicularDimension1 As NXOpen.Annotations.PerpendicularDimension = CType(workPart.FindObject("HANDLE R-1262952"), NXOpen.Annotations.PerpendicularDimension)

objects1(0) = perpendicularDimension1
Dim editSettingsBuilder1 As NXOpen.Annotations.EditSettingsBuilder
editSettingsBuilder1 = workPart.SettingsManager.CreateAnnotationEditSettingsBuilder(objects1)

editSettingsBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowLineColor = workPart.Colors.Find("Cornflower")
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.FirstExtensionLineColor = workPart.Colors.Find("Cornflower")
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.SecondExtensionLineColor = workPart.Colors.Find("Cornflower")
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.FirstArrowheadColor = workPart.Colors.Find("Cornflower")
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowheadColor = workPart.Colors.Find("Cornflower")
editSettingsBuilder1.AnnotationStyle.LineArrowStyle.SecondArrowLineColor = workPart.Colors.Find("Cornflower")
editSettingsBuilder1.AnnotationStyle.LetteringStyle.DimensionTextColor = workPart.Colors.Find("Yellow")

With best regards
Michael
 
Almost there with my journal.
Can anyone tell me what the collections are for Detail View Borders, Section Line Labels and View Direction Reference Arrows, had a good look round but cannot find them.
Also is there a way of selecting all views and updating as my section lines stay black until I do this?
Many thanks again.
 
Managed to crack the updating of all views in my drawing with this:
Code:
' Update All Views
		Try
                 theSession.Parts.Work.DraftingViews.UpdateViews(Drawings.DraftingViewCollection.ViewUpdateOption.All)
		 MsgBox("Updated All Views" , vbinformation + vbokonly, "Success")
		 Catch ex As exception
                        MsgBox("No Views updated" , vbinformation + vbokonly, "Error")
                        Exit Sub
 		End Try
Still stumped by what the collections are for Detail View Borders, Section Line Labels and View Direction Reference Arrows.
I've run a journal that tells me the type and subtype and looked these up against the entries in uf_object_types.h but can't quite make the link to what I need to put in the journal. Any clues?

 
Below is some code that I wrote a few years ago (for NX 9) that will get the detail view border given the detail view (or vice-versa). This example just writes out some info to the listing window and highlights the border arcs, but it returns the borders as arc objects which you could then pass to a display modification object if you want. All the code below the line of asterisks is the class code that does the heavy lifting; all the code above is a simple journal that shows how to make use of the class.

I have similar code for section views/section view lines. I've not had to deal with view direction arrows, but they would probably be similar.

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

Module test1

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


    Sub Main()

        lw.Open()

        'find border arc given a detail view
        For Each tempView As Drawings.DraftingView In theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet.SheetDraftingViews
            If TypeOf (tempView) Is Drawings.DetailView Then
                Dim myViewInfo As New DetailViewInfo(tempView)
                lw.WriteLine("detail view name: " & tempView.Name)
                lw.WriteLine("parent view name: " & myViewInfo.ParentView.Name)
                lw.WriteLine("border arc: " & myViewInfo.BorderArc.Tag.ToString)
                lw.WriteLine("  center point: " & myViewInfo.BorderArc.CenterPoint.ToString)
                myViewInfo.BorderArc.Highlight()

            End If
        Next



        'find detail view given a border arc
        'For Each tempArc As Arc In theSession.Parts.Work.Arcs
        '    lw.WriteLine("tempArc.Center: " & tempArc.CenterPoint.ToString)
        '    Dim myviewinfo As New DetailViewInfo(tempArc)
        '    If IsNothing(myviewinfo.BorderArc) Then
        '        lw.WriteLine("tempArc.Tag: " & tempArc.Tag.ToString)
        '        lw.WriteLine("given arc is not a detail view border")
        '    Else
        '
        '        tempArc.Highlight()
        '        lw.WriteLine("detail view: " & myviewinfo.DetailViewName)
        '        lw.WriteLine("border arc tag: " & myviewinfo.BorderArc.Tag.ToString)
        '        lw.WriteLine("tempArc.Tag: " & tempArc.Tag.ToString)
        '    End If
        'Next

        lw.Close()

    End Sub


End Module


'***************************************************************************************************************

Public Class DetailViewInfo

#Region "Private variables"
    Private _theSession As Session = Session.GetSession
    Private _theUfSession As UFSession = UFSession.GetUFSession()
    Private lg As LogFile = _theSession.LogFile

    'Private lw As ListingWindow = _theSession.ListingWindow
#End Region

    Private _detailViewName As String = ""
    Public ReadOnly Property DetailViewName() As String
        Get
            Return _detailViewName
        End Get
    End Property

    Private _parentView As Drawings.DraftingView
    Public ReadOnly Property ParentView() As Drawings.DraftingView
        Get
            Return _parentView
        End Get
    End Property

    Private _centerPt As Point3d = Nothing
    Public ReadOnly Property CenterPoint() As Point3d
        Get
            Return _centerPt
        End Get
    End Property

    Private _boundPt1 As Point3d = Nothing
    Public ReadOnly Property BoundingPoint1() As Point3d
        Get
            Return _boundPt1
        End Get
    End Property

    Private _boundPt2 As Point3d = Nothing
    Public ReadOnly Property BoundingPoint2() As Point3d
        Get
            Return _boundPt2
        End Get
    End Property

    Private _borderArc As Arc = Nothing
    Public ReadOnly Property BorderArc() As Arc
        Get
            Return _borderArc
        End Get
    End Property

    Public Sub New(ByVal theDetailView As Drawings.DetailView)
        lg.WriteLine("Sub New, given detail view")

        _detailViewName = theDetailView.Name
        'given the view, return the border arc
        Me.GetViewBounds(theDetailView)

        'The border arc (of a circular detail view) will be an arc where one of the smart object parents
        'will be the parent view of the detail view and the arc center will match _centerPt (within modeling tolerance).
        _borderArc = Me.FindBorderArc()

    End Sub

    Public Sub New(ByVal theBorderArc As Arc)
        _borderArc = theBorderArc

        'given the border arc, return the detail view
        Dim theDetailView As Drawings.DetailView = Me.FindDetailView(_borderArc)
        If IsNothing(theDetailView) Then
            _detailViewName = ""
        Else
            _detailViewName = theDetailView.Name

        End If

    End Sub

    Private Sub GetViewBounds(ByVal theDetailView As Drawings.DetailView)
        lg.WriteLine("GetViewBounds")

        Dim detailViewBuilder1 As Drawings.DetailViewBuilder = _theSession.Parts.Work.DraftingViews.CreateDetailViewBuilder(theDetailView)
        'lw.WriteLine("label on parent: " & detailViewBuilder1.LabelOnParent.ToString)
        lg.WriteLine("parent view: " & detailViewBuilder1.Parent.View.Value.Name)
        lg.WriteLine("boundary point 1: " & detailViewBuilder1.BoundaryPoint1.Coordinates.ToString)
        'lw.WriteLine("boundary point 2: " & detailViewBuilder1.BoundaryPoint2.Coordinates.ToString)
        _boundPt1 = detailViewBuilder1.BoundaryPoint1.Coordinates
        _boundPt2 = detailViewBuilder1.BoundaryPoint2.Coordinates

        If detailViewBuilder1.Type = Drawings.DetailViewBuilder.Types.Circular Then
            _centerPt = detailViewBuilder1.BoundaryPoint1.Coordinates
        End If

        _parentView = detailViewBuilder1.Parent.View.Value

        detailViewBuilder1.Destroy()

        lg.WriteLine("Exiting GetViewBounds")
        lg.WriteLine("")
    End Sub

    Private Function FindBorderArc() As Arc
        lg.WriteLine("FindBorderArc")

        'TO DO: make sure arc is not view dependent
        '  the "view boundary" arc around the actual detail view is view dependent in the detail view,
        '  this is NOT the border arc we are looking for (the arc on the parent view that represents what the detail view shows).

        For Each tempArc As Arc In _theSession.Parts.Work.Arcs
            Dim arcParents As New List(Of NXObject)
            GetSmartParents(tempArc, arcParents)
            For Each tempParent As NXObject In arcParents
                If TypeOf (tempParent) Is Drawings.DraftingView Then

                    lg.WriteLine("FindBorderArc: tempParent.Name: " & tempParent.Name)
                    lg.WriteLine("FindBorderArc: _parentView.Name: " & _parentView.Name)
                    lg.WriteLine("FindBorderArc: tempParent.Tag: " & tempParent.Tag.ToString)
                    lg.WriteLine("FindBorderArc: _parentView.Tag: " & _parentView.Tag.ToString)

                    If tempParent.Name <> _parentView.Name Then
                        lg.WriteLine("tempParent.Name <> _parentView.Name")
                        'this is not the arc we are looking for
                        'move along...
                        Continue For
                    End If

                    'if we get here, the view names match
                    'so far, so good
                    lg.WriteLine("view names match, checking points")
                    If Point3dEqual(tempArc.CenterPoint, _centerPt) Then
                        lg.WriteLine("points match, returning tempArc")
                        'parent views match and center points match
                        'this is it
                        '_borderArc = tempArc
                        Return tempArc
                    Else
                        lg.WriteLine("points do not match, check next parent")
                    End If

                End If
            Next
            'lw.WriteLine("")
        Next

        'no more arcs, no matches found
        lg.WriteLine("border arc = nothing")
        '_borderArc = Nothing
        Return Nothing

        lg.WriteLine("Exiting FindBorderArc")
        lg.WriteLine("")
    End Function

    Private Sub GetSmartParents(ByRef theSmartObject As NXObject, ByRef theParentList As List(Of NXObject))

        Dim numParents As Integer
        Dim theParentTags() As Tag = Nothing
        Dim isSmart As Boolean = False

        Try
            _theUfSession.So.IsSo(theSmartObject.Tag, isSmart)
            If isSmart Then
                _theUfSession.So.AskParents(theSmartObject.Tag, UFConstants.UF_SO_ASK_ALL_PARENTS, numParents, theParentTags)

                For Each tempTag As Tag In theParentTags
                    Dim objParent As NXObject = Utilities.NXObjectManager.Get(tempTag)
                    'lw.WriteLine("adding " & objParent.GetType.ToString & " to parent list")
                    theParentList.Add(objParent)

                    GetSmartParents(objParent, theParentList)

                Next

            End If

        Catch ex As NXException
            'lw.WriteLine("error: " & ex.ErrorCode)
            'lw.WriteLine("  " & ex.Message)
        End Try

    End Sub

    Private Function Point3dEqual(ByVal pt1 As Point3d, ByVal pt2 As Point3d) As Boolean

        If IsNothing(pt1) OrElse IsNothing(pt2) Then
            Return False
        End If

        Dim modelingTolerance As Double
        _theUfSession.Modl.AskDistanceTolerance(modelingTolerance)

        lg.WriteLine("modeling distance tolerance: " & modelingTolerance.ToString)

        If Math.Abs(pt1.X - pt2.X) > modelingTolerance Then
            lg.WriteLine("X distance exceeds modeling tolerance")
            Return False
        End If

        If Math.Abs(pt1.Y - pt2.Y) > modelingTolerance Then
            lg.WriteLine("Y distance exceeds modeling tolerance")
            Return False
        End If

        If Math.Abs(pt1.Z - pt2.Z) > modelingTolerance Then
            lg.WriteLine("Z distance exceeds modeling tolerance")
            Return False
        End If

        lg.WriteLine("points equal withing modeling distance tolerance")
        Return True

    End Function

    Private Function FindDetailView(ByVal theBorderArc As Arc) As Drawings.DetailView

        For Each tempView As Drawings.DraftingView In _theSession.Parts.Work.DraftingViews
            If Not TypeOf (tempView) Is Drawings.DetailView Then
                'only process detail views
                Continue For
            End If

            Me.GetViewBounds(tempView)
            Dim tempBorderArc As Arc
            tempBorderArc = Me.FindBorderArc
            If IsNothing(tempBorderArc) Then
                Continue For
            End If

            If theBorderArc.Equals(tempBorderArc) Then
                Return tempView
            End If

        Next

        Return Nothing

    End Function

End Class

www.nxjournaling.com
 
Have adapted the code above to change the detail view borders. Many thanks again Cowski!
Could you share how the similar journal worked with section line labels.
I'm just stuck on combining this with my main journal that changes the other drafting objects.
I had a go at making sure there were no similar objects but am still getting errors.
I've posted both separately below. Any help greatly appreciated.

Code:
Imports System
Imports NXOpen

Module Module123
    Sub Main(ByVal args() As String)

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

        Dim displayPart As NXOpen.Part = theSession.Parts.Display
		
		Dim sheet As Drawings.DrawingSheet

        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit Object Display")

		' Change Dimension Colour 1

        Dim displayModification1 As NXOpen.DisplayModification = Nothing
        displayModification1 = theSession.DisplayManager.NewDisplayModification()

        displayModification1.ApplyToAllFaces = True

        displayModification1.ApplyToOwningParts = False

        displayModification1.NewColor = 103

        displayModification1.Apply(workPart.Dimensions.ToArray)

        Dim nErrs1 As Integer = Nothing
        nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

        displayModification1.Dispose()
        theSession.CleanUpFacetedFacesAndEdges()
		
		'Change Note Colour 2

 		'Dim displayModification2 As NXOpen.DisplayModification = Nothing
        'displayModification2 = theSession.DisplayManager.NewDisplayModification()

        'displayModification2.ApplyToAllFaces = True

        'displayModification2.ApplyToOwningParts = False

        'displayModification2.NewColor = 103

        'displayModification2.Apply(workpart.Notes.ToArray)

        'Dim nErrs2 As Integer = Nothing
        'nErrs2 = theSession.UpdateManager.DoUpdate(markId1)

        'displayModification2.Dispose()
        'theSession.CleanUpFacetedFacesAndEdges()

		' Change Centreline Colour 3

		Dim displayModification3 As NXOpen.DisplayModification = Nothing
        displayModification3 = theSession.DisplayManager.NewDisplayModification()

        displayModification3.ApplyToAllFaces = True

        displayModification3.ApplyToOwningParts = False

        displayModification3.NewColor = 108

        displayModification3.Apply(workpart.Annotations.Centerlines.ToArray)

        Dim nErrs3 As Integer = Nothing
        nErrs3 = theSession.UpdateManager.DoUpdate(markId1)

        displayModification3.Dispose()
        theSession.CleanUpFacetedFacesAndEdges()

		' Change Symbol Colour 4
		
		Dim displayModification4 As NXOpen.DisplayModification = Nothing
        displayModification4 = theSession.DisplayManager.NewDisplayModification()

        displayModification4.ApplyToAllFaces = True

        displayModification4.ApplyToOwningParts = False

        displayModification4.NewColor = 108

        displayModification4.Apply(workpart.Annotations.IdSymbols.ToArray)

        Dim nErrs4 As Integer = Nothing
        nErrs4 = theSession.UpdateManager.DoUpdate(markId1)

        displayModification4.Dispose()
        theSession.CleanUpFacetedFacesAndEdges()	
	
		' Change Section Lines Colour 5
	
		Dim displayModification5 As NXOpen.DisplayModification = Nothing
        displayModification5 = theSession.DisplayManager.NewDisplayModification()

        displayModification5.ApplyToAllFaces = True

        displayModification5.ApplyToOwningParts = False

        displayModification5.NewColor = 108

        displayModification5.Apply(workpart.Drafting.Sectionlines.ToArray)

        Dim nErrs5 As Integer = Nothing
        nErrs5 = theSession.UpdateManager.DoUpdate(markId1)

        displayModification5.Dispose()
        theSession.CleanUpFacetedFacesAndEdges()	
		
		' Change Surface Finish Symbol Colour 6		
		
		Dim displayModification6 As NXOpen.DisplayModification = Nothing
        displayModification6 = theSession.DisplayManager.NewDisplayModification()

        displayModification6.ApplyToAllFaces = True

        displayModification6.ApplyToOwningParts = False

        displayModification6.NewColor = 103

        displayModification6.Apply(workpart.Annotations.DraftingSurfaceFinishSymbols.ToArray)

        Dim nErrs6 As Integer = Nothing
        nErrs6 = theSession.UpdateManager.DoUpdate(markId1)

        displayModification6.Dispose()
        theSession.CleanUpFacetedFacesAndEdges()	
		
		' Change Label Colour 7
		
		Dim displayModification7 As NXOpen.DisplayModification = Nothing
        displayModification7 = theSession.DisplayManager.NewDisplayModification()

        displayModification7.ApplyToAllFaces = True

        displayModification7.ApplyToOwningParts = False

        displayModification7.NewColor = 103

        displayModification7.Apply(workpart.Labels.ToArray)

        Dim nErrs7 As Integer = Nothing
        nErrs7 = theSession.UpdateManager.DoUpdate(markId1)

        displayModification7.Dispose()
        theSession.CleanUpFacetedFacesAndEdges()	
		
		' Change GDT Colour 8
		
		Dim displayModification8 As NXOpen.DisplayModification = Nothing
        displayModification8 = theSession.DisplayManager.NewDisplayModification()

        displayModification8.ApplyToAllFaces = True

        displayModification8.ApplyToOwningParts = False

        displayModification8.NewColor = 103

        displayModification8.Apply(workpart.GDTs.ToArray)

        Dim nErrs8 As Integer = Nothing
        nErrs8 = theSession.UpdateManager.DoUpdate(markId1)

        displayModification8.Dispose()
        theSession.CleanUpFacetedFacesAndEdges()
		
		' Change Projected View Arrows Colour 9
		
		'Dim displayModification9 As NXOpen.DisplayModification = Nothing
        'displayModification9 = theSession.DisplayManager.NewDisplayModification()

        'displayModification9.ApplyToAllFaces = True

       ' displayModification9.ApplyToOwningParts = False

        'displayModification9.NewColor = 108

        'displayModification9.Apply(workpart.ViewingDirectionArrow.ToArray)

        'Dim nErrs9 As Integer = Nothing
        'nErrs9 = theSession.UpdateManager.DoUpdate(markId1)

        'displayModification9.Dispose()
        'theSession.CleanUpFacetedFacesAndEdges()
		
		' Update All Views
		Try
         theSession.Parts.Work.DraftingViews.UpdateViews(Drawings.DraftingViewCollection.ViewUpdateOption.All)
		 MsgBox("Updated All Views" , vbinformation + vbokonly, "Success")
		 Catch ex As exception
                        MsgBox("No Views updated" , vbinformation + vbokonly, "Error")
                        Exit Sub
 		End Try
		
    End Sub
End Module

2nd journal

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

Module test1

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


    Sub Main()

        lw.Open()

        'find border arc given a detail view
        For Each tempView As Drawings.DraftingView In theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet.SheetDraftingViews
            If TypeOf (tempView) Is Drawings.DetailView Then
                Dim myViewInfo As New DetailViewInfo(tempView)
                'lw.WriteLine("detail view name: " & tempView.Name)
                'lw.WriteLine("parent view name: " & myViewInfo.ParentView.Name)
                'lw.WriteLine("border arc: " & myViewInfo.BorderArc.Tag.ToString)
               	'lw.WriteLine("  center point: " & myViewInfo.BorderArc.CenterPoint.ToString)
                'myViewInfo.BorderArc.Highlight()
				
				'Code to change the colour of the detail borders
				
				Dim workPart As NXOpen.Part = theSession.Parts.Work

				Dim objects1(0) As DisplayableObject
				
				Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        			markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit Object Display")
				
				Dim displayModification1 As NXOpen.DisplayModification = Nothing
        			displayModification1 = theSession.DisplayManager.NewDisplayModification()

       			displayModification1.ApplyToAllFaces = True

        			displayModification1.ApplyToOwningParts = False

        			displayModification1.NewColor = 108
			
				objects1(0) = myViewInfo.BorderArc

        			displayModification1.Apply(objects1)

        			Dim nErrs1 As Integer = Nothing
        			nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

        			displayModification1.Dispose()
        			theSession.CleanUpFacetedFacesAndEdges()

            End If
        Next



        'find detail view given a border arc
        'For Each tempArc As Arc In theSession.Parts.Work.Arcs
        '    lw.WriteLine("tempArc.Center: " & tempArc.CenterPoint.ToString)
        '    Dim myviewinfo As New DetailViewInfo(tempArc)
        '    If IsNothing(myviewinfo.BorderArc) Then
        '        lw.WriteLine("tempArc.Tag: " & tempArc.Tag.ToString)
        '        lw.WriteLine("given arc is not a detail view border")
        '    Else
        '
        '        tempArc.Highlight()
        '        lw.WriteLine("detail view: " & myviewinfo.DetailViewName)
        '        lw.WriteLine("border arc tag: " & myviewinfo.BorderArc.Tag.ToString)
        '        lw.WriteLine("tempArc.Tag: " & tempArc.Tag.ToString)
        '    End If
        'Next

        lw.Close()

    End Sub


End Module


'***************************************************************************************************************

Public Class DetailViewInfo

#Region "Private variables"
    Private _theSession As Session = Session.GetSession
    Private _theUfSession As UFSession = UFSession.GetUFSession()
    Private lg As LogFile = _theSession.LogFile

    'Private lw As ListingWindow = _theSession.ListingWindow
#End Region

    Private _detailViewName As String = ""
    Public ReadOnly Property DetailViewName() As String
        Get
            Return _detailViewName
        End Get
    End Property

    Private _parentView As Drawings.DraftingView
    Public ReadOnly Property ParentView() As Drawings.DraftingView
        Get
            Return _parentView
        End Get
    End Property

    Private _centerPt As Point3d = Nothing
    Public ReadOnly Property CenterPoint() As Point3d
        Get
            Return _centerPt
        End Get
    End Property

    Private _boundPt1 As Point3d = Nothing
    Public ReadOnly Property BoundingPoint1() As Point3d
        Get
            Return _boundPt1
        End Get
    End Property

    Private _boundPt2 As Point3d = Nothing
    Public ReadOnly Property BoundingPoint2() As Point3d
        Get
            Return _boundPt2
        End Get
    End Property

    Private _borderArc As Arc = Nothing
    Public ReadOnly Property BorderArc() As Arc
        Get
            Return _borderArc
        End Get
    End Property

    Public Sub New(ByVal theDetailView As Drawings.DetailView)
        lg.WriteLine("Sub New, given detail view")

        _detailViewName = theDetailView.Name
        'given the view, return the border arc
        Me.GetViewBounds(theDetailView)

        'The border arc (of a circular detail view) will be an arc where one of the smart object parents
        'will be the parent view of the detail view and the arc center will match _centerPt (within modeling tolerance).
        _borderArc = Me.FindBorderArc()

    End Sub

    Public Sub New(ByVal theBorderArc As Arc)
        _borderArc = theBorderArc

        'given the border arc, return the detail view
        Dim theDetailView As Drawings.DetailView = Me.FindDetailView(_borderArc)
        If IsNothing(theDetailView) Then
            _detailViewName = ""
        Else
            _detailViewName = theDetailView.Name

        End If

    End Sub

    Private Sub GetViewBounds(ByVal theDetailView As Drawings.DetailView)
        lg.WriteLine("GetViewBounds")

        Dim detailViewBuilder1 As Drawings.DetailViewBuilder = _theSession.Parts.Work.DraftingViews.CreateDetailViewBuilder(theDetailView)
        'lw.WriteLine("label on parent: " & detailViewBuilder1.LabelOnParent.ToString)
        lg.WriteLine("parent view: " & detailViewBuilder1.Parent.View.Value.Name)
        lg.WriteLine("boundary point 1: " & detailViewBuilder1.BoundaryPoint1.Coordinates.ToString)
        'lw.WriteLine("boundary point 2: " & detailViewBuilder1.BoundaryPoint2.Coordinates.ToString)
        _boundPt1 = detailViewBuilder1.BoundaryPoint1.Coordinates
        _boundPt2 = detailViewBuilder1.BoundaryPoint2.Coordinates

        If detailViewBuilder1.Type = Drawings.DetailViewBuilder.Types.Circular Then
            _centerPt = detailViewBuilder1.BoundaryPoint1.Coordinates
        End If

        _parentView = detailViewBuilder1.Parent.View.Value

        detailViewBuilder1.Destroy()

        lg.WriteLine("Exiting GetViewBounds")
        lg.WriteLine("")
    End Sub

    Private Function FindBorderArc() As Arc
        lg.WriteLine("FindBorderArc")

        'TO DO: make sure arc is not view dependent
        '  the "view boundary" arc around the actual detail view is view dependent in the detail view,
        '  this is NOT the border arc we are looking for (the arc on the parent view that represents what the detail view shows).

        For Each tempArc As Arc In _theSession.Parts.Work.Arcs
            Dim arcParents As New List(Of NXObject)
            GetSmartParents(tempArc, arcParents)
            For Each tempParent As NXObject In arcParents
                If TypeOf (tempParent) Is Drawings.DraftingView Then

                    lg.WriteLine("FindBorderArc: tempParent.Name: " & tempParent.Name)
                    lg.WriteLine("FindBorderArc: _parentView.Name: " & _parentView.Name)
                    lg.WriteLine("FindBorderArc: tempParent.Tag: " & tempParent.Tag.ToString)
                    lg.WriteLine("FindBorderArc: _parentView.Tag: " & _parentView.Tag.ToString)

                    If tempParent.Name <> _parentView.Name Then
                        lg.WriteLine("tempParent.Name <> _parentView.Name")
                        'this is not the arc we are looking for
                        'move along...
                        Continue For
                    End If

                    'if we get here, the view names match
                    'so far, so good
                    lg.WriteLine("view names match, checking points")
                    If Point3dEqual(tempArc.CenterPoint, _centerPt) Then
                        lg.WriteLine("points match, returning tempArc")
                        'parent views match and center points match
                        'this is it
                        '_borderArc = tempArc
                        Return tempArc
                    Else
                        lg.WriteLine("points do not match, check next parent")
                    End If

                End If
            Next
            'lw.WriteLine("")
        Next

        'no more arcs, no matches found
        lg.WriteLine("border arc = nothing")
        '_borderArc = Nothing
        Return Nothing

        lg.WriteLine("Exiting FindBorderArc")
        lg.WriteLine("")
    End Function

    Private Sub GetSmartParents(ByRef theSmartObject As NXObject, ByRef theParentList As List(Of NXObject))

        Dim numParents As Integer
        Dim theParentTags() As Tag = Nothing
        Dim isSmart As Boolean = False

        Try
            _theUfSession.So.IsSo(theSmartObject.Tag, isSmart)
            If isSmart Then
                _theUfSession.So.AskParents(theSmartObject.Tag, UFConstants.UF_SO_ASK_ALL_PARENTS, numParents, theParentTags)

                For Each tempTag As Tag In theParentTags
                    Dim objParent As NXObject = Utilities.NXObjectManager.Get(tempTag)
                    'lw.WriteLine("adding " & objParent.GetType.ToString & " to parent list")
                    theParentList.Add(objParent)

                    GetSmartParents(objParent, theParentList)

                Next

            End If

        Catch ex As NXException
            'lw.WriteLine("error: " & ex.ErrorCode)
            'lw.WriteLine("  " & ex.Message)
        End Try

    End Sub

    Private Function Point3dEqual(ByVal pt1 As Point3d, ByVal pt2 As Point3d) As Boolean

        If IsNothing(pt1) OrElse IsNothing(pt2) Then
            Return False
        End If

        Dim modelingTolerance As Double
        _theUfSession.Modl.AskDistanceTolerance(modelingTolerance)

        lg.WriteLine("modeling distance tolerance: " & modelingTolerance.ToString)

        If Math.Abs(pt1.X - pt2.X) > modelingTolerance Then
            lg.WriteLine("X distance exceeds modeling tolerance")
            Return False
        End If

        If Math.Abs(pt1.Y - pt2.Y) > modelingTolerance Then
            lg.WriteLine("Y distance exceeds modeling tolerance")
            Return False
        End If

        If Math.Abs(pt1.Z - pt2.Z) > modelingTolerance Then
            lg.WriteLine("Z distance exceeds modeling tolerance")
            Return False
        End If

        lg.WriteLine("points equal withing modeling distance tolerance")
        Return True

    End Function

    Private Function FindDetailView(ByVal theBorderArc As Arc) As Drawings.DetailView

        For Each tempView As Drawings.DraftingView In _theSession.Parts.Work.DraftingViews
            If Not TypeOf (tempView) Is Drawings.DetailView Then
                'only process detail views
                Continue For
            End If

            Me.GetViewBounds(tempView)
            Dim tempBorderArc As Arc
            tempBorderArc = Me.FindBorderArc
            If IsNothing(tempBorderArc) Then
                Continue For
            End If

            If theBorderArc.Equals(tempBorderArc) Then
                Return tempView
            End If

        Next

        Return Nothing

    End Function

End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor