Mass assigned to all the bodies

Hi ladies and gentlemen,

I'm new to Jorunal Programming. I'm looking for a solution to a problem.
In NX 12 at the component level, there must be a mass assigned to all the bodies within the component. (All Volume body!)
In the message box, you should enter the weight of the component and calculate the density in proportion to the total volume. The total weight of the component should be the same as the value entered.

I can use VB and Pyton too.

Thanks a lot.

Do you have an advanced assemblies license?
If so, you can assign (assert) a weight to a component.

If you do not have an advanced assemblies license, you can assign the density as needed (as described in your post) to the bodies in the component part file. This might get a bit tricky if the component part has multiple bodies, but only some of them are used in the reference set used in the assembly. The "weight" assigned in this way will not be associative to changes made in the model.

Hy,

thanks for your reply. I haven't this license. :(
I have this solution. I have with Expression m (weigt) and Assotiative Volume measurement (V) solwed. Density (D) = m/V

After this can i go to manuel change this Value, because density input isn't parameter or Attribute.

I have this Code, but it search the first Body, and the other bodies haven't Mass --> Mass Center.

Could you help this code to fixing?

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Public Enum units
PoundsInches = 1
PoundsFeet = 2
GramsCentimeters = 3
KilogramsMeters = 4
End Enum

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "measure body"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim theSolid As Body = Nothing
Dim found As Boolean = False

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ change desired units here
Const analysisUnits As units = units.KilogramsMeters
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

'iterate through the bodies collection, measure first solid body found
For Each temp As Body In workPart.Bodies
If temp.IsSolidBody Then
found = True
theSolid = temp
End If
Next

If Not found Then
lw.WriteLine("no solid body found in file")
Return
End If

Dim accuracyValues(10) As Double
accuracyValues(0) = 0.99
Dim massProps(46) As Double
Dim stats(12) As Double
theUfSession.Modl.AskMassProps3d({theSolid.Tag}, 1, 1, analysisUnits, 1, 1, accuracyValues, massProps, stats)

Dim surfaceArea As Double = massProps(0)
Dim volume As Double = massProps(1)
Dim mass As Double = massProps(2)

' itt irom le, hogy a mert volument es a suruseget szamitsa ki a tomeggel amit be kell irni.

Dim gewicht as double

gewicht=Inputbox("Gewünschte Masse in Kg:")

Dim dichte as double

dichte = gewicht / massProps(1)

' ----------------------------------------------
' Menü: Bearbeiten->Formelement->Dichte...
' ----------------------------------------------

markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim solidDensity1 As NXOpen.GeometricAnalysis.SolidDensity = Nothing
solidDensity1 = workPart.AnalysisManager.CreateSolidDensityObject()

solidDensity1.Density = dichte

solidDensity1.Units = NXOpen.GeometricAnalysis.SolidDensity.UnitsType.KilogramsPerCubicMeters

solidDensity1.Units = NXOpen.GeometricAnalysis.SolidDensity.UnitsType.KilogramsPerCubicMeters

solidDensity1.Density = dichte

theSession.SetUndoMarkName(markId1, "Dichte zuweisen-Dialogfenster")

For Each temp As Body In workPart.Bodies
If temp.IsSolidBody Then
found = True
theSolid = temp
End If
Next

If Not found Then
lw.WriteLine("no solid body found in file")
Return
End If

Dim added1 As Boolean = Nothing
added1 = solidDensity1.Solids.Add(theSolid)

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Dichte zuweisen")

solidDensity1.Density = dichte

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Dichte zuweisen")

Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = solidDensity1.Commit()

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(markId1, "Dichte zuweisen")

solidDensity1.Destroy()

theSession.CleanUpFacetedFacesAndEdges()

End Sub

End Module

Just a simple EngineerGuy :)

I like to ask about existing NX functionality before writing code to duplicate it. If this is something that you do on a regular basis, you might consider getting this extra functionality in NX; it usually works better in the long run rather than writing your own version.

Anyway, try the journal below. It will look for solid bodies in the current work part and assign the density based on the desired weight and calculated volume.

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

Module Module157

Public Enum units
PoundsInches = 1
PoundsFeet = 2
GramsCentimeters = 3
KilogramsMeters = 4
End Enum

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "measure body"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim theSolids As New List(Of Body)
Dim theSolidTags As New List(Of Tag)

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ change desired units here
Const analysisUnits As units = units.KilogramsMeters
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

'iterate through the bodies collection, measure first solid body found
For Each temp As Body In workPart.Bodies
If temp.IsSolidBody Then
theSolids.Add(temp)
theSolidTags.Add(temp.Tag)
End If
Next

If theSolids.Count = 0 Then
lw.WriteLine("no solid body found in file")
Return
End If

Dim accuracyValues(10) As Double
accuracyValues(0) = 0.99
Dim massProps(46) As Double
Dim stats(12) As Double
theUfSession.Modl.AskMassProps3d(theSolidTags.ToArray, theSolidTags.Count, 1, analysisUnits, 1, 1, accuracyValues, massProps, stats)

Dim surfaceArea As Double = massProps(0)
Dim volume As Double = massProps(1)
Dim mass As Double = massProps(2)

' itt irom le, hogy a mert volument es a suruseget szamitsa ki a tomeggel amit be kell irni.
'here I write down how to calculate the volume and density with the amount to be entered.

Dim gewicht As Double
gewicht = InputBox("Gewünschte Masse in Kg:")

Dim dichte As Double
dichte = gewicht / massProps(1)

markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Dichte zuweisen")

Dim solidDensity1 As NXOpen.GeometricAnalysis.SolidDensity = Nothing
solidDensity1 = workPart.AnalysisManager.CreateSolidDensityObject()

solidDensity1.Units = NXOpen.GeometricAnalysis.SolidDensity.UnitsType.KilogramsPerCubicMeters
solidDensity1.Density = dichte

Dim added1 As Boolean = Nothing
added1 = solidDensity1.Solids.Add(theSolids.ToArray)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Dichte zuweisen")

Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = solidDensity1.Commit()

theSession.DeleteUndoMark(markId3, Nothing)

solidDensity1.Destroy()

theSession.CleanUpFacetedFacesAndEdges()

End Sub

End Module

Hy,

Thank you. It works great.
I try to learn this programing, but without Course it will be a bit harder.

Best Regards

Just a simple EngineerGuy :)