<?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[How to Undo Switching Between Modes?]]></title><description><![CDATA[<p dir="auto">Hello all, my script needs to work in point, edge, and polygon modes (edit modes). At the end of the script, I will switch it back to model mode, but I'm not sure how to undo the mode switching. When I run the code in point mode, I can't return to point mode when undoing</p>
<pre><code>import c4d

def main():
    sel = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
    if not sel or not doc.IsEditMode(): return # edit mode

    doc.StartUndo()
    for obj in sel:
        doc.SetSelection(obj, c4d.SELECTION_SUB)
        joint = c4d.BaseObject(c4d.Ojoint)
        doc.AddUndo( c4d.UNDOTYPE_NEWOBJ, joint)
        doc.InsertObject(joint, None, obj, True)
        doc.SetSelection(joint, c4d.SELECTION_ADD)
        ...

    doc.SetMode(c4d.Mmodel) # set model mode
    doc.EndUndo()
    c4d.EventAdd()

if __name__ == '__main__':
    main()
</code></pre>
]]></description><link>http://developers.maxon.net/forum/topic/15626/how-to-undo-switching-between-modes</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 14:35:08 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/15626.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 03 Aug 2024 23:19:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to Undo Switching Between Modes? on Tue, 06 Aug 2024 16:02:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a> said in <a href="/forum/post/74705">How to Undo Switching Between Modes?</a>:</p>
<blockquote>
<p dir="auto">Well, just move the code which switches the mode to the end of your code when it is only cosmetic anyways. As I said above, a sensible way to use <code>SetMode</code> is when you want to leave the user in a state where he or she can continue working right away. But you can then just run all your code, check if everything went fine and then set your code. Otherwise you never set the mode, and therefore also have nothing to revert.</p>
</blockquote>
<p dir="auto">It's a matter of workflow. It's not simply for checking the code that it's working properly. It's about a workflow. The workflow in the example is Select some mesh components, run the command. It generates something for you and switches the mode for you.  If you selected the wrong components, you'd undo and try it again. But the undo won't put you back in the component mode. The issue is that that part of the command is not undoable so it's does hinder the workflow just a bit. I'm not necessarily advocating that it should be undoable or anything like that, just explaining the reasoning in this example and the value if it were undoable.</p>
]]></description><link>http://developers.maxon.net/forum/post/74711</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74711</guid><dc:creator><![CDATA[BretBays]]></dc:creator><pubDate>Tue, 06 Aug 2024 16:02:05 GMT</pubDate></item><item><title><![CDATA[Reply to How to Undo Switching Between Modes? on Tue, 06 Aug 2024 09:23:21 GMT]]></title><description><![CDATA[<p dir="auto">Well, just move the code which switches the mode to the end of your code when it is only cosmetic anyways. As I said above, a sensible way to use <code>SetMode</code> is when you want to leave the user in a state where he or she can continue working right away. But you can then just run all your code, check if everything went fine and then set your code. Otherwise you never set the mode, and therefore also have nothing to revert.</p>
<p dir="auto">It does not really break anything if you do it differently, as changing the document mode is not that much of an expensive operation. But in general, it is cosmetic call that has little impact on your code (exceptions prove the rule). The thing I wanted to emphasize here is that calling this method is mostly meaningless from an API point of view, other than the user view in the app, where the document mode is a fundamental decision which impacts many things.</p>
<p dir="auto">Cheers,<br />
Ferdinand</p>
]]></description><link>http://developers.maxon.net/forum/post/74705</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74705</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Tue, 06 Aug 2024 09:23:21 GMT</pubDate></item><item><title><![CDATA[Reply to How to Undo Switching Between Modes? on Tue, 06 Aug 2024 07:49:35 GMT]]></title><description><![CDATA[<p dir="auto">I think the idea is that when working with this and testing it, it becomes a thing that the user has to manage themselves.</p>
<p dir="auto">Imagine you have a script that takes point selections, then creates a null, and then switches to object mode with the null selected so you can immediate move the null.</p>
<p dir="auto">You hit undo, null is gone. Back to your point object selected, but you are still in model mode. So to run it again youd need to manually switch back to point mode, THEN run the script again.</p>
<p dir="auto">Thats what I think the idea for the use case is.</p>
]]></description><link>http://developers.maxon.net/forum/post/74702</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74702</guid><dc:creator><![CDATA[BretBays]]></dc:creator><pubDate>Tue, 06 Aug 2024 07:49:35 GMT</pubDate></item><item><title><![CDATA[Reply to How to Undo Switching Between Modes? on Mon, 05 Aug 2024 14:57:08 GMT]]></title><description><![CDATA[<p dir="auto">I understood that <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="🙂" /> What I do not understand is why you want to do this in the first place, as changing the document mode his little impact on your code. But I guess the problem is solved for your now, so let's move on <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>
]]></description><link>http://developers.maxon.net/forum/post/74696</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74696</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Mon, 05 Aug 2024 14:57:08 GMT</pubDate></item><item><title><![CDATA[Reply to How to Undo Switching Between Modes? on Mon, 05 Aug 2024 14:29:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a> My English isn't very good, sorry<img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f623.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--persevere" style="height:23px;width:auto;vertical-align:middle" title=":persevere:" alt="😣" />  about that. What I mean is that when I am in edit mode and select points/edges/polygons, create a null object, and then switch back to object mode, if I want to undo, it would be more 'user-friendly' if I could return to the previous edit mode instead of object mode<br />
It's good to know that calling doc.SetMode(c4d.Mmodel) is non-undoable; I struggled with this for a while<img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f62c.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--grimacing" style="height:23px;width:auto;vertical-align:middle" title=":grimacing:" alt="😬" /></p>
]]></description><link>http://developers.maxon.net/forum/post/74694</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74694</guid><dc:creator><![CDATA[kangddan]]></dc:creator><pubDate>Mon, 05 Aug 2024 14:29:32 GMT</pubDate></item><item><title><![CDATA[Reply to How to Undo Switching Between Modes? on Mon, 05 Aug 2024 10:27:19 GMT]]></title><description><![CDATA[<p dir="auto">Hey, thanks for the video. But I still do not quite understand what you want to achieve by switching the mode. Unlike end users in a document, we can always access all data in a document, no matter the mode it is in. As an on the nose example: We can access the points of an object while not being in points mode. This makes it a bit pointless to change modes unless you want to switch the mode for the user. E.g., a plugin that extrudes a polygon and then leaves off in polygon mode so that the user can keep modelling.</p>
<p dir="auto">There are some exceptions to this, there is for example some feature in the UV toolset which will refuse to work properly unless you are in UV mode (I always forget what feature that exactly this is until I need it and then wonder why things are not working <img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--smile" style="height:23px;width:auto;vertical-align:middle" title=":D" alt="😄" /> ). But these are very rare exceptions, not to say <em>'cough'</em> bugs <em>'cough'</em>.</p>
]]></description><link>http://developers.maxon.net/forum/post/74692</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74692</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Mon, 05 Aug 2024 10:27:19 GMT</pubDate></item><item><title><![CDATA[Reply to How to Undo Switching Between Modes? on Mon, 05 Aug 2024 09:44:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a>  Thank you for letting me know that switching between modes is irreversible! My initial thought was that when I generate an empty object in edit mode, if I undo the action, I could return to edit mode. Thanks again for your explanation <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="🙂" /><video class="embed-video-local" controls src="/forum/assets/uploads/files/1722851042468-move.mp4">
</video></p>]]></description><link>http://developers.maxon.net/forum/post/74690</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74690</guid><dc:creator><![CDATA[kangddan]]></dc:creator><pubDate>Mon, 05 Aug 2024 09:44:09 GMT</pubDate></item><item><title><![CDATA[Reply to How to Undo Switching Between Modes? on Mon, 05 Aug 2024 10:20:40 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/kangddan">@<bdi>kangddan</bdi></a>,</p>
<p dir="auto">Thank you for reaching out to us. I do not quite understand your question. The document mode is just a (special) tool that is active in the document. Setting that mode is not undoable, just as activating the extrude tool is not undoable. One can quite easily test this as an end user by hitting 'undo' after changing the document mode. So, I do not quite understand what you want to do.</p>
<p dir="auto">When you just want to revert to the previous state, just store/cache it yourself. But even that does not really make sense, as switching the document mode is not necessary for other code to run. So, when you set the document mode in code, you usually want it to stay so that user can make use of that new mode.</p>
<p dir="auto">Cheers,<br />
Ferdinand</p>
<h4>Output</h4>
<pre><code class="language-txt">The document mode is: 6
The document mode is: 7
Doing work ...
The document mode is: 6
</code></pre>
<h4>Code</h4>
<pre><code class="language-py">import c4d

def main():
    """
    """
    mode: int = doc.GetMode()
    print (f"The document mode is: {mode}")
    
    doc.SetMode(c4d.Mpolygons)
    print (f"The document mode is: {c4d.Mpolygons}")
    print ("Doing work ...")
    
    doc.SetMode(mode)
    print (f"The document mode is: {mode}")

    # This all does not make too much sense, as our API usually does not care in which mode a document is or
    # provides special arguments to emulate a mode like for example #SendModelingCommand does.
    
    c4d.EventAdd()


if __name__ == '__main__':
    main()
</code></pre>
]]></description><link>http://developers.maxon.net/forum/post/74686</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/74686</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Mon, 05 Aug 2024 10:20:40 GMT</pubDate></item></channel></rss>