Need help to write the code on Python (pymxs) or Maxscript which can allow to select all objects with same normals direction in 3Ds Msx.
I have this base function, but can't achieve needed result.
import pymxs
def select_same_normal_objects(normal_dir):
selection_set = []
geometry_objects = list(rt.execute('''for o in geometry where (isKindOf o GeometryClass and canConvertTo o Editable_Mesh) collect o'''))
for obj in geometry_objects:
if obj.getNormal() == normal_dir:
selection_set.append(obj)
return selection_set
Based on the comments above, specifically this statement
I have to select all faces of objects whose normals look in one direction
you could do something like:
def select_same_normal_objects(normal_dir):
selection_dict = dict()
geometry_objects = list(rt.execute("for o in geometry where (isKindOf o GeometryClass and canConvertTo o Editable_Mesh) collect o"))
for obj in geometry_objects:
# get a "get face normal" function for the obj type
getFaceNormal = None
if str(rt.classof(obj)) == 'Editable_Poly':
getFaceNormal = pymxs.runtime.polyop.getFaceNormal
elif str(rt.classof(obj)) == 'Editable_mesh':
getFaceNormal = pymxs.runtime.getFaceNormal
else:
pass # implement getFaceNormal() for other object types
if getFaceNormal:
for i in range(pymxs.runtime.getNumFaces(obj)):
# careful that maxscript has one-based indices
normal = getFaceNormal(obj, i+1)
if normal == normal_dir:
if obj not in selection_dict:
selection_dict[obj] = [i+1]
else:
selection_dict[obj].append(i+1)
return selection_dict
This returns you a dictionary with all found faces per object
{
obj1: [1,2,4,...],
obj2: [5,11,...],
...
}