Submitted by balamurali25 on Wed, 03/30/2016 - 01:38
Forums:
Hi,
looking for a journal which could process all NX files in a folder and display the file name and the measured volume in the listing window. (Information window) . Please help.
Hey, check out this Journal
Hey, check out this Journal here: http://www.nxjournaling.com/content/process-files-directory
Between the code provided in that link and this code below, you should be able to put something together that will do what you need:
This will process the instance bodies, not the prototype bodies and will give you the volume and centers of each part.
If you have any other questions or need help putting this together just let us know.
Imports System
Imports NXOpen
Imports NXOpen.UF
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Public Sub Main(ByVal args As String())
Dim bodies As Body() = AskAllBodies(workPart)
Echo("Found " & bodies.Length & " bodies")
Dim myMeasure As MeasureManager = theSession.Parts.Display.MeasureManager()
Dim massUnits(4) As Unit
massUnits(0) = theSession.Parts.Display.UnitCollection.GetBase("Area")
massUnits(1) = theSession.Parts.Display.UnitCollection.GetBase("Volume")
massUnits(2) = theSession.Parts.Display.UnitCollection.GetBase("Mass")
massUnits(3) = theSession.Parts.Display.UnitCollection.GetBase("Length")
Dim totalVolume As Double = 0
Dim mb As MeasureBodies
For Each tempBody As Body In bodies
mb = myMeasure.NewMassProperties(massUnits, 1, {tempBody})
mb.InformationUnit = MeasureBodies.AnalysisUnit.PoundFoot
Echo(tempBody.OwningComponent.Name & "; " & mb.Volume.ToString())
totalVolume += mb.Volume
Next
Echo("total volume = " & totalVolume)
End Sub
Function AskAllBodies(ByVal thePart As Part) As Body()
Dim theBodies As New System.Collections.ArrayList()
Dim aBodyTag As Tag = Tag.Null
Do
theUFSession.Obj.CycleObjsInPart(thePart.Tag, _
UFConstants.UF_solid_type, aBodyTag)
If aBodyTag = Tag.Null Then
Exit Do
End If
Dim theType As Integer, theSubtype As Integer
theUFSession.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
If theSubtype = UFConstants.UF_solid_body_subtype Then
theBodies.Add(theSession.GetObjectManager.GetTaggedObject(aBodyTag))
End If
Loop While True
Return DirectCast(theBodies.ToArray(GetType(Body)), Body())
End Function
Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub
Public Function GetUnloadOption(ByVal arg As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
Help needed in selecting all solid bodies
Hi,
I tried combining both the codes. First tested the folder process code by making it printing an attribute in the listing window . It worked great.
when I tried combining the codes for the volume, the code is only processing the first body it is taking from the assembly. The functionality should be that it should process all the solid bodies (irrespective of assembly or part) that is present.
Any idea regarding selecting all the solid bodies instead of single body ??
Update : I resolved the previous issue i guess. But now whenever this code is measuring volume from the file,If a sheet body exists , it takes the sheet body as a solid body and gives and additional volume.
P.s I have used the same code that you provided for the volume calculation part.
Any help would be appreciated.