Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Code read UFWeight.StateType (vb)

Status
Not open for further replies.

DragonRE

Mechanical
Jun 7, 2017
5
Hi,

i want to read the current "Weight Status" of the present File in NX with VB.Net.

Checling it manually, go to the Assembly-Navigator add the Column Weight Status and check the green Hook or yellow "?".

Some lines of Code:
if UFWeight.StateType.unknown = 3 then
' ...
end if

This Code will check if the Status "?" unknown is than 3.
Some more information can be read here:

Can someone support me in some lines Code, how to read the actual Status of weight (UFWeight.StateType = ... value).
Thanky a lot.

Kind regards, Frank
 
Replies continue below

Recommended for you

Hi Frank,

Unfortunatly I don't have the answer

But I would like to add another question:

How to retrieve the assembly weight to place it in the parts list ?

Regards
Didier Psaltopoulos
 
Hi -
You can extract the active partfile or assembly's weight(mass) by using this function:
ufs.Weight.EstabPartProps1 (pleas see net_ref.chm for further details.

Then if you run a custom program (automatic in background) every time you save, you can get the assembly weight into an attribute - which can be used in your partlist.

lklo



Code:
    Dim wProps As NXOpen.UF.UFWeight.Properties = Nothing
    Dim wExcept() As NXOpen.UF.UFWeight.Exceptions = Nothing ' changed to array, so ufs.Weight.EstabPartProps1 can be used
    Dim weight_value As Double = 0
Code:
    Function FindPartWeight(ByVal part_to_calculate As part)

        Try
            ufs.Weight.EstabPartProps1(thePart.Tag, 0.9, True, UFWeight.UnitsType.UnitsGm, wProps, wExcept)
            weight_value = (Format((wProps.mass) / 1000, "0.0000"))
            Return weight_value
        Catch e As Exception
            'nx("Failed: " & e.ToString)
            Return weight_value
        End Try

    End Function
 
Hello again,

unfortunatelly my Thread was used for a second Question and my One was not answered jet [wink]
So, i want to ask again:

I want to read the current "Weight Status" of the Workpart in NX with VB.Net.
Checking it manually: Go to the Assembly-Navigator add the Column -Weight Status- and check the green Hook or yellow "?".

The Code should read out what sign is there (green Hook or what ever).

Some lines of Code:
if UFWeight.StateType.unknown = 3 then
' ...
end if

The "UFWeight.StateType.unknown" is defined as Status 3, that means the Sign "?".
But how can i read out this Information?

Can someone support me in some lines Code, how to read the actual Status of weight (UFWeight.StateType = ... value).
Thanky a lot.

Kind regards, Frank
 
Here's some code I have (VB) that reads or calculates the weight of the work part. You can pass in the tag of a component to read the component weight instead of the work part.

Code:
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
        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim myWeightProps As UFWeight.Properties
        Dim myWeightExceptions() As UFWeight.Exceptions

        theUfSession.Weight.AskProps(workPart.Tag, UFWeight.UnitsType.UnitsLf, myWeightProps)

        lw.WriteLine("cache state: " & myWeightProps.cache_state.ToString)

        If myWeightProps.cache_state = UFWeight.StateType.NoCache Then
            'calculate weight
            theUfSession.Weight.EstabPartProps1(workPart.Tag, 0.999, True, UFWeight.UnitsType.UnitsLf, myWeightProps, myWeightExceptions)
        End If

        lw.WriteLine("mass: " & myWeightProps.mass.ToString & " lbf")

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

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

Part and Inventory Search

Sponsor