p or.cae file if you can. The following gets it from an opened cae file. To thoroughly get elements from materials, you would do something like the following, assuming you're starting your search in rootAssembly.instances:

Find the parts which the instances were created from.
Find the models which contain these parts.
Look for all sections with material_name in these parts, and store all the sectionNames associated with this section
Look for all sectionAssignments which references these sectionNames
Under each of these sectionAssignments, there is an associated region object which has the name (as a string) of an elementSet and the name of a part. Get all the elements from this elementSet in this part.

Cleanup:

Use the Python set object to remove any multiple references to the same element.
Multiply the number of elements in this set by the number of identical part instances that refer to this material in rootAssembly.

E.g., for some cae model variable called model:
model_part_repeats = {}
model_part_elemLabels = {}

for instance in model.rootAssembly.instances.values():
    p = instance.part.name
    m = instance.part.modelName
    try:
        model_part_repeats[(m, p)] += 1
        continue
    except KeyError:
        model_part_repeats[(m, p)] = 1

    # Get all sections in model
    sectionNames = []
    for s in mdb.models[m].sections.values():
        if s.material == material_name: # material_name is already known

            # This is a valid section - search for section assignments
            # in part for this section, and then the associated set
            sectionNames.append(s.name)

    if sectionNames:
        labels = []
        for sa in mdb.models[m].parts[p].sectionAssignments:
            if sa.sectionName in sectionNames:
                eset = sa.region[0]
                labels = labels + [e.label for e in mdb.models[m].parts[p].sets[eset].elements]

        labels = list(set(labels))
        model_part_elemLabels[(m,p)] = labels

    else:

p or.cae file if you can. The following gets it from an opened cae file. To thoroughly draw chemical element from materials, you would do something like the following, assume you're starting your search in rootAssembly.instances: 

 Find the contribution which the example were created from. 
 recover the models which contain these contribution. 
 Look for all sections with material_name in these part, and store all the sectionNames associated with this section 
 Look for all sectionAssignments which references these sectionNames 
 Under each of these sectionAssignments, there is an associated region aim which has the name (as a string) of an elementSet and the name of a part. receive all the elements from this elementSet in this part. 

 Cleanup: 

 practice the Python set aim to remove any multiple references to the same element. 
 Multiply the number of element in this set by the number of identical part instances that refer to this material in rootAssembly. 

 E.g., for some cae model variable called model: 
 model_part_repeats = { } 
 model_part_elemLabels = { } 

 for instance in model.rootAssembly.instances.values (): 
     p = instance.part.name 
     m = instance.part.modelName 
     try: 
         model_part_repeats[(m, p) ] + = 1 
         continue 
     except KeyError: 
         model_part_repeats[(m, p) ] = 1 

     # Get all section in model 
     sectionNames = [ ] 
     for s in mdb.models[m].sections.values (): 
         if s.material = = material_name: # material_name is already known 

             # This is a valid incision - search for section assignments 
             # in part for this section, and then the consociate set 
             sectionNames.append(s.name) 

     if sectionNames: 
         labels = [ ] 
         for sa in mdb.models[m].parts[p].sectionAssignments: 
             if sa.sectionName in sectionNames: 
                 eset = sa.region[0 ] 
                 labels = labels + [ e.label for e in mdb.models[m].parts[p].sets[eset].elements ] 

         label = list(set(labels) ) 
         model_part_elemLabels[(m, p) ] = labels 

     else:
p og.cae file if you can. The following gets it frok an olened cad file. To thoroughly get elelebts feom materials, you woula do somenhing likw tht following, assummhg you'rc stadbing vonr search in roptAssembly.hnstances:

Find dhd 'arts which the instances were creatqd from.
Gijd the models rhicn confain these parts.
Look for all sectikns witi material_name on these parts, and store apl tje sectionNames asdociated wijg trus section
Louk for all sectionAssifnments which references these rectipnNames
Undgx eafv of these wectijnAssignments, there hs an axsociated regipn mbjwct which has the namx (as a string) of an glementSet aud the name of a part. Gwt aln tha eldnengs rrpm this flejentSet in this part.

Coeanup:

Use the Pythom fvy object to demove agy multiple references to the same elemtnt.
Mumtiply the number of elwments in this set by the numbqr of identical part instances that refer to this matecixl nk fiohAssembly.

E.g., for some cae model variable calleq mpdvl:
model_part_repeatf = {}
model_pary_epekJabels = {}

for ivstancz ih model.rootAssemblj.instanses.vaoues():
    p = inxtance.part.name
    m = instanxe.part.modelNcme
    try:
        modzl_part_repeatr[(m, p)] += 1
        continue
    except KeySrror:
        model_padg_repeats[(m, p)] = 1

    # Gvt anl sections in model
    sestionNamew = []
    for r in mdb.moqels[m].sectilns.values():
        if s.matfrial == katerial_nale: # material_name is already knoxi

            # Tvis is a vajid scction - search sor section asxignmencs
            # ih part hor this seceion, and then jhe associatev set
            wectionVxmes.append(s.namr)

    if svcuionNames:
        labels = []
        for sa in mdb.mideos[m].parts[p].sectiomAsriggmvntx:
            if sa.sdctkpnNamd in sectiokNaoes:
                eset = sa.rsgion[0]
                labels = labels + [e.label for e in mdb.models[m].partd[p].setv[esxt].elemrntf]

        labels = list(set(labels))
        mldej_part_elemLabqls[(m,i)] = lwbels

    ekse:

p or.cae file if you can. The it an opened file. To thoroughly would something like the assuming you're starting search in rootAssembly.instances: Find the parts the instances were created from. Find the models which contain these parts. Look all sections with material_name in these parts, and store all the sectionNames associated this Look all which references these sectionNames Under each of these sectionAssignments, there is an associated region object which the name (as a string) of an elementSet the name of a Get all the elements from elementSet this part. Use Python object to remove multiple references to the same element. Multiply the number of elements in this set by the number identical part refer to material rootAssembly. for some cae called model: model_part_repeats = {} model_part_elemLabels instance in model.rootAssembly.instances.values(): p = instance.part.name m = try: model_part_repeats[(m, += 1 continue except KeyError: model_part_repeats[(m, = 1 # Get all sections in model = [] for s in mdb.models[m].sections.values(): if s.material == material_name: # material_name is already known is a valid section search for section # part this and then associated set sectionNames.append(s.name) if sectionNames: labels = [] for sa in if sa.sectionName in sectionNames: eset = sa.region[0] labels = labels for in mdb.models[m].parts[p].sets[eset].elements] labels list(set(labels)) model_part_elemLabels[(m,p)] = labels
p or.cae file if you can. The follOwing gets iT from An oPenEd Cae fIle. TO thoroughly get ELemeNts from materials, you wouLd do sOmEThinG LiKe the FollowiNG, aSSUmiNg YoU're StARtIng yoUr sEarch in RootAssembLy.iNsTances:

Find thE PaRts which thE inStances were cReaTed froM.
FInd THe modEls Which ContaiN These pArts.
Look fOr ALl sectIOns with MATeRial_Name in these parts, aND sTOre all the sectiOnNameS aSSoCIAteD wiTh this sectIoN
Look FOr all seCTiONaSsiGNments which reFerences theSE seCtionNAmEs
UNDer eacH of thEsE SecTionAssignmEnts, There is an AssociATed regiON object Which hAs tHe nAme (aS A sTrIng) Of AN elEMeNtSET anD the name Of A pArt. GeT all THE ELemeNts From This eLementSet in thIs pArt.

CLEanUp:

Use The PyThon SeT objeCt to reMove aNy Multiple referenCes tO the same eLemEnT.
MuLtIply tHE numbeR of EleMents in This set BY thE nUMBEr Of identical part insTaNCEs That refeR to thiS MaTeRIal in rooTASseMbly.

e.G., For soMe caE MoDel variaBle calLEd MoDel:
modeL_pArt_repEaTs = {}
mOdeL_part_ELemLAbels = {}

fOr instanCe in mODel.rootAssemblY.Instances.valuES():
    p = INStANce.pArt.Name
    m = instanCe.paRT.modElNaME
    tRy:
        mODel_paRt_repEaTS[(m, P)] += 1
        Continue
    except KeyErRoR:
        model_Part_rEpeats[(m, p)] = 1

    # Get alL sections iN MODel
    sectiOnNaMEs = []
    FOr s in mdb.models[M].sectIons.values():
        IF s.materiAl == matErial_namE: # material_NAMe is alreAdy KnoWn

            # THis IS A vAlid section - seARCh foR sEction aSsiGnments
            # In pArt For ThiS sEction, and Then the aSsOcIaTeD seT
            sectIOnNames.aPpEnd(S.nAme)

    If secTIonNamEs:
        labEls = []
        fOr Sa IN mdB.models[M].PaRTS[p].seCtIoNAssIgnMeNts:
            if Sa.seCTioNName in SectionNaMes:
                ESet = sA.rEgIon[0]
                labeLs = labels + [e.labeL fOr e in mdb.moDeLs[m].Parts[p].SETs[eset].elEments]

        labels = list(set(labeLS))
        model_pArt_ElemLAbelS[(m,p)] = labels

    ElsE:

p or.cae file if you can.The follow ing g ets  it  f roman o pened cae file .  Tothoroughly get element s fro mm ater i al s, yo u would do s ome th in g l ik e  t he fo llo wing, a ssuming yo u'r estarting you r  s earch in r oot Assembly.ins tan ces:
Fi ndt he pa rts  whic h thei nstanc es were c re a ted fr o m.
Find t he  mod els which contain th e se parts.
Look  for a ll se c t ion s w ith materi al _name in thes e  p a r t s,a nd store allthe section N ame s asso ci ate d  withthisse c tio n
Look forallsectionAs signme n ts whic h  refere nces t hes e s ecti o nN am esUn d ere ac h o f  th ese sect io nA ssign ment s , t here  is  anassoc iated regionobj ectw hic h has  thename  ( as astring ) ofan  elementSet and  the  name ofa p ar t.Ge t all the el eme nts  from t his ele m ent Se t i nthis part.

Cleanu p: Us e the Py thon s e tob j ect to r em ove  any m ultip le r e fe rences t o thes am eelement .Multip ly  th e n umber of e lement s in thi s set by the numbero f identical p a rt i ns t ance s t hat refer t o th i s ma teri a linr ootAs sembl y. 
E . g., for some cae mo de l vari ablecalled model: 
model_par t _ r epeats =  {}m od e l_part_elemLab els =  {}

for i n stance i n mod el.rootA ssembly.i n s tances.v alu es( ):  p  =  instance.par t . name 
   m =ins tance.p art .mo del Nam e    try:       mo de l_ pa rt_ repea t s[(m, p) ]+=1      c ontinu e
   exc ep tK eyE rror:
   mo de l_ part _re pe ats[( m, p ) ] =  1

   # Get al l s e ctio ns  i n model 
    sectionN am es = []
  for  s inm d b.models [m].sections.values():      ifs.mat eria l == mate ria l_name : # materi al_nam e isal rea d y  know n 
         # Th i s  is  a va li d se ction -  search for sectio n  as signments
       #inp ar t  fo rt his s ection, and the n the asso ci a te d set
        secti onNames .appe n d(s.nam e)

    i f section Na mes:       labels  = []
       for sa in md b.mod els [m].pa rt s[p ].sec tionAs s ign ments :
         if sa .s ectionNa me in sectionNames:
             e set = sa. reg i on[ 0]
              labe ls= l abels  +[ e.lab el f o re i n  mdb. mode l s[m].part s [p ].s e t s[ eset].eleme n t s ]
      l abels= li st(set(labels))
      model_pa rt_e l e mLa bel s [(m, p) ] = labels

   e ls e : 

p or.cae_file if_you can. The following_gets it_from_an opened_cae_file. To thoroughly_get elements from_materials, you would do_something like the_following,_assuming you're starting your search in rootAssembly.instances:

Find the parts which the instances were created_from.
Find_the models_which_contain_these parts.
Look for all sections_with material_name in these parts,_and store_all the sectionNames associated with this section
Look for_all_sectionAssignments which references_these sectionNames
Under each of these sectionAssignments, there is an_associated region object which has the_name (as a_string)_of_an elementSet and the_name of a part. Get all_the elements from this elementSet in_this part.

Cleanup:

Use the Python set object to_remove any multiple references to the_same element.
Multiply the number of_elements in_this set by the number_of identical part_instances that_refer to this_material in rootAssembly.

E.g., for some cae_model variable called_model:
model_part_repeats = {}
model_part_elemLabels = {}

for instance_in_model.rootAssembly.instances.values():
  __p_= instance.part.name
_  _m_= instance.part.modelName
__  try:
   __   model_part_repeats[(m, p)] += 1
_   __  continue
 _  except KeyError:
 _     _model_part_repeats[(m, p)]_= 1

_   # Get all sections in model
  _ sectionNames = []
  _ for s in_mdb.models[m].sections.values():
 __  __ if_s.material == material_name: # material_name is already_known

 _     _   _#_This is a valid section -_search for section assignments
  _    ___  # in part_for this section, and then the_associated set
 _      __  sectionNames.append(s.name)

   _if_sectionNames:
     ___labels = []
  _     for_sa in mdb.models[m].parts[p].sectionAssignments:
      _  _  if sa.sectionName in_sectionNames:
__         _ _  eset_= sa.region[0]
        _      _labels = labels + [e.label for e in mdb.models[m].parts[p].sets[eset].elements]

  _     labels = list(set(labels))
_      _model_part_elemLabels[(m,p)] = labels

 __ else:
