Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Need Journal Help for Value Assertion and Save-As

Status
Not open for further replies.

EnJoeNeer

Mechanical
Nov 27, 2006
17
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!
 
Replies continue below

Recommended for you

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
 
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor