Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Highlighting/selecting a component during journal operation 1

Status
Not open for further replies.

erpj

Aerospace
Jul 15, 2011
24
Hi everyone,
I wrote a journal (mainly by combining bits and pieces on this very forum) that creates a "START" attribute for each selected component in an assembly.
My problem is that my journal does not show any visual cue of what component is having its start attribute created/modified while it is happening.

Is there a way to select a specific component (or give any other visual feedback) during the journal execution?

Any help would be greatly appreciated.

Thanks!

Code:
'NXJournaling
'2014-06-19
'Etiennovski
'This program will ask the user to select one (or multiple) component(s) and then cycle thru each one of those
'and ask for a new value for the "START" attribute.  1 = true, 0 = false
' NOTE: If the attribute does not exist, the program will create it.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module create_or_update_START_ATTRIBUTE

    Sub Main()
    
        '---INITIALYZING ALL RELEVANT VARIABLES
        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        'lw.Open()

        Dim myComponents() As TaggedObject

        If SelectComponents("Select components", myComponents) = Selection.Response.Cancel Then
            Return
        End If

        For Each tempComp As Component In myComponents
            Try
                '---PERFORM OPERATION IF BOOLEAN ALREADY EXISTS
                Dim myCompAttr As String
                'assign attribute to string variable, change "attribute_title" as needed
                myCompAttr = tempcomp.GetStringAttribute("START")
                'write string variable to listing window
                'lw.WriteLine("Attribute Value: " & myCompAttr)
                'lw.WriteLine("")
                
                
            Catch ex As NXException
                
                '---BOOLEAN DID NOT EXIST SO WE CREATE IT
                If ex.ErrorCode = 512008 Then
                    'MsgBox("The attribute does not exists, let's create it!")
                    
                    
                    '---------------------------------
                    Dim objects(0) As NXObject
                    objects(0) = tempcomp
                    Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
                    attributePropertiesBuilder1 = workpart.PropertiesManager.CreateAttributePropertiesBuilder(objects)
                    attributePropertiesBuilder1.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentInstance
                    attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.Boolean
                    attributePropertiesBuilder1.Title = "START"
                    attributePropertiesBuilder1.IsArray = False
                    attributePropertiesBuilder1.BooleanValue = 1
                    Dim nXObject2 As NXObject
                    nXObject2 = attributePropertiesBuilder1.Commit()
                    attributePropertiesBuilder1.Destroy()
                    
                    '---------------------------------
             
                    
                Else
                    MsgBox(ex.ErrorCode.ToString & " : " & ex.Message)
                End If
                
            End Try
            
            Dim newStr as String
            Dim defAns as String
            Dim newBool as Boolean
            newStr="sup"
            newBool = tempcomp.GetStringAttribute("START")
            If newBool Then
            defAns=1
            Else
            defAns=0
            End If
                            Do While (newStr<>"1" And newStr<>"0")
                            REM newBool = 
                            newStr=InputBox("Component is at the start? (1/0)", "START attribute definition", defAns)
                            if newStr = "" then
                            'null string means cancel was pressed, exit journal
                            Continue Do
                            end if
                            
                            '---BASED ON USER ANSWER WE UPDATE THE ATTRIBUTE
                                                     
                            Dim objects(0) As NXObject
                            objects(0) = tempcomp
                            Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
                            attributePropertiesBuilder1 = workpart.PropertiesManager.CreateAttributePropertiesBuilder(objects)
                            attributePropertiesBuilder1.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentInstance
                            attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.Boolean
                            attributePropertiesBuilder1.Title = "START"
                            attributePropertiesBuilder1.IsArray = False
                            attributePropertiesBuilder1.BooleanValue = newStr
                            Dim nXObject2 As NXObject
                            nXObject2 = attributePropertiesBuilder1.Commit()
                            attributePropertiesBuilder1.Destroy()
                            
                            Loop
             
        Next

    End Sub


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

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select components"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        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_component_subtype
        End With

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

    End Function
    
    

    Function SelectSpecificComponent(myComponent) As Selection.Response
        '???????????????????
    End Function
    

    Function UnselectAllComponents() As Selection.Response
        '???????????????????
    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

Etienne
NX7.5.4.4 + TC Unified 8.3.2

 
Replies continue below

Recommended for you

What version of NX are you using?
Your signature line lists NX 7.5, but your code makes use of objects/methods not added until NX 8.

www.nxjournaling.com
 
Sorry I realized my signature was wrong after I posted. I'm running NX8.5.3.3 thru teamcenter 9.


Etienne
NX8.5.3.3 + TC9.1.2.2

 
To give some visual feedback, you can set the .Highlight of the component while it is being processed. But if all you are doing is checking/setting an attribute, the code may execute too quickly to give meaningful visual feedback.

The .GetStringAttribute method is deprecated in NX 8.5; use .GetStringUserAttribute or .GetBooleanUserAttribute in your case. Don't mix string and boolean attributes (don't set a boolean attribute then use .GetStringUserAttribute to read its value).

In NX 8 and above, there is a .HasUserAttribute method; this is now the preferred way to see if an attribute exists. The Try...Catch block was a bit of a workaround in previous versions.

www.nxjournaling.com
 
Wow thank you cowski for your helpful reply!
It's almost working, I can highlight each part while the attribute is being edited. However, for the first iteration everything selected stays highlighted. Is there a dumpSelection method or something that would perform the same function?


Etienne
NX8.5.3.3 + TC9.1.2.2

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor