×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Null tag not allowed: Changing the color of composite curves within the same journal file using VB

Null tag not allowed: Changing the color of composite curves within the same journal file using VB

Null tag not allowed: Changing the color of composite curves within the same journal file using VB

(OP)
I am writing a journal file which is designed to extract a composite curve from a selected edge (or group of edges), assign it some attributes, and also give it a bright color so the user knows they've already done the process on that edge, after the process. Everythiing runs flawlessly, with the exception of the color change.

The error I'm getting is this: "NXOpen.NXException: Null tag not allowed"

at NXOpen.DisplayModification.Apply(DisplayableObject[] objects)
at [tool name].ColorChange(CompositeCurve_curve3) in [file location]:line 625
at [tool name].apply_cb() in [file location]:line 277

Line 277 is where the function is called. Line 625 is where my issue is. Here's mycode:

.
.
.
ColorChange(compCurve)
.
.
.
Public Function ColorChange(ByRef curve3 As Features.CompositeCurve) ', ByRef WeldName As String)

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

Dim curves1() As Curve
curves1 = GetCurvesOfCompositeCurve(curve3) 'this extracts all the curve ibjects from the composite curve feature as an array of curves
Dim dispObjs(curves1.Length - 1) As DisplayableObject

For i As Integer = 0 To curves1.Length - 1
dispObjs(i) = CType(curves1(i), DisplayableObject)
Next

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

displayModification1.NewColor = 3

displayModification1.Apply(dispObjs) 'this is line 625

displayModification1.Dispose()

End Function

I'd really appreciate any advice anyone can offer, I have almost no experience with programming and this specific function has given me lots of grief.
Please let me know if any more information.

Thank you,
Peter

RE: Null tag not allowed: Changing the color of composite curves within the same journal file using VB

(OP)
I am using NX 7.5, if that helps.

RE: Null tag not allowed: Changing the color of composite curves within the same journal file using VB

Below is an easier, slightly less efficient alternative, it involves changing the color property of each curve individually.

CODE

Option Strict Off  
Imports System  
Imports NXOpen  
Imports NXOpen.Features  

Module Module1  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim theUI As UI = UI.GetUI()  
        Dim selectedFeatures As Feature()  
        Dim compositestring As String = "Select composite curves"  
        Dim curves() As NXObject  
        Dim curveEntity As Curve  
 'Dim curveType As String
        Dim totalLength As Double  

        selectedFeatures = selectFeatures(compositestring)  

        For Each compositecurve1 As Features.CompositeCurve In selectedFeatures  
            curves = compositecurve1.GetEntities  
            For i As Integer = 0 To curves.Length - 1  
 'curveType = curves(i).GetType().ToString()
                curveEntity = curves(i)  
                curveEntity.Color = 3  
                curveEntity.RedisplayObject()  
 'msgbox(curveType)
                totalLength = totalLength + curveEntity.GetLength()  
            Next  
        Next  
        MsgBox("Total Length: " & totalLength)  

    End Sub  

 '**********
    Function selectFeatures(ByVal prompt As String) As Features.Feature()  
        Dim theUI As UI = UI.GetUI  
        selectFeatures = Nothing  
        theUI.SelectionManager.SelectFeatures(prompt, Selection.SelectionFeatureType.Browsable, selectFeatures)  
    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 

www.nxjournaling.com

RE: Null tag not allowed: Changing the color of composite curves within the same journal file using VB

(OP)
Cowski,

Thanks you very much for responding...can't tell you how annoying it was to have an automation journal work great in almost every regard but look ugly simply because I couldn't change some colors. Fortunately I did figure this out using precisely that solution a week or two ago. Here's the code I settled on:

CODE -->

Public Function ColorChange(ByRef curve3 As Features.CompositeCurve) 'changes the color of a comp-curve

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

        Dim curves1() As Curve
        curves1 = GetCurvesOfCompositeCurve(curve3) 'gets curve objects from the composite curve feature

        Dim dispObjs(curves1.Length - 1) As DisplayableObject

        Dim displayModification1 As DisplayModification
        displayModification1 = theSession.DisplayManager.NewDisplayModification()
        displayModification1.NewColor = 6 'sets the color of the lines to yellow
        Dim objArray(0) As DisplayableObject

        For Each cu As Curve In curves1 'for each curve,
            Try
                objArray(0) = cu 'this makes the curve a displayable object
                displayModification1.Apply(objArray) 'and this turns that object yellow
            Catch ex As Exception
            End Try
        Next
    End Function 'changes the color of a composite curve 

I was under the impression that using the ".color" method I would have to regenerate all my work to display the change, so the ".redisplayobject()" is a good solution and great to know about.

Thanks again,
Peter

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources