[Closed] speedup simple code
I need cod to detect any kind of animation(metarial, transformation, modyfier animation etc… ) key in selection.
I created code which is able to do it however is very, very slow. Can anybody help to speed it up?
here is code:
with undo off
(
disableSceneRedraw()
global allanimationobjec=#()
allanimationobjecinfo=""
allanimationobjec=#()
if selection.count>0 then
(
temporaryobjlist=selection as array
for obj in selection do
(
windows.processPostedMessages()
select obj
animationobjcheckb=trackbar.getPreviousKeyTime()
animationobjcheckf=trackbar.getNextKeyTime()
if animationobjcheckb==undefined or animationobjcheckf==undefined then () else append allanimationobjec obj
select temporaryobjlist
)
free temporaryobjlist
allanimobjects=allanimationobjec.count
if allanimobjects>0 then
(
allanimationobjecinfo="Animated "+ allanimobjects as string ;allanimationobjecinfo=allanimationobjecinfo as string+"
“
)
)
enableSceneRedraw()
completeRedraw()
messagebox allanimationobjecinfo
)
what do you want to know? what selected objects are animated or what objects show keys in trackbar
You right.
Excuse me my messy explanation.
I would like to know how many object(which objects) in selection are animated – by animated I mean objects which posses any kind of animation key, it’s not important if keys are visible in trackbar or not.
http://forums.cgsociety.org/showpost.php?p=7697099&postcount=23
i already answered the same question in another thread
Another function that might work:
(
fn GetAnimatedNodes nodes:#() =
(
_getNextKeyTime = trackbar.getNextKeyTime
disableRefMsgs()
arr = for node in (nodes as array) collect
(
select node
if _getNextKeyTime() == undefined then dontcollect
)
enableRefMsgs()
return arr
)
-- Test
GetAnimatedNodes nodes:selection
)
It should return an array of nodes (within the past parameter nodes) that has any animated parameter. I havent fully tested it.
thanks Jorge but your code select – random object but never animated:)
Denis code is siutable for me but I dont know how to call this function to select object, the function is:
fn doesSubHaveAKey sub has:false =
(
if iskindof sub subanim do has = (sub.keys != undefined and sub.keys.count > 0)
for k=1 to sub.numsubs while not has do has = doesSubHaveAKey sub[k]
has
)
And I thought it was working… Well, here is a “fixed” version. Hope this one works:
(
fn GetAnimatedNodes nodes:#() =
(
_getNextKeyTime = trackbar.getNextKeyTime
disableRefMsgs()
arr = for node in (nodes as array) collect
(
select node
if _getNextKeyTime() == undefined then dontcollect else node
)
enableRefMsgs()
return arr
)
-- Test
select (GetAnimatedNodes nodes:selection)
)
Jorge, works great. Would you be so kind and give me one more simple clue.
As I operate on selection array this code should work on selection and it works just fine it self
however when I add any selection it seems like it work still fine when in selection is animated object(s) but if there is no animated object in selection then always one object is selected by this function inspite is without any key. I just add 3 short line which represent continuation of my code and it make your function won’t work correctly with selection free from animation.
What am I doing wrong?
(
objectslistmda=selection as array
clearselection()
select objectslistmda
fn GetAnimatedNodes nodes:#() =
(
_getNextKeyTime = trackbar.getNextKeyTime
disableRefMsgs()
arr = for node in (nodes as array) collect
(
select node
if _getNextKeyTime() == undefined then dontcollect else node
)
enableRefMsgs()
return arr
)
– Test
select (GetAnimatedNodes nodes:selection)
)
)
Piotr, the function is not fully implemented. For example it has no error checking, it does not restore the past nodes, etc. However it returns an array with the animated nodes. If there are no animated nodes it returns an empty array. From there you can do what you need with the result. The test line:
select (GetAnimatedNodes nodes:selection)
is just some action you can take, but it is not the only think you could do. For example, if you need to only keep selected the animated nodes you could do something like:
animatedNodes = GetAnimatedNodes nodes:selection
if animatedNodes.count > 0 then select animatedNodes
else max select none
This is just one way of doing it, but you could rewrite the function so it could be called SelectAnimatedNodes and implement the selection inside the function.
I already make a detour round an obstacle by adding this code after your function:
for o in selection do
(
animationobjcheckb=trackbar.getPreviousKeyTime()
animationobjcheckf=trackbar.getNextKeyTime()
if animationobjcheckb==undefined or animationobjcheckf==undefined then deselect $
)
however I will check your way, seems to look way cleaner than this one above. One way or another, your function save my day because yesterday was critical point for plugin I’m working on and amount of errors and scale of problems make me reinstal system today:) all of a sudden my script start doing random things. Hopefully I menage most of them at least the most terrible and I can go on with this. Yesterday I sat from 9am to 1 pm to fix errors and I fall in sleeped on keebord.
Thank you one more time
I will replace getPreviousKeyTime method with this
if (nodes = getCurrentSelection()).count != 0 do
(
local animNodes = #(), getNextKey = trackbar.getNextKeyTime
clearSelection()
with redraw off
for o in nodes do
(
select o
at time animationrange.start
if getNextKey() != null do append animNodes o
)
if animNodes.count != 0 do select animNodes
)
with redraw off
In this case disabling the redraw doesn’t seem to speed it up by much.
at time animationrange.start
If there are no keys ahead the current time, “getNextKeyTime” returns the first key.
If the “Reference Notification System” is not disabled it has a big impact in time, and it is much bigger if you happen to be in Modify Panel. On the other hand it is a little bit “dangerous” to disable/enable it.