Duplicate object finder/selecter..........

Is is possible to make a script that can find two identical objects in the same position but select only 1 of them?

I have 3000 trees to place and used replace in max to position a box at every location a tree should be. The only problem being that i started with a CAD drawing from an architect and they have duplicated the tree markers on top of each other so every location has two markers so the replace script has placed two boxes at every point.

So I'd like to select all 6000 of my boxes and run a script that would find the duplicates and select or deselect one copy at every location so I can easily delete the duplicates.

I hope that makes sense! I guess it could utilise the pivot point coordinates or something to gauge duplicates??

It would save me doing them one by one!

Here's hoping there is a genius amongst you clever people!

Cheers.

Comments

Comment viewing options

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

polycount check

Hej guys

there is a variable on the top checksamepoly, it has to be set to true in order to also test that those objects at the same location have the same polycount or not.

clearlistener()
t1 = timestamp()
selarray = selection as array
afaces = 0
bfaces = 0
checksamepoly = true
objpos = #()
theindexarray=#()
for i=1 to selarray.count do (
objpos[i] = selarray[i].pos
)
objpos2 = deepcopy objpos
objpos2 = makeUniqueArray objpos2
if objpos2.count != objpos.count then (
thenewsel =#()
theposarray =#()
for i=1 to selarray.count do (
for k=i+1 to selarray.count do (
if objpos[i] == objpos[k] do (
if (finditem theposarray objpos[i]) == 0 and (finditem thenewsel selarray[i]) == 0 do (
append thenewsel selarray[i]
append theposarray objpos[i]
)
if (finditem theposarray objpos[i]) != 0 and (finditem thenewsel selarray[i]) == 0 do (
try (
afaces = selarray[i].numfaces
) catch (
afaces = 0
)
append thenewsel selarray[i]
)
)
)
)
t2 = timestamp()
print ("sorting duplicates took " + ((t2-t1)/1000.0) as string + " milisecs")
if checksamepoly==true do (
for i=thenewsel.count to 1 by -1 do (
try (
afaces = thenewsel[i].numfaces
) catch (
afaces = 0
continue
)
	index = finditem selarray thenewsel[i]
	if index !=0 do (
	try (
		bfaces = selarray[index].numfaces
	) catch (
		bfaces = 0
		continue
	)
	)
	if afaces != bfaces and afaces!=0 and bfaces !=0 do (
		print "----------deleting item -------"
		deleteitem thenewsel i
	)
)
)
clearselection()
select thenewsel
) else (
messagebox "there are no duplicates or nthlicates xD"
)
actrask's picture

Thanks losbellos, worked

Thanks losbellos, worked perfectly!

losbellos's picture

at least 3-4 X faster, counts lot when dealing w many objects

t1 = timestamp()
selarray = selection as array
objpos = #()
theindexarray=#()
for i=1 to selarray.count do (
objpos[i] = selarray[i].pos
)

objpos2 =objpos
objpos2 = makeUniqueArray objpos2

if objpos2.count != objpos.count then (

thenewsel =#()
theposarray =#()

for i=1 to selarray.count do (
for k=i+1 to selarray.count do (
if objpos[i] == objpos[k] do (

if (finditem theposarray objpos[i]) == 0 and (finditem thenewsel selarray[i]) == 0 do (

append thenewsel selarray[i]
append theposarray objpos[i]

)

if (finditem theposarray objpos[i]) != 0 and (finditem thenewsel selarray[i]) == 0 do (

append thenewsel selarray[i]

)
)
)
)

t2 = timestamp()
print ("sorting duplicates took " + ((t2-t1)/1000.0) as string + " milisecs")

clearselection()
select thenewsel

) else (
messagebox "there are no duplicates or nthlicates xD"
)

robox's picture

Hi Losbellos, cool script and

Hi Losbellos,

cool script and very fast compared to other scripts i tried so far.

I tried this on a heavy scene but unfortunately the script also selects objects, which aren`t
"real" duplicates. Is it possible to add some code to also check and compare the polycount for the founded duplicates....so it is sure that these are real duplicates ?

Thanks for your help.

Robin

losbellos's picture

updated

updated

Stefan.Co's picture

different z position objects

Hi losbellos,

is it possible to make a little change in this script?
I need to select objects that have the same position in x and y axis, but they have different z position.
Thank you.

Stefan

ashishsharma's picture

Thanx works for me

nice and clean boss...
just select all objects and run this.. whollah
Thank you

AJs

Anubis's picture

Try makeUniqueArray function

Try makeUniqueArray function (it's available in Max 2008 and higher)

-- 1. select your objects end run next line to collect objs.position
posArray = for i in selection collect i.pos
-- 2. remove dublicated items
posArray = makeUniqueArray posArray
-- 3. filter out just 1 obj per pos
clearArray = #()
for i = 1 to posArray.count do (
	for obj in selection do (
		if obj.pos == posArray[i] do clearArray[i] = obj
	)
)
-- 4. select them
select clearArray

my recent MAXScripts RSS (archive here)

sergo's picture

Thank you Anubis! :)

Thank you Anubis! :)

Comment viewing options

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