Compute surface normal of face

Member, Employee Posts: 11
Name Dropper First Comment
✭✭✭
edited July 2023 in 3D Design

Hello all, 

I have a faceted body as shown below and I would like to capture the top faces, bottom faces and cylindrical faces separately and assign named selections using scripting. There are hundreds of such fins and to manually assign named selections is very tedious and also each fin has different dimensions, but they are all cylindrical in shape. 


I was looking to compute the surface normal of all faces, put the faces whose normal is facing +Z in one bin and assign a named selection, do the same for -Z and for the rest assign another named selection.

Anyone has a better idea on scripting this? If computing the surface normal is the best option, can you please let me know the script to compute the normal? 

Thank you for your help. 

Regards,

Rahul

Comments

  • Moderator, Employee Posts: 131
    100 Comments 25 Likes Second Anniversary 5 Answers
    ✭✭✭✭

    @RK

    Here is the script you can use for the same.

    1. # Python Script, API Version = V23
    2. meshes = GetRootPart().Meshes
    3. z_vector = Vector.Create(0,0,1)
    4. MeshTopoList = []
    5. for mesh in meshes:
    6.     for face in mesh.Shape.Faces:
    7.         normal = face.Normal.UnitVector
    8.         dot_product = Vector.Dot(z_vector,normal)
    9.         if dot_product > 0.9: #+ve z
    10.             MeshTopoList.append(mesh.GetDesignMeshTopology(face))
    11.             
    12. if len(MeshTopoList) > 0:
    13.     Selection.Create(MeshTopoList).CreateAGroup("PositiveZ_Fins")


  • Member, Employee Posts: 11
    Name Dropper First Comment
    ✭✭✭

    Hi Rajesh,

    Thank you very much, this works perfect!

    Regards,

    Rahul

Welcome!

It looks like you're new here. Sign in or register to get started.