cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a measure feature at assembly level?

Esteemed Contributor
Esteemed Contributor

Attached find a journal to create a measure feature, the problem is that it is not created with its position at the assembly level.

I get the following information for the measure feature created manually:

Feature status for: Distance Measurement(2)
Feature is alive
 
Owning part         TL2697/A;1-D15,96R2/ZW-L40/C6SIL/C6-C8-150
Modified Version    21    01 Feb 2017 15:20 (by user Stefan.Pendl)
Created Version     21    01 Feb 2017 15:20 (by user Stefan.Pendl)
 
------------------------------------------------------------
Defining Part for Distance Measurement(2)          : WK6277/A;1-D15,96R2_Dijet, WK6305/A;1-C6-80-C8-390.540-150 SK50 (Fully Loaded)
Defining Feature for Distance Measurement(2)       : Datum Coordinate System(0)
Position determined by assembly                    : TL2697/A;1-D15,96R2/ZW-L40/C6SIL/C6-C8-150 (Fully Loaded)
Position based upon arrangement                    : Arrangement 1
Link Status                                        : Up to Date
 
Distance Measurement(2)
------------------------------------------------------------
p5=distance4                                                           490.5

For the NXOpen API created feature I get the following information:

Feature status for: Distance Measurement(1)
Feature is alive
 
Owning part         TL2697/A;1-D15,96R2/ZW-L40/C6SIL/C6-C8-150
Modified Version    21    01 Feb 2017 15:20 (by user Stefan.Pendl)
Created Version     21    01 Feb 2017 15:20 (by user Stefan.Pendl)
 
------------------------------------------------------------
Defining Part for Distance Measurement(1)          : WK6277/A;1-D15,96R2_Dijet, WK6305/A;1-C6-80-C8-390.540-150 SK50 (Fully Loaded)
Defining Feature for Distance Measurement(1)       : Datum Coordinate System(0)
Link Status                                        : Up to Date
 
Distance Measurement(1)
------------------------------------------------------------
p3=distance2                                                               0

How can I make sure to have the feature position determined by the assembly, so I get the correct measure value?

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community
5 REPLIES

Re: How to create a measure feature at assembly level?

Esteemed Contributor
Esteemed Contributor

BTW, the recorded journal of the interactive way looks like this:

' NX 10.0.3.5
' Journal created by Stefan.Pendl on Wed Feb 01 10:29:06 2017 Mitteleuropäische Zeit
'
Option Strict Off
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: Analysis->Measure Distance...
        ' ----------------------------------------------
        Dim markId1 As NXOpen.Session.UndoMarkId
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

        Dim nullNXOpen_NXObject As NXOpen.NXObject = Nothing

        Dim measureDistanceBuilder1 As NXOpen.MeasureDistanceBuilder
        measureDistanceBuilder1 = workPart.MeasureManager.CreateMeasureDistanceBuilder(nullNXOpen_NXObject)

        measureDistanceBuilder1.Mtype = NXOpen.MeasureDistanceBuilder.MeasureType.Minimum

        theSession.SetUndoMarkName(markId1, "Measure Distance Dialog")

        Dim component1 As NXOpen.Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT WK5958-A 1"), NXOpen.Assemblies.Component)

        Dim datumPlane1 As NXOpen.DatumPlane = CType(component1.FindObject("PROTO#HANDLE R-727"), NXOpen.DatumPlane)

        measureDistanceBuilder1.Object1.Value = datumPlane1

        Dim component2 As NXOpen.Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT WK5990-A 1"), NXOpen.Assemblies.Component)

        Dim datumPlane2 As NXOpen.DatumPlane = CType(component2.FindObject("PROTO#HANDLE R-728"), NXOpen.DatumPlane)

        measureDistanceBuilder1.Object2.Value = datumPlane2

        Dim markId2 As NXOpen.Session.UndoMarkId
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Measure Distance")

        theSession.DeleteUndoMark(markId2, Nothing)

        Dim markId3 As NXOpen.Session.UndoMarkId
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Measure Distance")

        Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

        Dim measureDistance1 As NXOpen.MeasureDistance
        measureDistance1 = workPart.MeasureManager.NewDistance(unit1, NXOpen.MeasureManager.MeasureType.Minimum, False, datumPlane1, datumPlane2)

        Dim measure1 As NXOpen.Measure
        measure1 = measureDistance1.CreateFeature()

        measureDistance1.Dispose()
        Dim datadeleted1 As Boolean
        datadeleted1 = theSession.DeleteTransientDynamicSectionCutData()

        theSession.DeleteUndoMark(markId3, Nothing)

        theSession.SetUndoMarkName(markId1, "Measure Distance")

        measureDistanceBuilder1.Destroy()

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

    End Sub
End Module

The journal also looks for the prototypes of the datum planes, so I see no real difference.

The measure distance builder is for internal use only and even including it makes no difference.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: How to create a measure feature at assembly level?

Honored Contributor
Honored Contributor

To create the feature at the assembly level, you will need to work with occurrence objects. Check the .IsOccurrence property of the datum planes in your code vs. the recorded journal. My guess is that the recorded journal is returning an occurrence and not the prototype.

Re: How to create a measure feature at assembly level?

Esteemed Contributor
Esteemed Contributor

I have already tried to use the occurrence of the datum planes, but that was just resulting in the NewDistance method to fail with a second parameter is wrong exception.

Will try again today, may be some sleep got my brain a bit brighter.

Attached is my test assembly.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: How to create a measure feature at assembly level?

Valued Contributor
Valued Contributor

Hi,

The issue is you collected the prototype object and same used for measurement. The correct method is collect the prototype and gets the occurence object from the component and  use the occurence object for measurement.

Below i given the code to get the occurence object. 

 

 If theDatumPlane.Layer = 255 AndAlso theDatumPlane.Normal.X = 1.0 Then
                            theSession.ListingWindow.WriteLine(String.Format("Origin ... {0,3} ... {1}", theDatumPlane.Layer, theDatumPlane.Origin.ToString()))
                            theSession.ListingWindow.WriteLine(String.Format("Normal ... {0,3} ... {1}", theDatumPlane.Layer, theDatumPlane.Normal.ToString()))
                            'theDatumPlanes.Add(theDatumPlane)

                            ' Get the occurence object of component to measure the component objects
                            Dim thisDatum As DatumPlane = CType(theComponent.FindOccurrence(theDatumPlane), DatumPlane)
                            theDatumPlanes.Add(thisDatum)
                        End If
Selvaraj C
CAD Automation Engineer
NX 9 | NX 11 | Teamcenter 10

Re: How to create a measure feature at assembly level?

Esteemed Contributor
Esteemed Contributor

Thanks you so much @Selvaraj Smiley Very Happy

I think I have gone the wrong way, I will have to practice more with the assembly objects in .NET, might have done it right initially with the UF wrappers, but wanted to avoid them.

I am now successfully getting the correct result for the measurement using the code below.

If theDatumPlane.Layer = 255 AndAlso theDatumPlane.Normal.X = 1.0 Then
    theSession.ListingWindow.WriteLine(String.Format("Origin ... {0,3} ... {1}", theDatumPlane.Layer, theDatumPlane.Origin.ToString()))
    theSession.ListingWindow.WriteLine(String.Format("Normal ... {0,3} ... {1}", theDatumPlane.Layer, theDatumPlane.Normal.ToString()))
    
    theDatumPlanes.Add(CType(theComponent.FindOccurrence(theDatumPlane), DatumPlane))
End If

Happy coding Smiley Wink

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community