Hi @m_magalhaes
Thanks for the response.
RE: Your script, as you are trying to do it, will never work. Disabling the track, change the value, reactivate the track
Oh okay. The "reactivation part" was just my hunch since you deactivate it first. I was thinking to reactivate it again.
That said, I tried doing only Disabling Track
and Change Value
but the result is still the same (i.e. It does work with the keyed object. The problem is it overrides the previous values. )
RE: your ActivateTracks isn't right, track.SetBit(c4d.BIT_ACTIVE) is not the right command to "activate" a track.
So I guess this part is irrelevant since I don't need to activate/reactive it?
RE: this thread about using the autokey
I tried the autokey with the doc.AutoKey
and even with the doc.Record
but I still get the same result ( .e. It does work with the keyed object. The problem is it overrides the previous values.)
Here is the working code in a plugin form as you suggested:
It only works on the object named "Cylinder" same as before:
import c4d
import sys
from c4d import bitmaps, documents, gui, plugins, threading, utils
PLUGIN_ID = 18113999 # Just test ID. Not for production.
class MyDialog(c4d.gui.GeDialog):
def __init__(self):
self.doc = c4d.documents.GetActiveDocument()
self.finger_B_01_L_con = self.doc.SearchObject('Cylinder')
def DesactivateTracks(self, op):
# Retrieves the tracks.
tracks = op.GetCTracks()
# Track list that we want to desactivate.
trackListToDIsable = [c4d.ID_BASEOBJECT_POSITION, c4d.ID_BASEOBJECT_ROTATION, c4d.ID_BASEOBJECT_SCALE]
for track in tracks:
did = track.GetDescriptionID()
# If the Parameter ID of the current CTracks is not on the trackListToDIsable we go to the next one.
if not did[0].id in trackListToDIsable:
continue
track.SetBit(c4d.BIT_ANIM_OFF)
def ActivateTracks(self, op):
# Retrieves the tracks.
tracks = op.GetCTracks()
# Track list that we want to desactivate.
trackListToDIsable = [c4d.ID_BASEOBJECT_POSITION, c4d.ID_BASEOBJECT_ROTATION, c4d.ID_BASEOBJECT_SCALE]
for track in tracks:
did = track.GetDescriptionID()
# If the Parameter ID of the current CTracks is not on the trackListToDIsable we go to the next one.
if not did[0].id in trackListToDIsable:
continue
track.SetBit(c4d.BIT_ACTIVE)
def CreateLayout(self):
self.AddEditNumberArrows(id=404040, flags=c4d.BFH_LEFT, initw=100, inith=0)
return True
def InitValues(self):
val = self.finger_B_01_L_con[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Z]
self.SetDegree(404040, val, min=-180, max=180, step=1, tristate=False)
return True
def Message(self, msg, result):
if msg.GetId() == c4d.BFM_ACTION:
ID_AUTOKEYING_COMMAND = 12425
previousAutokeyEnableState = c4d.IsCommandChecked(ID_AUTOKEYING_COMMAND)
if not previousAutokeyEnableState:
c4d.CallCommand(ID_AUTOKEYING_COMMAND)
self.DesactivateTracks(self.finger_B_01_L_con)
self.doc.StartUndo()
self.doc.AddUndo(c4d.UNDOTYPE_CHANGE, self.finger_B_01_L_con)
undoObj = self.doc.GetUndoPtr()
self.finger_B_01_L_con[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_Z] = self.GetFloat(404040)
#self.ActivateTracks(self.finger_B_01_L_con)
self.doc.AutoKey(self.finger_B_01_L_con, undoObj, False, True, True, True, True, True)
self.doc.Record()
c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_NO_REDUCTION | c4d.DRAWFLAGS_STATICBREAK)
self.doc.EndUndo()
if not previousAutokeyEnableState:
c4d.CallCommand(ID_AUTOKEYING_COMMAND)
if msg.GetId() == c4d.BFM_INTERACTEND:
self.InitValues()
return True
return c4d.gui.GeDialog.Message(self, msg, result)
def Command (self, id, msg):
return True
class MyMenuPlugin(plugins.CommandData):
dialog = None
def Execute(self, doc):
# create the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)
def RestoreLayout(self, sec_ref):
# manage the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__ == "__main__":
okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "Key Objects Interactively",0, None, "Key Objects Interactively", MyMenuPlugin())
if (okyn):
print "Key Objects Interactively"