Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Python: How to select all instances at once? 1

Status
Not open for further replies.

dfgsdfgfd

Mechanical
Sep 30, 2015
37
Hi everyone,

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

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

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

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

Thanks very much!
 
Replies continue below

Recommended for you

Just collect all faces with two simple for-loops. The first over all instances and the second over all faces of each instance.
 
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.
 
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
 
This is in the Assembly module , what if I want to select the faces of a part in the part module with getByBoundingBox ??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor