<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Stuck with loop through tags]]></title><description><![CDATA[<p dir="auto">Hello everyone!</p>
<p dir="auto">I`m noobie and working on simple script that should generate on selected layers Redshift Object tag with checked Object ID Override. Also I need to make uniqe Object ID numbers by adding 1 to each tag.</p>
<p dir="auto">Problem: When I make loop through tags and try to increase Object ID parameters by 1 (I need 1, 2, 3,...) it pass all the tags exept the last and make the last tag Object ID parameter equal to objects quantity (9 in my case)</p>
<ol>
<li>How to increase Object ID parameters for each tags with uniqe data from 1 to {tags quantity}?</li>
<li>How to improve this code?</li>
</ol>
<p dir="auto"><img src="https://d.radikal.ru/d38/2006/39/852ddc99a13b.jpg" alt="screenshot" class=" img-fluid img-markdown" /></p>
<pre><code>import c4d
from c4d import gui



def main():
    doc.StartUndo()

    selection = doc.GetSelection()
    collectedObjects = []


    if selection:
        for s in selection:
            collectedObjects.append(s)
    else:
        c4d.gui.MessageDialog('Please choose objects')


    for s in collectedObjects:
        tag = c4d.BaseTag(1036222)
        tag[c4d.REDSHIFT_OBJECT_OBJECTID_OVERRIDE] = True
        s.InsertTag(tag)
        doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
        
        
        
    for tags in range(len(collectedObjects)):
        
        tag[c4d.REDSHIFT_OBJECT_OBJECTID_ID] += 1
        

        
    doc.EndUndo()    
        
        
if __name__=='__main__':
    c4d.CallCommand(13957)
    main()
    c4d.EventAdd()
</code></pre>
<p dir="auto">Thank you for your attention!</p>
]]></description><link>http://developers.maxon.net/forum/topic/12661/stuck-with-loop-through-tags</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Jul 2026 01:17:45 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/12661.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 12 Jun 2020 23:38:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Stuck with loop through tags on Mon, 15 Jun 2020 06:38:47 GMT]]></title><description><![CDATA[<p dir="auto">hi <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/superhomiak">@<bdi>SuperHomiak</bdi></a> welcome to the forum.<br />
Thanks @zipit for the answer <img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:23px;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
<p dir="auto">For your next threads, please help us keeping things organised and clean. I know it's not your priority but it really simplify our work here.</p>
<ul>
<li><a href="https://developers.maxon.net/forum/topic/11004/q-a-new-functionality" target="_blank" rel="noopener noreferrer nofollow ugc">Q&amp;A New Functionality</a>.</li>
<li><a href="https://developers.maxon.net/forum/topic/10953/how-to-post-questions" target="_blank" rel="noopener noreferrer nofollow ugc">How to Post Questions</a> especially the tagging part.</li>
</ul>
<p dir="auto">I've set the thread to a question and marked zipit answer as the right answer <img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:23px;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
<p dir="auto">Cheers,<br />
Manuel</p>
]]></description><link>http://developers.maxon.net/forum/post/63344</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/63344</guid><dc:creator><![CDATA[Manuel]]></dc:creator><pubDate>Mon, 15 Jun 2020 06:38:47 GMT</pubDate></item><item><title><![CDATA[Reply to Stuck with loop through tags on Sun, 14 Jun 2020 10:43:17 GMT]]></title><description><![CDATA[<p dir="auto">@zipit I appreciate your answer. Thank you very much!</p>
]]></description><link>http://developers.maxon.net/forum/post/63339</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/63339</guid><dc:creator><![CDATA[SuperHomiak]]></dc:creator><pubDate>Sun, 14 Jun 2020 10:43:17 GMT</pubDate></item><item><title><![CDATA[Reply to Stuck with loop through tags on Sat, 13 Jun 2020 02:13:20 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">it is easier just to answer in commented code, you will find anything there.</p>
<pre><code>import c4d
from c4d import gui

def main():

    # This would also include tags and materials, i.e. is not what you
    # want.    
    # selection = doc.GetSelection()

    # This does not accomplish anything. 'selection' is already a list and
    # you just build element by element a new list of it.

    # collectedObjects = []
    # if selection:
    #     for s in selection:
    #         collectedObjects.append(s)
    # else:
    #     c4d.gui.MessageDialog('Please choose objects')  

    # This part is technically okay, but we will consolidate it with the
    # next loop.
    # for s in collectedObjects:
    #     tag = c4d.BaseTag(1036222)
    #     tag[c4d.REDSHIFT_OBJECT_OBJECTID_OVERRIDE] = True
    #     s.InsertTag(tag)
    #     doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
    
    # You never use your loop variable 'tags'. And you are referencing
    # 'tag', which was the symbol for the BaseTag you did instantiate in 
    # the last loop. Because of that you will only increment the last tag
    # you have created in this last loop over and over.

    # for tags in range(len(collectedObjects)):
    #     tag[c4d.REDSHIFT_OBJECT_OBJECTID_ID] += 1

    # If you want to enumerate some objects, you could just create a counter
    # and increment it manually.

    counter = 0
    for char in ["A", "B", "C", "D"]:
        print counter, char
        counter += 1

    # But that would not be very pythonic. Python has the wonderful function
    # enumerate for this scenario, which will enumerate a collection object.

    # This will only return the selected BaseObject nodes. See the docs for
    # details. I did choose the flags so that we also include nodes that are
    # not top level nodes and that the returned list reflects the selection
    # order, which seems important in this case.
    flags = (c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER | 
             c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
    selection = doc.GetActiveObjects(flags)

    if not selection:
        raise ValueError("No objects selected.")

    doc.StartUndo()
    for i, node in enumerate(selection):
        # Since I do not own ReadShift, I will just be using the annotation
        # tag.
        tag = c4d.BaseList2D(c4d.Tannotation)
        tag[c4d.ANNOTATIONTAG_TEXT] = str(i)
        node.InsertTag(tag)
        doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
    doc.EndUndo()    
    c4d.EventAdd()
          
if __name__=='__main__':
    #c4d.CallCommand(13957)
    main()
</code></pre>
<p dir="auto">Cheers,<br />
zipit</p>
]]></description><link>http://developers.maxon.net/forum/post/63333</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/63333</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Sat, 13 Jun 2020 02:13:20 GMT</pubDate></item></channel></rss>