On 30/09/2013 at 15:09, xxxxxxxx wrote:
Do not use doc = c4d.documents.GetActiveDocument()in plugin code (except for command data
plugins). C4d does duplicate the document for rendering which will render that code useless as
GetActiveDoucment() will always return the active document in the editor (so that you are using
the wrong document). It also does introduce possible problems with dead objects. If you cannot
get hold of the document a node is sitting in with GeListNode.GetDocument(), it is a strong
indicator that you should look for a later point of interception.
As I wrote already in my first posing the most straight forward option would be a MessageData
plugin monitoring your scene structure (or more specifically the top object and the current
selection). If you do REALLY want to do it from within your ObjectData plugin you could do the
following.
1. To be extra sure that the whole process is only invoked once I would add a virtual element to
the objects description, indicating if the object has already been moved once or not. You will also
need some boolean flag value in your class indicating that the node has to be moved.
2. In the Message method ( you could also use Init(), the object isn't yet alive there either ) store
the active object selection as a class member, using some clunky GetActiveDocument() code.
3. One of the first things which will happen after the node has been initialized is that c4d will build
its cache and call GVO. So check in GVO if your object is flagged for being relocated, if so, use the
stored object selection to modify the location of the node passed to GVO.
Please let me stress again, that this actually rather HACKY and BAD code. The separate
MessageData plugin would be a much cleaner solution.
edit : the general flaw in the logic of your code is ( now i do understand what niklas meant with
op.InsertUnder(op)), that at the point when the object is alive the active selection will be the
object itself, as c4d is selecting new objects. that is why you will need that 2 step approach and
also why a MessageData solution would be much better, as it wouldn't need such hacks.