On 18/05/2017 at 12:43, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R18
Platform:
Language(s) : PYTHON ;
---------
I got a pretty weird crash. The crash occurs only when sds tag already exist into the mesh.
About the script usage. Make a box. Make it editable. Make an edge selection into it.
import c4d
def get_all_objs(op, data=None) :
""" get a list of all obj in the scene """
if not data:
data = list()
while op:
data.append(op)
data += get_all_objs(op.GetDown(), None)
op = op.GetNext()
return data
def reinitialize(obj) :
tag = obj.GetTag(c4d.Tsds)
#probably crash come from here. Since it's only bug when an SDS is already into the mesh.
if tag:
new_tag = c4d.BaseTag(c4d.Tsds)
obj.InsertTag(new_tag)
tag.Remove()
if not tag:
tag = c4d.BaseTag(c4d.Tsds)
obj.InsertTag(tag)
def make_sds(obj) :
selection_tag = obj.GetTag(c4d.Tedgeselection)
if not selection_tag:
return
doc.SetActiveObject(obj)
# Set To edge mdoe
doc.SetMode(c4d.Medges)
# Get selected edge
bs = obj.GetEdgeS()
bs_copy = bs.GetClone() # for retrieve it later
# Set the weight
tool = c4d.plugins.FindPlugin(1007573, c4d.PLUGINTYPE_TOOL)
tool[c4d.MDATA_SDSWEIGHT_MODE] = 0
tool[c4d.MDATA_SDSWEIGHT_STRENGTH] = 1
c4d.CallButton(tool, c4d.MDATA_SDSWEIGTH_SETSTRENGTH)
# reset edge selection
bs_copy.CopyTo(obj.GetEdgeS())
def main() :
objs = get_all_objs(doc.GetFirstObject())
save_mode = doc.GetMode()
save_obj = doc.GetActiveObjects(1)
for obj in objs:
make_sds(obj)
# reset doc
first = True
for o in save_obj:
if first:
doc.SetSelection(o, c4d.SELECTION_NEW)
first = False
else:
doc.SetSelection(o, c4d.SELECTION_ADD)
doc.SetMode(save_mode)
c4d.EventAdd()
objs = get_all_objs(doc.GetFirstObject())
for obj in objs:
reinitialize(obj)
c4d.EventAdd()
if __name__ == '__main__':
main()
If you execute only one time. and quit the scene. C4D will not crash.
If you execute this script two time. C4d will crash on the exit.
If you only use make_sds. It not crash
If you only use reinitialize. It not crash
If you use reinitialize before make_sds. It not crash.
I think the crash come from this part since it only happend if a c4d.Tsds tag already exist on the mesh.
if tag:
new_tag = c4d.BaseTag(c4d.Tsds)
obj.InsertTag(new_tag)
tag.Remove()
I already found a workaround, and I changed my reinitialize function and now is not crashing anymore. So it's just for you support guys.