Optimizing code
Hello
I am trying to optimize my code. Need to select a object class in a specific layer.
I am working with code that consists of two stages:
1: Selecting all objects in the layer.
2: Selecting splines from selected objects.
( local allNodes = #(), theNodes = #() for n in selection do (n.layer.nodes &theNodes ; join allNodes theNodes) select allNodes select(for obj in selection where classof obj.baseObject==line collect obj) )
I am looking for a way to exclude the first part while keeping the result.
Any ideas on how to do this? Any help appreciated.
Comments
.
Tools and Scripts for Autodesk 3dsMax
Many thanks. Ideally!
Many thanks. Ideally!
.
What if selection contains several nodes that belong to the same layer?
You'll have n^2 results in allNodes array if all selected nodes are lines and belong to the same layer
>>> 10000
just use "appendIfUnique"
just use "appendIfUnique" instead of "append"
Youtube, Gumroad
.
it doesn't solve n^2 issue at all
LayerManager.deleteLayerByNam
Youtube, Gumroad
;)
>>> 100
iterations: 10000 -- n^2 is still there ;)
sometimes using try()catch()
sometimes using try()catch() is better than wasting time in solving all cases with errors
same as your case cuz it take seconds ;)
but if u care about the iterations go ahead :)
Youtube, Gumroad
.
try catch? but how does it help you here?
Just imagine a user having 10.000 lines in a single layer. Possible? Easy. Still seconds?
10.000^2 is a pretty large amount of work. I bet max will hang for a long long time or just eat quite a lot of ram and crash after that.
I'd save a scene before any attempt to run a script with n^2 solution. ;)
That's why I posted the example to demonstrate the issue.
If it isn't a problem, ok.
LayerManager.deleteLayerByNam
Youtube, Gumroad