Delete Duplicates (same polycount)

Hi all,

I want to remove all duplicate objects from a scene, I want to find the duplicates by comparing polycount of all objects.

When I've found the polycount of each object i want to group all objects with same polycount together and delete all but 1 of them. Should be simple, i am having trouble building an array with all duplicate objects in it though...

My code is attached below, throws no errors but doesn't add any objects to #(duplicates) array. My code does determine polycount for all objects and puts it in objs_info array.

Any help will be greatly appreciated, thank you!

AttachmentSize
delete_duplicates_4.ms1.08 KB

Comments

Comment viewing options

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

.

I don't know why you want first to group the objects with the same polycount and then to delete all but one, but...

(
	clearselection()
	select geometry
	deselect helpers
	objsArr = selection as array
 
	objsByFaceCountArr = #()
	i = 0
	while objsArr.count != 0 do
	(
		i += 1
		tmpArr = #(objsArr[i])
 
		facesNum1 = (getPolygonCount objsArr[i])[1]
		deleteItem objsArr i
		for j = objsArr.count to 1 by -1 do
		(
			facesNum2 = (getPolygonCount objsArr[j])[1]
			if facesNum1 == facesNum2 do
			(
				append tmpArr objsArr[j]
				deleteItem objsArr j
			)			
		)
		append objsByFaceCountArr tmpArr
	)
 
	--	"group the objects"
	for arr in objsByFaceCountArr do 
	(
		group arr
	)
 
	--	"delete all but 1"
	for arr in objsByFaceCountArr do
	(
		delete (for i = 2 to arr.count collect arr[i])
	)
 
)

Comment viewing options

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