select 0d, 1d, 2d, 3d parts

here’s how to select parts based on element type

 

Here is a link to a python file

select_parts_0D_1D_2D.py

from ensight.objs import *

#
#
#
def echo_part_elem_type(p):
    if p.HAS1DELEMENTS:
        print p.DESCRIPTION, " has 1D line elements"
    if p.HAS2DELEMENTS:
        print p.DESCRIPTION, " has 2D surface elements"
    if p.HAS3DELEMENTS:
        print p.DESCRIPTION, " has 3D volume elements"
    #  Ensight 10 only
    #if p.HAS0DELEMENTS:
    #    print p.DESCRIPTION, " has 0D point elements"
    #
    # STRUCTURED MODEL PART
    #
    if p.PARTTYPE == ensight.PART_MODEL:
        if p.NODERANGESTEPI[0] > 0 and p.NODERANGESTEPI[1] > 0 and p.NODERANGESTEPI[2] > 0:
            print "Structured I from ", p.NODERANGESTEPI[0] , " to ", p.NODERANGESTEPI[1], " by step " , p.NODERANGESTEPI[2]
        if p.NODERANGESTEPJ[0] > 0 and p.NODERANGESTEPJ[1] > 0 and p.NODERANGESTEPJ[2] > 0:
            print "Structured J from ", p.NODERANGESTEPJ[0] , " to ", p.NODERANGESTEPJ[1], " by step " , p.NODERANGESTEPJ[2]
        if p.NODERANGESTEPK[0] > 0 and p.NODERANGESTEPK[1] > 0 and p.NODERANGESTEPK[2] > 0:
            print "Structured K from ", p.NODERANGESTEPK[0] , " to ", p.NODERANGESTEPK[1], " by step " , p.NODERANGESTEPK[2]
    print
    return
#
#  Note this methodology will work in ES10
#
for p in core.PARTS:
    if p.ISGROUP == True:
        if p.sources:
            for subp in p.sources:
                echo_part_elem_type(subp)
    else:
        echo_part_elem_type(p)

3 thoughts on “select 0d, 1d, 2d, 3d parts

  1. The script is quite short so very easy to understand. Unfortunately it does not pick parts on the client side.
    Some time ago I’ve worked on a way to separate part types for GUI combo items. I wanted the combos to be separated to 1D, 2D and 3D parts. Attached is the way I solved it. Unfortunately it’s three times as long as your routine:

    from cei.qtgenericdlg import *
    from generic_menu import *
    from ensight.objs import core
    #
    one_dim_list = []
    two_dim_list = []
    three_dim_list = []
    #
    # This routine selects all 3D parts in the current case
    #
    def select_3D(self):
    #list = [‘Tetra4’, ‘Tetra4’, ‘Tetra10’, ‘Pyra5’, ‘Pyra13’, ‘Penta6’, ‘Penta15’, ‘Hexa8’, ‘Hexa20’, ‘N-faced’, ‘N-faced’]
    selection = []
    for i in range(len(ensight.query_parts(‘all’,client = 1))):
    part = core.PARTS[i]

    def mod_selection(testfunc,self=None):
    newlist=[]
    for p in core.PARTS:
    if testfunc(p):
    newlist.append(p)
    core.selection(ENS_PART).addchild(newlist,replace=1)
    ensight.refresh()

    def is3D(part):
    return isElemRep(part,elemreps3D)

    def isElemRep(part,replist):
    rv=False
    d=part.partnumele #dictionary
    for key in d.keys():
    if key in replist:
    rv=True
    if rv:
    selection.append(ensight.query_parts(‘all’,client = 1)[i][0])
    return rv

    is3D(part)

    ensight.part.select_begin(selection)
    #
    # This routine selects all 2D parts in the current case
    #
    def select_2D(self):
    #list = [‘Tetra4’, ‘Tetra4’, ‘Tetra10’, ‘Pyra5’, ‘Pyra13’, ‘Penta6’, ‘Penta15’, ‘Hexa8’, ‘Hexa20’, ‘N-faced’, ‘N-faced’]
    selection = []
    for i in range(len(ensight.query_parts(‘all’,client = 1))):
    part = core.PARTS[i]

    def mod_selection(testfunc,self=None):
    newlist=[]
    for p in core.PARTS:
    if testfunc(p):
    newlist.append(p)
    core.selection(ENS_PART).addchild(newlist,replace=1)
    ensight.refresh()

    def is2D(part):
    return isElemRep(part,elemreps2D)

    def isElemRep(part,replist):
    rv=False
    d=part.partnumele #dictionary
    for key in d.keys():
    if key in replist:
    rv=True
    if rv:
    selection.append(ensight.query_parts(‘all’,client = 1)[i][0])
    return rv

    is2D(part)

    ensight.part.select_begin(selection)

    select_3D(None)
    part_info = ensight.query_parts(client=1)
    for selected_parts in range(0,len(part_info)):
    three_dim_list.append(part_info[selected_parts][3])
    ensight.part.modify_begin()
    ensight.part.visible(“OFF”)
    ensight.part.modify_end()
    #
    select_2D(None)
    part_info = ensight.query_parts(client=1)
    for selected_parts in range(0,len(part_info)):
    two_dim_list.append(part_info[selected_parts][3])
    ensight.part.modify_begin()
    ensight.part.visible(“OFF”)
    ensight.part.modify_end()
    #
    # Selecte visible (= 1D) parts
    #
    ensight.part.select_visible()
    part_info = ensight.query_parts(client=1)
    for selected_parts in range(0,len(part_info)):
    one_dim_list.append(part_info[selected_parts][3])
    ensight.part.select_all()
    ensight.part.modify_begin()
    ensight.part.visible(“ON”)
    ensight.part.modify_end()
    #
    print one_dim_list
    print two_dim_list
    print three_dim_list
    #
    # ##################################################################
    #
    # Start GUI
    #
    items = []
    items.append([‘text’,ITEM_TEXT,”Please select your parts”,””])
    items.append([‘text’,ITEM_TEXT,””,””])
    items.append([‘1D_PART’,ITEM_COMBO,”Select Particle Trace Part”,””,0,one_dim_list])
    items.append([‘2D_PART’,ITEM_COMBO,”Select Surface Part”,””,0,two_dim_list])
    items.append([‘3D_PART’,ITEM_COMBO,”Select Flowfield Part”,””,0,three_dim_list])
    a = CeiQtGenericDialog(items,None,”Part selection GUI”,”OK”,”Cancel”)

    if a.doit():
    if a.getValue(‘1D_PART’) != -1:
    print one_dim_list[a.getValue(‘1D_PART’)]
    if a.getValue(‘2D_PART’) != -1:
    print two_dim_list[a.getValue(‘2D_PART’)]
    if a.getValue(‘3D_PART’) != -1:
    print three_dim_list[a.getValue(‘3D_PART’)]

Leave a Reply