Solved Force InExclusionData update after remove object outside of In-/Exclusion User Data

Hi,
I have a very simple scene:

  • A Null Object with an In-/Exclusion User Data
  • A Python Tag on the Null Object
  • some script in the Python Tag
import c4d

def main():
    obj = op.GetObject()
    objList = obj[c4d.ID_USERDATA,1] # point to the In-/Exclusion User Data
    print(objList.GetObjectCount())

If I add scene objects into In-/Exclusion User Data, or remove object within In-/Exclusion User Data, Python Tag will print correct object count.

But if I remove an object from the Object Manager which had been added into the In-/Exclusion User Data before, I can see object has been removed in In-/Exclusion User Data, but Python Tag report wrong object count (as if the object has not been removed).

And only if I make some change within the In-/Exclusion User Data directly, that the Python Tag report correct count number again.

I wonder if there is something I'm missing from the script for forcing InExclusionData update, or it's a bug in the "updating system"?

Thanks!

Hi,

The InExcludeData object count does not always reflect the accurate number of valid objects depending on the scenarios.
Additionally to calling GetObjectCount() the returned value from ObjectFromIndex() should be checked if it's not None.

Former MAXON SDK Engineer

Hi, y_puech!

Thank you for replying!
I use

i = 0
while True:
    obj = InExData.ObjectFromIndex(doc,i)
    if obj == None:
        break
i += 1

to get right result.

Hi,

Just a quick note on your code. A pythonic solution could be:

count = inExData.GetObjectCount()
for i in xrange(count):
    obj = inExData.ObjectFromIndex(doc, i)
    if obj is None:
        continue

Why are you breaking out from the loop with the first invalid object in the InExcludeData?

Former MAXON SDK Engineer

Oh! Sorry! I know what you mean in the previous post now. I'm doing the wrong way. Your solution is correct!

By the way, I wonder if there is a situation where the actual object counts are greater than GetObjectCount() returned?

By the way, I wonder if there is a situation where the actual object counts are greater than GetObjectCount() returned?

This should never happen.

Thanks for marking the topic as solved. Note that you can mark a specific post as the correct answer or solution. See step 5 in Q&A New Functionality.

Former MAXON SDK Engineer

Hi, @y_puech I may find a bug of the forum about "mark a post correct answer", discussion post here: Cannot mark post as answer
Once this bug solved, I will re-edit this topic and posts correctly.