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!

Measure Intersection Curve 1

Status
Not open for further replies.

Twullf

Mechanical
Jan 24, 2012
196
I need to convert my intersection curve to a displayable object, so far everything I have tried has failed.

The error says "System.NullReferenceException: Object reference not set to an instance of an object.
at ModelChecking.MeasureLineLength(IntersectionCurve moldInterLine, String strMoldLength, Boolean boolLength, Unit_unitMM) in" ... "line 676"

Code:
   Sub MeasureLineLength( ByRef moldInterLine As Features.IntersectionCurve, ByRef strMoldLength As String, _
      ByRef boolLength As Boolean, ByRef unitMM As Unit )

      Dim measureDistanceBuilder1     As MeasureDistanceBuilder
      Dim measureLength1              As MeasureLength
      Dim curves(-1)                  As NXObject
      Dim nullNXObject                As NXObject

      nullNXObject = Nothing

       measureDistanceBuilder1 = workPart.MeasureManager.CreateMeasureDistanceBuilder(nullNXObject)

      curves = moldInterLine.GetEntities()

      'Try

         measureLength1 = workPart.MeasureManager.NewLength( unitMM, curves )

         strMoldLength = measureLength1.value.ToString

         msgbox("Mold length = " & strMoldLength )

      'Catch

         'strMoldLength = "Failed To Measure"

      'End Try
   End Sub

Line 676 is the line curves = moldInterLine.GetEntities()

Any help is greatly appreciated.
 
Replies continue below

Recommended for you

Try this:

Code:
[COLOR=blue]Dim[/color] featureObjects() [COLOR=blue]As[/color] NXObject  
featureObjects [COLOR=blue]=[/color] myIntersectionCurve.GetEntities  
[COLOR=blue]Dim[/color] featureCurves [COLOR=blue]As New[/color] List(Of Curve)  
[COLOR=blue]For Each[/color] crv [COLOR=blue]As[/color] Curve [COLOR=blue]In[/color] featureObjects  
    featureCurves.Add(crv)  
[COLOR=blue]Next[/color]  

[COLOR=blue]Dim[/color] totalLength [COLOR=blue]As Double =[/color] 0  
[COLOR=blue]For Each[/color] crv [COLOR=blue]As[/color] Curve [COLOR=blue]In[/color] featureCurves  
    totalLength [COLOR=blue]+=[/color] crv.GetLength  
[COLOR=blue]Next[/color]  

MsgBox("total length [COLOR=blue]of[/color] intersection curve: " [COLOR=blue]&[/color] totalLength)

To use the list, you'll need to add the line:
Imports System.Collections.Generic
to the "imports" section

Length will be returned in the "analysis units" of the part.

www.nxjournaling.com
 
I added that import though I already had:
Imports System.Collections

The problem is it is failing at the second line of your code, or that is where my error is directing me:
<code>
featureObjects = myIntersectionCurve.GetEntities
<code>

I had the same line in my code, I don't know why it won't work.

Error reads:

System.NullReferenceException: Object reference not set to an instance of an object.
at ModelChecking.MeasureLineLength(intersectionCurve moldInterLine, String, strmoldInterLine, String strMoldLength, Boolean, boolLength, Unit_unitMM) ... line 678
 
In that case it is most likely a problem with moldInterLine; either it is null or doesn't hold what you think it holds. I'd add some code in this routine to investigate if moldInterLine IsNull or IsEmpty. If it is null or empty, you'll have to dig a bit deeper to find out why. If it isn't, then you'll need to find out what that variable does contain.

www.nxjournaling.com
 
In the sub where the intersection line is created, after it is committed then you get the following line before destroying the builder.

Code:
     Try
         feature1 = intersectionCurveBuilder1.commitFeature()
         moldinterLine = CType( feature1, Features.IntersectionCurve )
      Catch
         boolIntersection = false
         intersectionCurveBuilder1.Destroy()
         Exit Sub
      End Try
      intersectionCurveBuilder1.Destroy()

From a glance is this "transforming" the builder to curve, correctly?
 
How is moldinterLine declared?

I'd try:
Code:
 dim moldInterLine as Features.IntersectionCurve
...
...
...
moldInterLine = intersectionCurveBuilder1.commitFeature()

www.nxjournaling.com
 
Alright right after setting:

moldInterLine = intersectionCurveBuilder1.commitFeature()

I did an if statement as follows

If moldInterLine is Nothing then
msgbox("interLine = Nothing")
End If

and it activated.

I am attempting to place an intersection curve on a component of an assembly, the intersection curve does appear but it is unassociated, that is fine I can make it work, but would this effect the ability of the variable to be passed and used later in the program?
 
As a test, I opened a small assembly and recorded a journal while creating an intersect curve feature. I selected the face of a component for the first set and a datum plane owned by the assembly file itself for the second set. The journal showed that 2 extract face features and a wave link were created but they did not show up in the feature tree, only the intersection curve. It appears that the .CommitCreateOnTheFly method creates some "behind the scenes" features.

To investigate further, I ran this code on the assembly file (where the intersect curve feature was created):
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features

Module NXJournal
Sub Main


Dim s As Session = Session.GetSession()
Dim ui As UI = UI.GetUI()
Dim lw As ListingWindow = s.ListingWindow
lw.Open()

Dim featArray() As Feature = s.Parts.Work.Features.GetFeatures()
Dim featEntities() as NXObject

lw.WriteLine("*** All Features ***")
For each myFeature as Feature in featArray
    lw.WriteLine(myFeature.GetFeatureName)
	lw.WriteLine(myFeature.FeatureType)
	lw.writeline("")

Next
lw.Close

End Sub
End Module

This is a simple journal that simply lists all the features in the work part to the information window. I found there was a linked face feature with the same feature number as the intersect curve feature, but it does not appear in the part history.

Perhaps too much code was cut from the journal you originally created to help make your intersect curve feature subroutine?

www.nxjournaling.com
 
Very very possible.

I have actually called the GTAC helpline and gotten them to see if they can help me, in the mean time I'll check the original journal and see if I can start from scratch

Thanks for all your help.
 
For future programmers, there is no such thing as an unassociative feature. once the feature is unassociated it looses the information which would make it a feature.

For getting something like an intersection curve from a component of an assembly you must wave link the feature you are working off of.

So I'm off to learn how to wave link.

Thanks for all the help cowski!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor