Notifications
Clear all

[Closed] Get Tri-count instead of Polycount for MaxScript?

Hi everyone! I’m new to CGSociety and new to MaxScript as well. I was asked as an exercise to create a script/rollout that would select all objects in the scene that were above any given tri-count (ex: if I set the limit to “500”, the script would automatically select any objects above a tri-count of 500 by clicking a button in a rollout).

I have successfully completed the script – kind of. The script only pays attention to the “polycount” (the quad count) as opposed to referencing the tri-count. Since this script is meant to work with a game dev pipeline (Unity), the tri-count is the only value I care about.

Is there a way I can tweak my script to select objects based on their tri-counts and not based on their quads? Any help would be greatly appreciated. My script is as follows (be gentle, I’m new!):

EDIT: Fixed a formatting issue.

-- Clear current selection
clearSelection()

--Rollout that w
rollout TriTracker "Tri-Tracker"
(
	--Creates the "Tri-Count Range" spinner which will select objects with a tri-count HIGHER than the value in the "range" parameter
	spinner tri_range "Tri-Count Range: " range:[1,10000000,0] type:#integer
	--Creates the "Search Scene" button in the rollout
	button search "Search Scene"
	
	--When the "Search Scene" button is pressed, the code below will run
	on search pressed do
	(
		--Creates a variable which stores all geometry in the scene into an array to be searched
		allobjs = geometry as array
		
		--For loop that checks every individual object in the scene based on the "allobjs" variable previously created
		for i = 1 to allobjs.count do
		(
			-- Creates a variable "xp" that reads the total tri-count of every object in the scene
			xp = getPolygonCount allobjs[i]
			-- If statement checking to see if each object's tri-count is less than the "Tri-Count Range" value from the rollout
			if xp[1] > (tri_range.value) then 
			(
				--Selects the object if the above statement is true based on "i"
				selectmore allobjs[i]
			)
		)
	)
	
)
--Generates the pop-up panel of the "TriTracker" rollout to appear
createDialog TriTracker width:200
4 Replies

According to the documentation, getPolygonCount() should return the number of triangles, but it doesn’t. So you could use the mesh property of the object and get the number of faces from there.

$.mesh.numfaces

Also, instead of using the selectMore() function, you might want to collect all the nodes in an array and select them at once at the end, as selectMore() is slower. Something like:

rollout TriTracker "Tri-Tracker"
     (
     	spinner tri_range "Tri-Count Range: " range:[1,10000000,0] type:#integer
     	button search "Search Scene"
     	
     	on search pressed do
     	(
  		clearSelection()
  		range = tri_range.value
     		
     		nodes = for node in geometry where node.mesh.numfaces > range collect node
     		select nodes
     		
     		-- or
     		-- select (for node in geometry where node.mesh.numfaces > range collect node)
     	)
    )
     createDialog TriTracker width:200
1 Reply
(@psybertyger)
Joined: 10 months ago

Posts: 0

This works perfectly! Now I just need to figure out how to make the selection update based solely on the spinner value rather than a button and I’ll be good to go. Thank you so much!

there is GetTriMeshFaceCount…

(GetTriMeshFaceCount selection[1])[1]
rollout TriTracker "Tri-Tracker"
  (
  	spinner tri_range "Tri-Count Range: " range:[1,10000000,0] type:#integer
  	
  	on tri_range changed val do
  	(
  		-- Make sure you are not in Modify Panel
  		max create mode
  		
  		nodes = for node in geometry where node.mesh.numfaces > val collect node
  		if nodes.count > 0 then select nodes else clearselection()
  	)
  )
  createDialog TriTracker width:200