PDA

View Full Version : Selecting all faces in a given area


CharacterStudy
10-12-2011, 07:29 PM
I'm a beginner at scripting (or anything to do with code in general), so please don't be to scorn full if I am missing some obvious steps :)

I'm trying to figure out how to write a little script that will select all the faces in an area a certain distance from a given point.

For the sake of the script, lets argue that there is a 2.2 height, 1.6 wide box with its axis centered in world space. I would like to select all (or as many as possible) faces in the area.

selectType -sf 1;
polySelectConstraint -m 2 -t 8 -d 1 -db 0 0.8 -dp 0 0 0;


I'm not sure what I am missing in this piece or if I am on the wrong track. If anyone has any advise I would be very appreciative.


Thanks in advance.

bendingiscool
10-13-2011, 02:22 PM
Hey,

I did something similar, though quick and nasty, to this yesterday. Make a cube and a sphere and it will select the sphere's faces that are inside the cube.

import maya.cmds as cmds

bbox = cmds.xform("pCube1",q=True,bb=True)

insideFaces = []
for i in range(cmds.polyEvaluate("pSphere1",f=True)):
facePos = cmds.xform("pSphere1.f[%d]" % (i),q=True,ws=True,t=True)
if facePos[0] > bbox[0] and facePos[0] < bbox[3]:
if facePos[1] > bbox[1] and facePos[1] < bbox[4]:
if facePos[2] > bbox[2] and facePos[2] < bbox[5]:
insideFaces.append("pSphere1.f[%d]" % (i))

cmds.select(insideFaces)

cheers,
Chris

CharacterStudy
10-13-2011, 08:35 PM
Nice, that actually works much better for me. I have geometry in place to represent the area of each selection which I can use as the framework to actually do the selection. Two birds with one rock (edit: ...errr...stone). ;)

I'll toy around with this and see what I can learn from it.

Thank you :)

CGTalk Moderation
10-13-2011, 08:35 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.