×
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

Need Journal Help for Value Assertion and Save-As

Need Journal Help for Value Assertion and Save-As

Need Journal Help for Value Assertion and Save-As

(OP)
Hi,
I am looking to automate an assembly, but I'm trying to do it without interpart expressions in the lower level components looking up to the master assembly. I am doing this because IPEs don't always update, I don't want them looking at the same assembly post save-as, and I'd like a cleaner way to do a 1-time assertion of value and then not have an IPE connection. All of the journaling I have recorded myself has gone through "make displayed part" operations and then "workPart.Expressions.EditWithUnits(expression3, unit2, """COMPONENT/01""::EXPRESSION_NAME")" type operations to identify the expression and the value to assign. Does anybody know of a means of identifying a part number, an expression, and a value to assert in one operation without changing part files? I am also looking to do something similar with a save-as. I would like to identify the current part number and do a save-as to a number part number I identify, similar to a clone, not with dissimilar string values.

Does anybody have some familiarity with this?

I could do all of this through IPEs and manual save-as, but I'd like to try something a little new and cleaner.

Thank you!

RE: Need Journal Help for Value Assertion and Save-As

The code below will prompt you to select a component; it will then list all the expressions in the component part's parent file. The commented section of the for loop will search for an expression named "dia" and change its value if found. All this can be done without changing part files (however, the components may need to be fully loaded for this to work properly, the journal doesn't check this).

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim mySelComp As TaggedObject
        If SelectComponent("select a component", mySelComp) = Selection.Response.Cancel Then
            Exit Sub
        End If

        Dim myComp As Assemblies.Component = mySelComp
        Dim myCompPart As Part
        myCompPart = myComp.Prototype.OwningPart

        lw.WriteLine("Expressions in Component: " & myComp.Name)
        For Each tempExp As Expression In myCompPart.Expressions
            'If tempExp.Name = "dia" Then
            '    Dim markId1 As Session.UndoMarkId
            '    markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Expression")
            '    myCompPart.Expressions.Edit(tempExp, "3")
            '    Dim nErrs1 As Integer
            '    nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
            'End If
            lw.WriteLine(tempExp.Name & " = " & tempExp.RightHandSide)
        Next

        lw.WriteLine("")
        lw.Close()

    End Sub

    Function SelectComponent(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a component"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_component_type
            .Subtype = UFConstants.UF_all_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selobj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function

End Module 

www.nxjournaling.com

RE: Need Journal Help for Value Assertion and Save-As

(OP)
Cowski,
Thank you VERY much, that was a huge help. I am successfully pushing string values using this method, so that you for getting me this far. Do you happen to know how to read the value of a string into the place where you are setting tempExp equal to 3? My goal is to set a string value at the top level, read this value into where you call out the integer 3, then put an if statement to assign this string value to an expression in a lower level component if found. I'm having an issue with the syntax that doesn't just pass the variable name into the lower level. Do you know if this is possible?

Thank you again for your help this far, this message board is fortunate to have you around.

RE: Need Journal Help for Value Assertion and Save-As

Is your variable declared as an integer or double type? If so, you can use the .ToString method to convert it to a string type (which is what the .Edit method is expecting). That would look something like this:

CODE

dim newValue as Double = 3.14
myCompPart.Expressions.Edit(tempExp, newValue.ToString) 

If your expressions have units associated with them, use the .EditWithUnits() method instead.

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