Selecting top faces only of multiple objects

Hi,

I have allot of box shaped objects (buildings) in a scene and I want to select only top faces/polygons (roofs) in order to texture those top faces only.

Is there a little script I can write to make all objects in the scene have their top faces/polygons only selected?

Thanks

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Claviateur's picture

Thanks again for the time you

Thanks again for the time you spent on the script :) I tried it for 1 object and it works perfrectly but for many independant objects in the scene it did not function unfortunately.

What I did is select all objects and run the script then I hit 4 but I see no selection being done?

Thanks !

barigazy's picture

You need to select single

You need to select single object and then press 4.

barigazy

Claviateur's picture

Yes I did select a single

Yes I did select a single object and pressed 4 but only the roof of that object was selected and not all the other objects roofs

Is there anything I need to change in the script?

Thanks

barigazy's picture

test object + *.ms

Here also script and test file (*.obj and *.ms)
You welcome!

:)

AttachmentSize
select_obj_tops.rar 2.53 KB

barigazy

barigazy's picture

This is your script

Options:
"Angle Threshold spinner" -- angle beetven face normal and Z-axis
"Max Height" -- select only faces which center position is > Max Height

try(DestroyDialog ::bgaRoll)catch()
rollout bgaRoll "selectObjTops"
(
	local poGFN = polyop.getFaceNormal, poGFC = polyop.getFaceCenter
	spinner spn_ang "Angle Threshold:" range:[0,360,5] pos:[5,5]
	spinner spn_heig "Max Height:        " range:[0,360,0] pos:[4,25]
	button btn "Select T O P S!" width:150 pos:[5,45]
 
	fn getDirAngle v1 v2 = (acos(dot (normalize v1) (normalize v2)))
	fn getTops obj ang: elev: =
	(
		local topFaces = #{}, norm = [0,0,1]
		if isKindOf obj Editable_Mesh do (poGFN = getFaceNormal ; poGFC = meshop.getFaceCenter) 
		for f = 1 to obj.numfaces where getDirAngle norm (poGFN obj f) <= ang do
		(
			if abs ((poGFC obj f).z-obj.min.z) >= elev do append topFaces f
		) ; obj.selectedfaces = topFaces	
	)
	on btn pressed do
	(
		if selection.count > 0 do
		(
			for obj in selection where isKindOf obj Editable_Poly or isKindOf obj Editable_Mesh do 
				getTops obj ang:(spn_ang.value) elev:(spn_heig.value)
		)
	)
)
createDialog bgaRoll 160 70 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

barigazy's picture

This is a test code.Select

This is a test code.Select all objects (E-Poly or E-Mesh) and run the code.
Then go and select any object and press "4" on keyboard (face sub-object mode)

for o in selection where isKindOf o Editable_Poly or isKindOf o Editable_Mesh do
(
	topFaces = #{}
	gfc = if isKindOf o Editable_Poly then polyop.getFaceCenter else meshop.getFaceCenter
	for f = 1 to o.numfaces do
	(
		if (gfc o f).z == o.max.z do append topFaces f 
	)
	o.selectedfaces = topFaces
)

barigazy

barigazy's picture

Attach a screenshot to see

Attach a screenshot to see with what kind of objects you have

barigazy

Claviateur's picture

Thanks so much, I tried the

Thanks so much, I tried the script as you mentioned but did not get the selections of all top faces. I followed your tutorial by selecting all objects in the scene, run the script, then select 1 object and I hit 4. But only the selected object top face/roof was selected and not all of the objects top faces.

Here is a screen capture of a portion of the objects (buildings) that I need to select the roofs (top faces) only

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.