ScriptSpot home

Forum topic · Scripts Wanted

Remove duplicated geometries?

By Brian · 2013-02-15

Description

I have a map, however some of the geometries are duplicated, how to remove them?

They have the following characteristic:
1. same pivot
2. same texture

so basically everything is the same, thanks!

Comments (14)
asymptote

Nice one Barigazy, very useful, can this be made to work on duplicate splines easily ?

Reply to asymptote
Branko Živković

Only if splines share same pivot ei. positions in the scene.
Works on any kind of max object.

GushingDizzy

Hello. Sorry to dig up an old thread. I thought perhaps this code would work for me but I got the message:
-- Syntax error: at ), expected
-- In line: )

Here's my situation: A couple CAD files I've imported (into Max 2016, which retains instancing) have between 16k and 20k objects in them. Hundreds (maybe thousands) of these objects are duplicate instances that I don't need, and cause rendering problems. So I need a script that will delete duplicate instances of objects. However, to make sure all my instanced nuts and bolts remain, the script should only delete the extra objects that have the same pivot point.

It would probably be doable by hand if the objects had proper names, but most of these objects came in with the exact same names as hundreds of other objects.

Thanks. I hope you can help.

Reply to GushingDizzy
Branko Živković

Try this function
BTW you can use "mode" argument as:
- #originals (when you want to select first ei. original objects)
- #duplicates (to select all object that have same position as original objects)
Also when you want to delete selected object use argument "del"


fn doubleSelect mode: del:off =
(
	local objArr = objects as array
	local uniqueObjs = dataPair node:#() hash:#()
	for o in objArr where (findItem uniqueObjs.hash (e = gethashvalue o.pos 0)) == 0 do (append uniqueObjs.hash e ; append uniqueObjs.node o)
	case mode of 
	(
		#originals: (select uniqueObjs.node)
		#duplicates: (select uniqueObjs.node ; max select invert)
	)
	if del do delete selection
)

EXAMPLE

-- select only originals and don't delete
doubleSelect mode:#originals del:off
-- select duplicates and delete
doubleSelect mode:#duplicates del:on

Branko Živković

This is untested code just try and tell my how works for you

geoArr = geometry as array
while geoArr.count != 1 do
(
lastObj = geoArr[geoArr.count]
idxArr = #() ; cnt = #() ; objArr = #()
for o = geoArr.count-1 to 1 by -1 where lastObj.pos = geoArr[o].pos and \
lastObj.material = geoArr[o].material do (append idxArr o ; append objArr geoArr[o]
if idxArr.count != 0 do
(
delete objArr
cnt = append idxArr geoArr.count
for i = 1 to cnt.count do deleteItem geoArr idxArr[i]

)
)

Ops sorry, the material is different (but the texture is the same just the directory is different), is it possible to use pivot or faces or vertex count etc.?

Reply to Branko Živković
Branko Živković

U can use the next
--check distance
--check bounding box
--check ClassName
--check transform
--check modifiers count etc.
Try by yourself and show me your result.
Just u need to change one line of my code

it says unexpected end-of-script
btw how do I change "material" to other things? I dunno anything about maxscript sorry ;(

Reply to Brian
Branko Živković

Now should work
If your object share same position in world space (overlaping) then will be deleted.


geoArr = geometry as array
while geoArr.count > 0 do
(
	lastObj = geoArr[geoArr.count]
	idxArr = #() ; objArr = #()
	for o = geoArr.count-1 to 1 by -1 where distance lastObj.pos geoArr[o].pos < 0.01 do (append idxArr o ; append objArr geoArr[o])
	if idxArr.count != 0 do
	(
		delete objArr
		insertItem geoArr.count idxArr 1
		for i = 1 to idxArr.count do deleteItem geoArr idxArr[i]
	)
)

Line that you need to change is
... where distance lastObj.pos geoArr[o].pos < 0.01 ...
If you want to learn more you need to start with MaxScript help

for some reason the max just stop working, I've 3000 objects and I guess there are about 500 overlapping geometries.
Then I try if it works on 11 objects only, it still stop working!