Hi, I've got a prototype/pythonTag running in py2 & py3, where all the basics are just working fine. The problem is that python2 crashes when I try to avoid multiple "MSG" pyTags in one scene/doc...
I can only have 1 tag per scene since the pyTag adjusts the timeLine where needed. Multiple tags would fight each other..
I thought of a workaround involving 2 items set to the document container (op & op.GetObject()).
The basic principle is that I know what/where to delete if a new tag is copied/inserted by the user. (The pyTag itself is set to No_Delete & No_DragNDrop)
As said, this works fine in py3 (R23/24), but I don't understand why this isn't working in py2 - for I can just read the doc.GetDataInstance & ..GetData(..) etc.
Any clues on what's causing the crash in py2?
(and as a sub-question - is there a smarter way to ensure 1 specific tag per scene?..)
See the check_single_pytag() func below. Tia, Jochem
def set_doc_bc(uniqueId):
doc = op.GetDocument()
docBC = doc.GetDataInstance()
subBc = c4d.BaseContainer()
subBc[123] = op
subBc[124] = op.GetObject()
docBC.SetContainer(uniqueId, subBc)
doc.SetData(docBC)
def check_single_pytag(): # check pyTag(s) - for there can be only one..
doc = op.GetDocument()
docBC = doc.GetDataInstance()
uniqueId = 12345 # not this :)
def new_null(): # small local func to set pyTag to a new null..
nully = c4d.BaseObject(c4d.Onull)
nully.InsertBefore(op.GetObject())
nully.SetName("MSG")
nully[c4d.NULLOBJECT_DISPLAY] = 14 # none
nully.InsertTag(op)
op[c4d.ID_USERDATA,52] = nully
op.Message(c4d.MSG_UPDATE)
try:
docBcTag = doc.GetDataInstance()[uniqueId].GetData(123)
if docBcTag == op: pass # original tag, so skip
elif not docBcTag.GetDocument(): # orginal tag deleted - set a new one
new_null()
set_doc_bc(uniqueId)
else:
# UD52 = linkfield on pyTag with op.GetObject()
if op[c4d.ID_USERDATA,52] == None or op.GetObject() == doc.GetDataInstance()[uniqueId].GetData(124):
op.Remove() # 2nd tag on original pyNull - remove
return False
else: # new/copied tag - remove all..
op.GetObject().Remove()
return False
except AttributeError: # no tag in doc yet..
new_null()
set_doc_bc(uniqueId)
return True