ScriptSpot

Forum topic · Scripts Wanted

Remove duplicated geometries?

By brianuuu · 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 · 2015-10-07

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

barigazy · 2015-10-07

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

asymptote · 2015-10-12

Oh you f***ing beauty !!

I've been searching for a way to do this for weeks, your pivot comment was the solution, after centering the pivot on all the dupe splines it works perfectly!

http://www.screencast.com/t/wRWEHzc7Dxh

Many thanks!

GushingDizzy · 2015-10-01

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.

barigazy · 2015-10-02

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

barigazy · 2013-02-15

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]

)
)

brianuuu · 2013-02-15

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.?

barigazy · 2013-02-15

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

brianuuu · 2013-02-15

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

barigazy · 2013-02-15

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

brianuuu · 2013-02-15

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!

GushingDizzy · 2015-10-02

Thank you for helping. I'm afraid nothing happens when I run the script though. :o/

barigazy · 2015-10-02

First run the function then run one of theses two codes below

double_select_tool

barigazy · 2015-10-02

Try with this tool

Attachments