Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

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

Status
Not open for further replies.

PeterOliver

Mechanical
Aug 10, 2012
4
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
 
Replies continue below

Recommended for you

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

Code:
[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpen.Features  

[COLOR=blue]Module[/color] Module1  

    [COLOR=blue]Sub[/color] Main()  

        [COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
        [COLOR=blue]Dim[/color] theUI [COLOR=blue]As[/color] UI [COLOR=blue]=[/color] UI.GetUI()  
        [COLOR=blue]Dim[/color] selectedFeatures [COLOR=blue]As[/color] Feature()  
        [COLOR=blue]Dim[/color] compositestring [COLOR=blue]As[/color] [COLOR=blue]String[/color] [COLOR=blue]=[/color] "Select composite curves"  
        [COLOR=blue]Dim[/color] curves() [COLOR=blue]As[/color] NXObject  
        [COLOR=blue]Dim[/color] curveEntity [COLOR=blue]As[/color] Curve  
 [COLOR=green]'Dim curveType As String[/color]
        [COLOR=blue]Dim[/color] totalLength [COLOR=blue]As[/color] [COLOR=blue]Double[/color]  

        selectedFeatures [COLOR=blue]=[/color] selectFeatures(compositestring)  

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

    End [COLOR=blue]Sub[/color]  

 [COLOR=green]'**********[/color]
    [COLOR=blue]Function[/color] selectFeatures(ByVal prompt [COLOR=blue]As[/color] [COLOR=blue]String[/color]) [COLOR=blue]As[/color] Features.Feature()  
        [COLOR=blue]Dim[/color] theUI [COLOR=blue]As[/color] UI [COLOR=blue]=[/color] UI.GetUI  
        selectFeatures [COLOR=blue]=[/color] [COLOR=blue]Nothing[/color]  
        theUI.SelectionManager.SelectFeatures(prompt, Selection.SelectionFeatureType.Browsable, selectFeatures)  
    End [COLOR=blue]Function[/color]  
 [COLOR=green]'**********[/color]
    [COLOR=blue]Public[/color] [COLOR=blue]Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As[/color] [COLOR=blue]String[/color]) [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  
 [COLOR=green]'Unloads the image immediately after execution within NX[/color]
        GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.Immediately  
    End [COLOR=blue]Function[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor