access userdata inside userdata group [SOLVED]
-
On 09/07/2015 at 02:17, xxxxxxxx wrote:
Hello,
if you just want to reset the userdata of a specific userdata group you have to check if a given userdata parameter is part of that group. You can access DESC_PARENTGROUP to get the ID of the parent group. So your code could look something like this:
for id, bc in op.GetUserDataContainer() : if bc[c4d.DESC_PARENTGROUP][-1].id == 2: op[id] = bc[c4d.DESC_DEFAULT]
Best wishes,
Sebastian -
On 09/07/2015 at 03:33, xxxxxxxx wrote:
I get an error message:
Traceback (most recent call last) :
File "scriptmanager", line 11 in ,module.
TypeError:_setitem_expected int or bool, not None -
On 09/07/2015 at 06:00, xxxxxxxx wrote:
Originally posted by xxxxxxxx
I get an error message:
Traceback (most recent call last) :
File "scriptmanager", line 11 in ,module.
TypeError:_setitem_expected int or bool, not NoneHi
I test code and simple print to dive in to levelfor id, bc in op.GetUserDataContainer() : print bc[c4d.DESC_PARENTGROUP][-1].id if bc[c4d.DESC_PARENTGROUP][-1].id == 700: op[id] = bc[c4d.DESC_DEFAULT]
i have id in level = 700.
Try such, code works for me
-
On 09/07/2015 at 06:18, xxxxxxxx wrote:
I tried your code and still get the same error message.
-
On 09/07/2015 at 06:22, xxxxxxxx wrote:
If I try this code from the Script Manager, it works and only userdata from group 255 is reset but when it is on a Python tag, it doesn't. Any suggestions?
import c4d
for id, bc in op.GetUserDataContainer() :
if bc[c4d.DESC_PARENTGROUP][-1].id == 255:
try:
op[id] = bc[c4d.DESC_DEFAULT]
except TypeError:
#No or invalid default value.
passc4d.EventAdd()
-
On 09/07/2015 at 08:02, xxxxxxxx wrote:
For a Python Tag, "op" is the Tag, not the Object. Use the variable "obj" in all places instead of "op" and add "obj = op.GetObject()" beforehand.
-
On 09/07/2015 at 10:57, xxxxxxxx wrote:
Thanks, Niklas, that totally worked! The last thing I need and can't get to work is the switch. Here is what I have:
import c4d
obj = op.GetObject()
ID_RESET_Iceland = 39
def main() :
for id, bc in obj.GetUserDataContainer() :
if bc[c4d.DESC_PARENTGROUP][-1].id == 255:
if obj[c4d.ID_USERDATA, ID_RESET_Iceland]:
obj[c4d.ID_USERDATA, ID_RESET_Iceland] = False
try:
obj[id] = bc[c4d.DESC_DEFAULT]
except TypeError:
#No or invalid default value.
pass
c4d.EventAdd()if __name__=='__main__':
main() -
On 09/07/2015 at 11:44, xxxxxxxx wrote:
I now have this but it still doesn't work.
import c4d
obj = op.GetObject()
ID_RESET_Iceland = 39
def main() :
for id, bc in obj.GetUserDataContainer() :
if (bc[c4d.DESC_PARENTGROUP][-1].id == 255 and
obj[c4d.ID_USERDATA, ID_RESET_Iceland] == False) :
try:
obj[id] = bc[c4d.DESC_DEFAULT]
except TypeError:
#No or invalid default value.
pass
c4d.EventAdd()if __name__=='__main__':
main() -
On 09/07/2015 at 17:10, xxxxxxxx wrote:
Try this instead
import c4d ID_RESET_Iceland = 39 def main() : obj = op.GetObject() if not obj[c4d.ID_USERDATA, ID_RESET_Iceland]: return obj[c4d.ID_USERDATA, ID_RESET_Iceland] = False for id, bc in obj.GetUserDataContainer() : if bc[c4d.DESC_PARENTGROUP][-1].id == 255: try: obj[id] = bc[c4d.DESC_DEFAULT] except TypeError: pass c4d.EventAdd()
Don't use that __name__ == "__main__" part in a Python Tag
-
On 09/07/2015 at 19:59, xxxxxxxx wrote:
It works! You are a genius! Thanks very much for this Niklas.
-
On 09/07/2015 at 20:19, xxxxxxxx wrote:
One problem, the script keeps looping after I activate the reset button. Is there a way to stop it?
-
On 09/07/2015 at 20:23, xxxxxxxx wrote:
Figured that out. Moved c4d.EventAdd() out of the for loop. But now it resets regardless of whether or not the reset switch is activated.
import c4d
ID_RESET_Iceland = 39
def main() :
obj = op.GetObject()
if not obj[c4d.ID_USERDATA, ID_RESET_Iceland]:
return
obj[c4d.ID_USERDATA, ID_RESET_Iceland] = Falsefor id, bc in obj.GetUserDataContainer() :
if bc[c4d.DESC_PARENTGROUP][-1].id == 255:
try:
obj[id] = bc[c4d.DESC_DEFAULT]
except TypeError:
pass
c4d.EventAdd() -
On 10/07/2015 at 15:48, xxxxxxxx wrote:
Got it working! I had the wrong userdata id number.
import c4d
def main() :
ID_RESET_Iceland = 121
obj = doc.SearchObject("DEEP FREEZE")
#obj = op.GetObject()
if obj[c4d.ID_USERDATA, ID_RESET_Iceland]:
obj[c4d.ID_USERDATA, ID_RESET_Iceland] = Falsefor id, bc in obj.GetUserDataContainer() :
if bc[c4d.DESC_PARENTGROUP][-1].id == 255:
try:
obj[id] = bc[c4d.DESC_DEFAULT]
except TypeError:
pass
for id, bc in obj.GetUserDataContainer() :
if bc[c4d.DESC_PARENTGROUP][-1].id == 277:
try:
obj[id] = bc[c4d.DESC_DEFAULT]
except TypeError:
pass
for id, bc in obj.GetUserDataContainer() :
if bc[c4d.DESC_PARENTGROUP][-1].id == 515:
try:
obj[id] = bc[c4d.DESC_DEFAULT]
except TypeError:
pass
for id, bc in obj.GetUserDataContainer() :
if bc[c4d.DESC_PARENTGROUP][-1].id == 516:
try:
obj[id] = bc[c4d.DESC_DEFAULT]
except TypeError:
pass
c4d.EventAdd()