ScriptSpot home

Forum topic · General Scripting

Select only vertical faces of the EditableMesh object

By harumscarum · 2023-06-05

Description

Is there any solution to select vertical faces of the Editable Mesh object?

Comments (3)
harumscarum

ChatGPT did the job, however it do not know how to select faces, may only delete it
and it is slow

-- Assuming you have the EditableMesh object selected
obj = selection[1]

-- Get the number of faces
numFaces = obj.numFaces

-- Iterate through faces in reverse order
for f = numFaces to 1 by -1 do
(
    -- Get the normal of the face
    faceNormal = getFaceNormal obj f

    -- Check if the face is vertical
    if dot faceNormal [0, 0, 1] < 0.99 do
    (
        -- Delete the face
        deleteFace obj f
    )
)

.

The code you have will delete bottom faces of a box primitive converted to Editable Mesh.


(
	obj = selection[1]	
	if classOf obj == Editable_mesh do
	(
		vertFacesBA = #{}
		numFaces = obj.numFaces
		for f = 1 to numFaces where ( dot (fNormal = getFaceNormal obj f) [0, 0, 1] < 0.99 ) and (dot fNormal [0,0,1] > -0.99) do vertFacesBA[f] = f		
		if vertFacesBA.numberset != 0 then
		(
			select obj
			max modify mode
			subobjectlevel = 3
			setFaceSelection obj vertFacesBA
		)
		else
			messagebox "No vertical faces has been found" title:""
	)
)
Reply to miauu
Panteleev Sergey

.

it might be faster to use abs to make just a single value comparison
like that:


...
for f = 1 to numFaces where (abs (dot (getFaceNormal obj f) z_axis)) < 0.99 do vertFacesBA[f] = true
...