First off, instead ofselect objectsfor obj in selection doyou could writefor obj in objects doWhy do you want to select them?

3500 objects is not that much.Is it worth spending hours optimizing if it saves only a handful of seconds? How long is it taking right now?

Your nested ifs at the end look weird.You're adding a material only if the object's name contains "Wall" and "Tile" and "brick".Is that correct?

read 422 times3/8/2016 1:02:16 PM (last edit: 3/8/2016 1:09:05 PM)

jpedleham

Fair point on the selection3500 is the very minimum. i suppose realistically it could be upwards of 7500 objects but its a process that we in my team have to do weekly. At the moment it freezes up and takes about 10 minutes.

The nested ifs seem to work but i dont know how to use multiple arguments any other way.at the moment it checks if its a wall then looks if it needs a tile texture and then if its brickbonded tile. later on there will be other types of tile and wall finishes to add to that statement.Im adding a materialID (based on an existing multisub) to the object if it includes certain stuff yeah. Its for large scale revit buildings that we look at in realtime software and the materials are always the same so it seems a waste of time manually processing the entire building every time.

read 407 times3/8/2016 4:34:44 PM (last edit: 3/8/2016 4:38:18 PM)

Garp

There isn't much room for optimization, I'm afraid.From your code I gather that the substrings are not at a fixed position in the names. If they were, you could sort things first and then go much faster.

One thing you could do that 'might' speed things a little is to group operations. Check all the patterns first, then assign all the materials. This would require measuring, as it might end up making no difference or even slowing things down.

You could store your substrings in an array and have a second array of identical size storing the corresponding material IDs. For some index i, you would have matIDs[i] corresponding to patterns[i].Then you'd have yet another array that you'd fill up as you traverse the objects with the appropriate IDs, again with matching indices. And then a second traversal were you assign the materials.This would separate the pattern matching part from the material additions.

If it's not faster, at least it should make your code clearer and easier to extend with more patterns and material IDs.

read 399 times3/8/2016 5:20:10 PM (last edit: 3/8/2016 5:24:41 PM)

gogodr

Use If Else otherwise it will keep testing on the same object over and over again even though you already did what you wanted

Hello there

beautiful ;3

read 391 times3/8/2016 5:56:19 PM (last edit: 3/8/2016 5:56:19 PM)

jpedleham

^Good call.

I assume its

If obj.name pattern:"*Wall*" do

ACTION

Else

ACTION

Else

Also garp that sounds like a decent suggestion but this code might need to be edited in the future by someone else and i think having an easily understandable bit of code that can just be copied and pasted to add another value might be slightly easier to grasp.

The substrings unfortunately could be anywhere within the name as revit naming gets quite messy containing things like dimensions, material, front finish, manufacturer etc so its a long shot that they all name things even with the right words.

read 385 times3/8/2016 8:01:33 PM (last edit: 3/8/2016 8:01:33 PM)

jpedleham

I tried the else statement but couldnt get it working, is there something i can put at the end of each if statement that will tell max to go to the next object?

So once it has found its material it doesnt keep looking?

EDIT: Nevermind i got it running in under two minutes so thats pretty quick on a revit building with 12k objects!

read 372 times3/9/2016 10:34:08 AM (last edit: 3/9/2016 12:59:19 PM)

jpedleham

Thanks for the help guys!

read 367 times3/9/2016 1:17:48 PM (last edit: 3/9/2016 1:39:37 PM)

jpedleham

Im getting a weird problem where the modifier panel becomes completely disabled. no buttons work and when i select an object no name appears but it appears in the other panels. Any ideas?