Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Attribute strange behavior. Don't save instance attributes.

Status
Not open for further replies.

javaxp

Automotive
Jul 14, 2014
43
Hi,

I'm suffering a strange behavior setting attributes.


I've made a journal that sets the attribute "PLIST_IGNORE_MEMBER" to selected components in an assembly.


If I use:

Code:
component.SetUserAttribute(attName, -1, attVal, Update.Option.Now)

the attribute is saved. But if I use:

Code:
 component.SetInstanceUserAttribute(attName, -1, attVal, Update.Option.Now)

the attribute is not saved at all.

I've found a relationed thread , but no clue about .

The code complete is:


Code:
Imports NXOpen
Imports NXOpen.Assemblies

''' <summary>
''' Asigna el atributo PLIST_IGNORE_MEMBER de las instancias seleccionadas
''' </summary>
Module SetAttributeToSelectedInstances

    Sub Main()

        Const attName As String = "PLIST_IGNORE_SUBASSEMBLY"
        Const attVal As String = "Yes"

        Dim session As Session = Session.GetSession()
        Dim nxUI As UI = UI.GetUI
        Dim selectCount As Integer
        Dim selobj As TaggedObject
        Dim component As Component
        Dim workPart As Part = session.Parts.Work

        Try

            


            'Numero de objetos seleccionados
            selectCount = nxUI.SelectionManager.GetNumSelectedObjects()

            'Si hay algo seleccion
            If selectCount > 0 Then

                'Recorre los elementos seleccionados
                For index As Integer = 0 To selectCount - 1

                    'Obtiene el elemento seleccionado
                    selobj = nxUI.SelectionManager.GetSelectedTaggedObject(index)

                    'Comprueba que sea un componente
                    If TypeOf selobj Is Component Then

                        'Convierte el elemento seleccionado a Component
                        component = CType(selobj, Component)

                      

                        'Asigna el valor
                        component.SetInstanceUserAttribute(attName, -1, attVal, Update.Option.Now)
                      
                       
                        

                    End If

                Next

                nxUI.NXMessageBox.Show("Terminado", NXMessageBox.DialogType.Information, "Cambios completados correctamente")

            Else
                'Muestra mensaje
                nxUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Warning, "No hay ningun elemento seleccionado")


                component = session.Parts.WorkComponent
                component.SetInstanceUserAttribute(attName, -1, attVal, Update.Option.Now)
               

            End If

        Catch ex As NXException
            If nxUI IsNot Nothing Then
                nxUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Error ejecutando la macro")
            End If
        Finally
            'Libera la memoria
            component = Nothing
            selobj = Nothing
            nxUI = Nothing
            session = Nothing
        End Try

    End Sub


    Public Function GetUnloadOption(ByVal text As String) As Integer
        'Libera la libreria inmediatamente
        Return CInt(Session.LibraryUnloadOption.Immediately)
    End Function

End Module

Thanks in advance,

Javi




NX 12.0.2.9 MP14
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor