cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the youngs modulus and poissons ratio as string

Creator
Creator

Hello,

 

just a quick question. Iam currently working on a preprocessor for fem analysis. So my little tool checks if a material is assigned, which already works.

 

Now it should also check for the youngs modulus and poissons ratio but I cannot find the right attribute. Could someone help me?

 

I read the material in the following way:

 

string material = workPart.GetStringAttribute("MATERIAL");

 

Thanks in advance.

1 REPLY

Re: Getting the youngs modulus and poissons ratio as string

Phenom
Phenom

The code below gets the work part's "Material" attribute then attempts to get the material properties. If the material is found, the Young's modulus and Poisson's ratio are reported to the information window.

 

The code is written in VB and was tested with NX 9.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    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 = "report material"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)


        Dim matMissing As NXObject.AttributeInformation = Nothing
        matMissing = workPart.GetUserAttribute("MaterialMissingAssignments", NXObject.AttributeType.String, -1)
        If matMissing.StringValue.ToUpper = "TRUE" Then
            'no material assigned
            lw.WriteLine("no material assigned")
            Return
        End If

        Dim matNameAssigned As NXObject.AttributeInformation = Nothing
        matNameAssigned = workPart.GetUserAttribute("Material", NXObject.AttributeType.String, -1)
        lw.WriteLine("material assigned: " & matNameAssigned.StringValue)

        Dim theChosenMaterial As PhysicalMaterial = Nothing
        'use material if it is loaded
        theChosenMaterial = workPart.MaterialManager.PhysicalMaterials.GetLoadedLibraryMaterial("physicalmateriallibrary.xml", matNameAssigned.StringValue)

        If IsNothing(theChosenMaterial) Then
            'load material from library
            theChosenMaterial = workPart.MaterialManager.PhysicalMaterials.LoadFromNxmatmllibrary(matNameAssigned.StringValue)
        End If

        If IsNothing(theChosenMaterial) Then
            lw.WriteLine("material not found in NX material library")
            Return
        End If

        Dim propTable As BasePropertyTable = Nothing
        propTable = theChosenMaterial.GetPropTable

        Dim youngsModProp As Fields.ScalarFieldWrapper = Nothing
        youngsModProp = propTable.GetScalarFieldWrapperPropertyValue("YoungsModulus")
        Dim ymExp As Expression = youngsModProp.GetExpression
        lw.WriteLine("Young's Modulus: " & ymExp.RightHandSide & " " & ymExp.Units.Abbreviation)

        Dim poissonRatio As Fields.ScalarFieldWrapper = Nothing
        poissonRatio = propTable.GetScalarFieldWrapperPropertyValue("PoissonsRatio")
        Dim poissonExp As Expression = poissonRatio.GetExpression
        lw.WriteLine("Poisson's ratio: " & poissonExp.RightHandSide)

        lw.Close()

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module