journal for face data (problem with area and perimeter)
journal for face data (problem with area and perimeter)
(OP)
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
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





RE: journal for face data (problem with area and perimeter)
Did you get this to work?
www.nxjournaling.com
RE: journal for face data (problem with area and perimeter)
RE: journal for face data (problem with area and perimeter)
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 Modulewww.nxjournaling.com
RE: journal for face data (problem with area and perimeter)
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 !!
RE: journal for face data (problem with area and perimeter)
CODE
measureFaces1 = workPart.MeasureManager.NewFaceProperties(unit1, unit2, 0.99, measureFaceBuilder1.FaceCollector)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