Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

journal for face data (problem with area and perimeter)

Status
Not open for further replies.

zmedwael

Aerospace
May 2, 2013
20
FR
Hi ,
this is the journal , the problem is that area and perimeter outputs are zeros , others are working well.
Any help .


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

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

'Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Edit->Object Display...
' ----------------------------------------------
' ----------------------------------------------
' Dialog Begin Color
' ----------------------------------------------
Dim uf As UFSession = UFSession.GetUFSession()
Dim x As Integer
Dim mySelectedObjects As nxobject()
Dim lw As ListingWindow = theSession.ListingWindow
Dim nullNXObject As NXObject = Nothing

Dim measureFaceBuilder1 As MeasureFaceBuilder
measureFaceBuilder1 = workPart.MeasureManager.CreateMeasureFaceBuilder(nullNXObject)





If SelectObjects("Hey, select multiple somethings", _
mySelectedObjects) = Selection.Response.Ok Then

For Each mySelObj As Object In mySelectedObjects

Dim boundaryFaces1(-1) As Face
Dim faceTangentRule1 As FaceTangentRule
faceTangentRule1 = workPart.ScRuleFactory.CreateRuleFaceTangent(mySelObj, boundaryFaces1, 0.5)

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

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

Dim rules1(0) As SelectionIntentRule
rules1(0) = faceTangentRule1
measureFaceBuilder1.FaceCollector.ReplaceRules(rules1, False)

Dim measureFaces1 As MeasureFaces
measureFaces1 = workPart.MeasureManager.NewFaceProperties(unit1, unit2, 0.99, measureFaceBuilder1.FaceCollector)




Dim measure1 As Measure
measure1 = measureFaces1.CreateFeature()

lw.Open()

lw.WriteLine("to string :" & myselobj.tostring)
lw.WriteLine("journalidentifier :" & myselobj.journalidentifier)
lw.WriteLine("color :" & myselobj.color)
lw.WriteLine("name :" & myselobj.name)

Dim x1, x2 As Double
x1 = measureFaces1.Area
x2 = measureFaces1.Perimeter

lw.WriteLine("Area :" & x1)
lw.WriteLine("Perimeter :" & x2)



Next
End If

End Sub



Function SelectObjects(ByVal prompt As String, _
ByRef selObj As NXObject()) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{ _
Selection.SelectionType.Faces}

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, "Choisir les faces a mailler", _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selobj)

If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function
End Module
 
Replies continue below

Recommended for you

The journal as written will allow multiple faces to be selected then will iterate through those individual faces collecting tangent faces and reporting area and perimeter of each collection. If you select 3 faces, you will end up with 3 face collections and the journal will write out 3 values of area and perimeter. Is this your intention, or do you want just 1 value for all selected/collected faces?

Also, bear in mind that the perimeter value reported is the perimeter of each individual face added together, which will be greater than the perimeter of the "region"* created by the "face set"*.

* - terms I'm making up on the fly, may not agree with or appear in NX terminology.

Anyway, below is some code I've modified to get around the issue with the original journal. The use of a face collector in the NewFaceProperties method is new to NX 8.5, so it may have some issues. I'd suggest contacting GTAC with your original code to see if the face collector is behaving as it should. Perhaps they will have a better work-around than mine.

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

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

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

        Dim uf As UFSession = UFSession.GetUFSession()
        Dim mySelectedObjects As NXObject()
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim nullNXObject As NXObject = Nothing

        Dim measureFaceBuilder1 As MeasureFaceBuilder
        measureFaceBuilder1 = workPart.MeasureManager.CreateMeasureFaceBuilder(nullNXObject)

        If SelectObjects("Hey, select multiple somethings", _
        mySelectedObjects) = Selection.Response.Ok Then

            For Each mySelObj As Object In mySelectedObjects

                Dim mFaces As New List(Of Face)

                Dim boundaryFaces1(-1) As Face
                Dim faceTangentRule1 As FaceTangentRule
                faceTangentRule1 = workPart.ScRuleFactory.CreateRuleFaceTangent(mySelObj, boundaryFaces1, 0.5)

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

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

                Dim rules1(0) As SelectionIntentRule
                rules1(0) = faceTangentRule1
                measureFaceBuilder1.FaceCollector.ReplaceRules(rules1, False)

                Dim measureFaces1 As MeasureFaces
                For Each tempFace As TaggedObject In measureFaceBuilder1.FaceCollector.GetObjects
                    mFaces.Add(CType(tempFace, Face))
                Next
                measureFaces1 = workPart.MeasureManager.NewFaceProperties(unit1, unit2, 0.99, mFaces.ToArray)

                'Dim measure1 As Measure
                'measure1 = measureFaces1.CreateFeature()

                lw.Open()

                lw.WriteLine("to string :" & myselobj.tostring)
                lw.WriteLine("journalidentifier :" & myselobj.journalidentifier)
                lw.WriteLine("color :" & myselobj.color)
                lw.WriteLine("name :" & mySelObj.name)
                lw.WriteLine("number of faces collected: " & measureFaceBuilder1.FaceCollector.GetObjects.Length.ToString)

                Dim x1, x2 As Double
                x1 = measureFaces1.Area
                x2 = measureFaces1.Perimeter


                lw.WriteLine("Area :" & x1)
                lw.WriteLine("Perimeter :" & x2)

            Next
        End If

    End Sub



    Function SelectObjects(ByVal prompt As String, _
    ByRef selObj As NXObject()) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim typeArray() As Selection.SelectionType = _
        { _
        Selection.SelectionType.Faces}

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
        prompt, "Choisir les faces a mailler", _
        Selection.SelectionScope.AnyInAssembly, _
        False, typeArray, selobj)

        If resp = Selection.Response.ObjectSelected Or _
        resp = Selection.Response.ObjectSelectedByName Or _
        resp = Selection.Response.OK Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function
End Module

www.nxjournaling.com
 
the main goal of my journal was to find faces that have the same area (or perimeter) as a reference face (just one reference face) .
but I still don't understand why the journal that you wrote is working (e.g area and perimeter appear in a listing window) while mine don't , in my journal just an empty listing window appears with no infos.
is that because you're using a face collector ?

Thanks !!
 
The original code you posted is puzzling because only zeros are written to the listing window, but the created measurement feature contains the expected values. I originally tried your code in NX 8 and it errored out on this line:

Code:
measureFaces1 = workPart.MeasureManager.NewFaceProperties(unit1, unit2, 0.99, [highlight #FCE94F]measureFaceBuilder1.FaceCollector[/highlight])

In NX 8 and earlier, you could not pass a FaceCollector directly to the NewFaceProperties method; you had to pass an array of faces. This functionality is new to NX 8.5, hence my comment about showing your original code to GTAC; either it isn't functioning as expected, or we are not calling it correctly. In the code I posted, all I did was take the faces from the FaceCollector and put them into an array which I passed to the NewFaceProperties method.

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top