Why?
Script example:
(16000 iteration in for loop)
startTime =
timeStamp()
firstSelectedBaseobject =
selection[1].baseobject
edgesBetweenMatIDs = #()
edgesNumber =
polyOp.getNumEdges firstSelectedBaseobject
getFacesUsingEdge = polyOp.getFacesUsingEdge --I'm cashing function in variable but performance isn't changing for edge = 1 to edgesNumber do
(
neighbourFaces = (getFacesUsingEdge firstSelectedBaseobject #(edge)) as array
if neighbourFaces.count == 2 do
(
matID1 =
polyOp.getFaceMatID firstSelectedBaseobject neighbourFaces[1]
matID2 =
polyOp.getFaceMatID firstSelectedBaseobject neighbourFaces[2]
if matID1 != matID2 then
(
append edgesBetweenMatIDs edge
)
)
)
polyOp.setEdgeSelection firstSelectedBaseobject edgesBetweenMatIDs
format "Time %s\n\n" ((timeStamp() - startTime) / 1000.0)
How to optimize polyOp.getFacesUsingEdge?
Replies
I'm not sure you're actually caching the result of that function. I think it still has to work out the conversion based on the current selection which is what will take the time. You would presumably need to pass in the object and edge selection when you declare getFacesUsingEdge in order to see any benefit and that won't work in the context you're using it.
I suspect its the per edge iteration that's taking the time rather than than the selection conversion though. if speed is important I'd suggest rethinking how you gather the information you need.
I took a pass on the script it went from 1.08 seconds to 0.04 seconds. The basic ideas to make things faster (with MaxScript) are avoid using memory in loops, and avoid converting data types especially in loops.