Select/attach Near

Hi all, I was wondering if anyone could create a script to select objects within a certain distance of the selection.

Use case: I have hundreds of thousands of objects most of them should be one big object but at the moment all their components are detached. I would like to be able to select the main body and tell max to attach/select all geometry that is either overlapping/near my selection, this should be able to work with multiple selections.

So for example.
Say I have 50 cars, each car is in it's individual component such as bolts, doors, windows etc...

I would like to select the the main body of the car and the script would then give me the option to select/attach all objects that are either near or overlapping the main body, I suppose I would have to enter a value for the "near" part.

I have no idea how difficult this is to do but this would make my life a billion times easier and I imagine many others would use it as well.

Thanks very much to anyone who can help or give me advice.

Cheers.

Comments

Comment viewing options

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

Thanks

Thanks very much Sable, I'll give it a shot and get back to you.

Cheers.

sable806's picture

Working code

Hello, i've been writing a code that should work for what you need. I've tested it on max 2016 and it works.

Feel free to test it and give me feedback, the overlapping feature is for now just a bounding box intersection so it will be very approximative, but if you need more precise overlapping feature you are welcome to ask.

AttachmentSize
smartattach.mcr 1.84 KB
Reapergrim's picture

Script Review

Hi Sable, This script is simply amazing, thanks for all the work you put into it.

I hope you don't mind but here are a few things that I think would definitely improve it.

1. faster attach Algorithm built in (I can do this manually of course by using the select function you created but having it built in would definitely save time) the Cluster attach seems to work very well for attaching thousands of objects. I found the script for cluster attach here

https://davewortley.wordpress.com/2017/01/26/optimising-scenes-by-reduci...

2. Would it be possible to add a loop command, so right now the script does exactly what I asked for, which again I must say thank you very much. When I select an object and say attach overlapping I would like to run that in a loop, so after it attaches the first overlapping, it would then start attaching the next overlapping with the newly created mesh.

3. It seems that it is still selecting objects in the scene that are hidden or isolated, would it be possible to make it work only on the visible objects in the scene and ignore any hidden ones?

4. A check box that has overlapping geometry instead of overlapping bounding box would be most useful when it comes to the loop function and in general.

I hope you understand what I mean haha, but again really amazing script, it's going to save me loads of time :)

sable806's picture

Retakes

Hello, i'm glad it worked the way you wanted to !

Concerning what you asked :

1. I implemented the algorithm of Dave Wortley and i run the script to attach 700 hundreds objects together and using the Dave's algorithm won an extra 2s, i went from 34s with my script to 32s with this algorithm so i'm keeping Dave's one. Maybe on really heavy scenes it will gain much more.

2. Looping is not a bad idea but i think you can come very quickly to attach your all scene together. I can implement it but maybe it could be good to define a lopp numbers, like when the first round finished it goes for a new round of overlapping until it reaches the desired loo number. The Only On Visible objects will make this features works nicely too.

4. I make the fourth point before 3 cause it's directly related to point 2. I've never done that kind of script before but i'm sure it's possible, i'll check this out, and if it's possible to make then i'll do it. Implementing this could make the point 2 feature interesting cause i think it will definitely works better with geometry overlapping instead of bounding box.

3. I implemented the on Visible only algorithm.

If you need more feel free to ask, it's a nice idea you brought and i'm gonan use that script for sure !

AttachmentSize
smartattach_v1.1.mcr 2.11 KB
Reapergrim's picture

Brilliant!!

That's absolutely fantastic, thanks!

Yes, I think your idea of setting the loop amount is definitely valid as it might start attaching too many objects.

I think the bounding box works well for the first few rounds, the only problem is that when it attaches objects that are diagonal to each other t puts a massive bounding box around it, which means the next attach will have a much bigger area than what you would like, which is why I think the geometry attach is the best option.

Thanks again, I'm eager to see what you come up with.

Cheers.

Comment viewing options

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