Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

simple sample code for looping through all open part and update them

Status
Not open for further replies.

godpaul

Automotive
Joined
May 4, 2014
Messages
119
Location
US
based on cowski suggestion yesterday, here is the simple code for updating all model, for simplicity, i didnt link to Excel but just ask the cdeo to find a specific parameter and replace the value, after that, update the model

Code:
'loop through all models and update
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Annotations
Imports System.Text.RegularExpressions
Imports System.Collections.Generic
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen.Assemblies



Module updateAllModelfgh

    Dim theSession As Session = Session.GetSession()
    Dim LW As ListingWindow = theSession.ListingWindow


    Sub Main()
        Dim workpart As Part = theSession.Parts.Work
        LW.Open()

        For Each part As Part In theSession.Parts

            Dim partLoadStatus As PartLoadStatus
            Dim status1 As PartCollection.SdpsStatus
            status1 = theSession.Parts.SetDisplay(part, False, False, partLoadStatus)

            Try

                For Each NXExp As Expression In part.Expressions
                    'replace expression
                    If NXExp.Name = "diameter" Then
                        NXExp.RightHandSide = "8"
                    End If
                Next
                Dim upDateMark1 As Session.UndoMarkId
                theSession.UpdateManager.DoUpdate(upDateMark1)

            Catch ex As NXException
                If ex.ErrorCode = 3520016 Then
                    LW.WriteLine("No expressions in NX were found that can match with the external expressions")
                Else
                    LW.WriteLine(ex.ErrorCode & ": " & ex.Message)
                End If


            End Try

        Next

    End Sub

End Module

the purpose i want to do this code is that later on i want to have two models, model 1 and 2, model 2 has some parameters controlled by model 1, yes, use interpart relationship, such a poweful finding!!!!!!
 
got anther question:

in model 1, there is an expression:
diameter = 7

in model 2, there is an expression:
newDia = 10*("model1"::diameter)

i notice: if i delete model 1, and open up model 2, No error such as model 1 is missing, bala,bala....which happens in assembly if one part is missing in the folder


so, if model 2 can work standalone, how does NX remember the value of diameter? right now, it shows that newDia = 70....
 
This is getting into the internal workings of NX, of which I have no specialized knowledge. However, based on its behavior, I'd guess that model2 is caching the last known value of the expression from model1 to use if/when model1 is not available.

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

Part and Inventory Search

Sponsor

Back
Top