×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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 --> vb

'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!!!!!!

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

(OP)
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....

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources