×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Python: How to select all instances at once?

Python: How to select all instances at once?

Python: How to select all instances at once?

(OP)
Hi everyone,

Using Python, I'm trying to select the faces of all instances with getByBoundingBox:

CODE --> Python

faces = a.rootAssembly.instances['Part-1'].faces.getByBoundingBox(...)+        a.rootAssembly.instances['Part-2'].faces.getByBoundingBox(...)+        a.rootAssembly.instances['Part-3'].faces.getByBoundingBox(...)+        ... 

This is very tedious for many instances. Unfortunately, rootAssembly doesn't have the attribute faces, so I can't use

CODE --> Python

faces = a.rootAssembly.faces.getByBoundingBox(...) 

Is there an alternative way to select all faces with a bounding box?

Thanks very much!

RE: Python: How to select all instances at once?

Just collect all faces with two simple for-loops. The first over all instances and the second over all faces of each instance.

RE: Python: How to select all instances at once?

(OP)
Thanks very much for your response. When I try to do that, I get an error saying "TypeError: 'Repository' object is not iterable"

My code is:

CODE

edges1 = [] 
for i in a.rootAssembly.instances:
    edges1.append(i.edges.getByBoundingBox(-1,-1,-1,1,1,1))] 

_____________________________________________________________________________________
Edit:
I think I found the solution (maybe there's a simpler one?):

CODE

edges1 = [] 
for i in a.rootAssembly.instances.keys():
    edges1.append(a.rootAssembly.instances[i].edges.getByBoundingBox(-1,-1,-1,1,1,1))] 


_____________________________________________________________________________________
Edit2:
I have to do the second iteration, as you mentioned, as well:

CODE

edges1 = [] 
for i in a.rootAssembly.instances.keys():
    for ii in a.rootAssembly.instances[i].edges.getByBoundingBox(-1,-1,-1,1,1,1):
        edges1.append(ii) 

_____________________________________________________________________________________
Edit3:
I give up.. the above works for the edges, but not for faces. When I do it with faces, i get the error "TypeError: faces; found tuple, expecting GeomSequence"

Any help is appreciated, please.

RE: Python: How to select all instances at once?

That below is what I've ment. With these simple loops you cycle over all faces and can do whatever you like with it.

CODE -->

a = mdb.models['Model-1'].rootAssembly

for iname in a.instances.keys():
    for xface in a.instances[iname].faces:
        print iname, xface.index 

RE: Python: How to select all instances at once?

This is in the Assembly module , what if I want to select the faces of a part in the part module with getByBoundingBox ??

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources