How to get Faces Aligned with a Direction and Located at the "Top" of the Body
This example is how to get faces aligned with a direction and also located on the "top" of the body in that direction. You can see the type of faces in the image, aligned with the Z Direction. Notice one of the 3 blocks does not have a face selected because it it not oriented in line with the Z axis.
This is useful often when wanting to select these faces as cutters or to pull for some reason.
An example SC geometry file with script group is attached.
Comments
-
Hi
I want to select faces by specific directions.So, I thinked i can use your method. But when i open and run your、 I had an error "attribute 'V20' of 'namespace#' object is read-only".Do you have any solution?
Also, I read your script. I think your write about materials. How did you select "Top" face? If you can, Could you teach the method?
BR
1 -
@Mike.Thompson Can you taka a look into Hashimoro-san's question?
0 -
@Takahiro Yamaguchi , I have updated the original post to correct the attachment. The code is also posted below:
# Python Script, API Version = V20 """ Get the top face in the Z Direction """ UserDirection = Direction.DirZ DotTolerance = 0.9999 TopFaces=[] for B in GetRootPart().GetAllBodies(): ZFaces = [] for F in B.Faces: Norm = F.GetFaceNormal(0,0) Dot = Vector.Dot(Norm.UnitVector, UserDirection.UnitVector) if Dot > DotTolerance: Z = F.GetFacePoint(0,0)[2] ZFaces.append([F,Z]) if len(ZFaces)>0: ZFaces.sort(key=lambda V: V[1]) TopFaces.append(ZFaces[-1][0]) Selection.Create(TopFaces).SetActive()
1 -
@Mike.Thompson Thank you! It was works fine to me.
0 -
@Mike.Thompson If I want to select the X direction, what should I change?
0 -
At the top of the script is: UserDirection = Direction.DirZ
You can change this to UserDirection = Direction.DirX, or you can specify any arbitrary direction with XYZ like Direction.Create(0.5,0.8,1.596)
0