NX Journal Dialog to select a component

2019/12/12 categories:NX Journal| tags:NX Journal|Python|

I have created a program that displays a dialog for selecting a component.

You can display the selection dialog with “Select Tagged Object” in the “Selection” class of NX Open.

The title of the dialog is specified by “title” in the code, the message of the dialog is specified by “message”, and the attribute is specified by “myAttribute”. Specify the target to be selected in this dialog with “mask”. The information window is used to display the attributes.

If you use “Select Tagged Object” to select an object, you will be able to process the selected object, so I think the created command will be easier to use.

Python Code

import NXOpen

def main():
    theSession = NXOpen.Session.GetSession()
    lw = theSession.ListingWindow

    components = SelectComponent()

    for component in components:
        lw.WriteLine( component.GetStringAttribute("myAttribute") )

def SelectComponent():
    scope = NXOpen.SelectionSelectionScope.AnyInAssembly
    action = NXOpen.SelectionSelectionAction.ClearAndEnableSpecific
    mask = NXOpen.SelectionMaskTriple_Struct
    mask.Type = NXOpen.UF.UFConstants.UF_component_type
    mask.Subtype = NXOpen.UF.UFConstants.UF_component_subtype
    response, objects = NXOpen.Selection.SelectTaggedObjects("message", "title", scope, action, False, False, [mask])
    if not response == NXOpen.SelectionResponse.ObjectSelectedByName or not response == NXOpen.SelectionResponse.ObjectSelected:
        return []
    return objects

if __name__ == '__main__':

Share post

Related Posts