<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: addToAnimClip() in VRED Forum</title>
    <link>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/11968170#M3133</link>
    <description>&lt;P&gt;I stumbled across this issue during development as well.&lt;/P&gt;&lt;P&gt;At first I thought the API documentation of&amp;nbsp;addToAnimClip is misleading or wrong... but it's correct as soon as one realizes that o&lt;SPAN&gt;bjects of type vrNodePtr can come from several different node graphs&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_open_mouth:"&gt;😮&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The API v2 documentation does a good job at explaining that, by the way:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://help.autodesk.com/view/VREDPRODUCTS/2021/ENU/?guid=VRED_Python_Documentation_Python_API_V2_Scene_graphs_in_VRED_html" target="_blank" rel="noopener"&gt;VRED 2021.3 Help | Scene Graphs in VRED | Autodesk&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here, the confusion might arise due to the second parameter of&amp;nbsp;&lt;STRONG&gt;addToAnimClip&lt;/STRONG&gt;(clip, object, frame)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&lt;SPAN&gt;object (vrNodePtr) - The object which should be added to the clip.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Unfortunately, the required type is ambigious:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;vrNodePtr objects from the scenegraph (e.g. vrScenegraph.getSelectedNode)&lt;/LI&gt;&lt;LI&gt;vrNodePtr objects from the curve editor (e.g.&amp;nbsp;vrAnimWidgets.findAnimBlock)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;The object has to come from the vrAnimWidgets for this function to work correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, one has to dig quite deep to locate animations that are linked to scenegraph nodes.&lt;/P&gt;&lt;P&gt;The best I could come up with relies heavily on API v1 fields:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getAnimationsFromNode(animatedScenegraphNode):
    animations = []
    # scenegraph nodes with animations have an 'AnimAttachment'
    if animatedScenegraphNode.hasAttachment("AnimAttachment"):
        animAttachment = animatedScenegraphNode.getAttachment("AnimAttachment")
        animationRoot = vrFieldAccess(vrFieldAccess(animAttachment).getFieldContainer("animationRoot"))
        # the animationRoot links to all animations that refer to this scenegraph node
        # access to multiple nodes through the vrFieldAccess is only possible via IDs
        ids = animationRoot.getMFieldContainerId("children")
        # iterate over all animations of this scenegraph node
        for animationNode in [toNode(id) for id in ids]:
            if not animationNode.isValid():
                print(f"Skipping invalid animation node {animationNode}")
                continue
            # access vrNodePtr from animation graph
            print(f"{animatedScenegraphNode.getType()} '{animatedScenegraphNode.getName()}' with ID {animatedScenegraphNode.getID()} has {animationNode.getType()} '{animationNode.getName()}' with ID {animationNode.getID()}")
            animations.append(animationNode)
    return animations


animatedNode = getSelectedNode()
# clip that should receive the selected node's animation blocks
clipName = "Clip"
clip = findAnimClip(clipName)
for animation in getAnimationsFromNode(animatedNode):
    success = addToAnimClip(clip, animation, 0)
    if success:
        print(f"Successfully added {animation.getType()} '{animation.getName()}' to {clip.getType()} '{clip.getName()}'")
    else:
        print(f"Failed to add {animation.getType()} '{animation.getName()}' to {clip.getType()} '{clip.getName()}'")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Let me know if there's a better solution.&lt;/P&gt;</description>
    <pubDate>Tue, 16 May 2023 18:08:42 GMT</pubDate>
    <dc:creator>clemens_schlicker_audi</dc:creator>
    <dc:date>2023-05-16T18:08:42Z</dc:date>
    <item>
      <title>addToAnimClip()</title>
      <link>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/10281469#M3130</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get an animation block into a clip using addToAnimClip() in 2021.3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thing is, it crashes VRED when I use the results from findAnimClip() and findAnimBlock() + 0 like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;addToAnimClip&lt;/STRONG&gt;(studyClip, studyBlock, 0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which as far as I can tell is following the documentation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;addToAnimClip&lt;/STRONG&gt;(clip, object, frame)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;where:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;clip&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(vrNodePtr) - The target clip.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;object&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(vrNodePtr) - The object which should be added to the clip.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;frame&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(int) - The start frame for the block or camera track. This value has no effect for clips.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;BR /&gt;I purposefully sent the wrong arguments to see if I could get some more info and got this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;did not match C++ signature:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;addToAnimClip(class vrNodePtr, class vrNodePtr, int clip, object, frame)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Not 100% what i'm doing wrong, but it consistently crashes VRED if I pass what I assume are the right arguments. Anyone have any ideas as to how to get this to work?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 12:41:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/10281469#M3130</guid>
      <dc:creator>bryan_martin_morris</dc:creator>
      <dc:date>2021-04-30T12:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: addToAnimClip()</title>
      <link>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/10289034#M3131</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;thanks for reporting the crash, I can reproduce it. Your way of using addToAnimClip is correct.&lt;/P&gt;
&lt;P&gt;The crash happens when the block node passed to the function is not valid, e.g. a block with the name could not be found.&lt;/P&gt;
&lt;P&gt;Of course addToAnimClip should check that internally and not crash, but to work around you can check it yourself before calling addToAnimClip:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;studyClip = findAnimClip("clip name")
studyBlock = findAnimBlock("block name") 
if studyBlock.isValid():
    addToAnimClip(studyClip, studyBlock, 0)
else:
    print("could not find block")&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Sinje&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 09:18:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/10289034#M3131</guid>
      <dc:creator>sinje_thiedemann</dc:creator>
      <dc:date>2021-05-04T09:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: addToAnimClip()</title>
      <link>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/10289169#M3132</link>
      <description>&lt;P&gt;Hey Sinje,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the response, I'll work that into my script although clearly now I need to get to the bottom of why I'm calling a non-existant block &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the addition of an .isValid() check would probably be a good idea elsewehere in my scripts too!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also sorry my post title was lacking detail. I think it must have been too close to beer o'clock on Friday, and my mind was not fully functional.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bryan&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 10:09:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/10289169#M3132</guid>
      <dc:creator>bryan_martin_morris</dc:creator>
      <dc:date>2021-05-04T10:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: addToAnimClip()</title>
      <link>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/11968170#M3133</link>
      <description>&lt;P&gt;I stumbled across this issue during development as well.&lt;/P&gt;&lt;P&gt;At first I thought the API documentation of&amp;nbsp;addToAnimClip is misleading or wrong... but it's correct as soon as one realizes that o&lt;SPAN&gt;bjects of type vrNodePtr can come from several different node graphs&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_open_mouth:"&gt;😮&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The API v2 documentation does a good job at explaining that, by the way:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://help.autodesk.com/view/VREDPRODUCTS/2021/ENU/?guid=VRED_Python_Documentation_Python_API_V2_Scene_graphs_in_VRED_html" target="_blank" rel="noopener"&gt;VRED 2021.3 Help | Scene Graphs in VRED | Autodesk&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here, the confusion might arise due to the second parameter of&amp;nbsp;&lt;STRONG&gt;addToAnimClip&lt;/STRONG&gt;(clip, object, frame)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&lt;SPAN&gt;object (vrNodePtr) - The object which should be added to the clip.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Unfortunately, the required type is ambigious:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;vrNodePtr objects from the scenegraph (e.g. vrScenegraph.getSelectedNode)&lt;/LI&gt;&lt;LI&gt;vrNodePtr objects from the curve editor (e.g.&amp;nbsp;vrAnimWidgets.findAnimBlock)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;The object has to come from the vrAnimWidgets for this function to work correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, one has to dig quite deep to locate animations that are linked to scenegraph nodes.&lt;/P&gt;&lt;P&gt;The best I could come up with relies heavily on API v1 fields:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getAnimationsFromNode(animatedScenegraphNode):
    animations = []
    # scenegraph nodes with animations have an 'AnimAttachment'
    if animatedScenegraphNode.hasAttachment("AnimAttachment"):
        animAttachment = animatedScenegraphNode.getAttachment("AnimAttachment")
        animationRoot = vrFieldAccess(vrFieldAccess(animAttachment).getFieldContainer("animationRoot"))
        # the animationRoot links to all animations that refer to this scenegraph node
        # access to multiple nodes through the vrFieldAccess is only possible via IDs
        ids = animationRoot.getMFieldContainerId("children")
        # iterate over all animations of this scenegraph node
        for animationNode in [toNode(id) for id in ids]:
            if not animationNode.isValid():
                print(f"Skipping invalid animation node {animationNode}")
                continue
            # access vrNodePtr from animation graph
            print(f"{animatedScenegraphNode.getType()} '{animatedScenegraphNode.getName()}' with ID {animatedScenegraphNode.getID()} has {animationNode.getType()} '{animationNode.getName()}' with ID {animationNode.getID()}")
            animations.append(animationNode)
    return animations


animatedNode = getSelectedNode()
# clip that should receive the selected node's animation blocks
clipName = "Clip"
clip = findAnimClip(clipName)
for animation in getAnimationsFromNode(animatedNode):
    success = addToAnimClip(clip, animation, 0)
    if success:
        print(f"Successfully added {animation.getType()} '{animation.getName()}' to {clip.getType()} '{clip.getName()}'")
    else:
        print(f"Failed to add {animation.getType()} '{animation.getName()}' to {clip.getType()} '{clip.getName()}'")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Let me know if there's a better solution.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 18:08:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/11968170#M3133</guid>
      <dc:creator>clemens_schlicker_audi</dc:creator>
      <dc:date>2023-05-16T18:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: addToAnimClip()</title>
      <link>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/12616307#M3134</link>
      <description>&lt;P&gt;Hi Clemens,&lt;/P&gt;&lt;P&gt;you are writing: "&lt;SPAN&gt;The object has to come from the vrAnimWidgets for this function to work correctly."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I guess you mean it has to come from the&amp;nbsp;scenegraph, thats why you provide your function with the field access, no?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;BTW: Your workaround is working great!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In 2024.1, the nodePtr provided by vrAnimWidgets.findAnimClip is still not usable in&amp;nbsp;vrAnimWidgets.addToAnimClip.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This makes no sense at all.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 14:49:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/12616307#M3134</guid>
      <dc:creator>andreasK3K4G</dc:creator>
      <dc:date>2024-03-05T14:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: addToAnimClip()</title>
      <link>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/12616495#M3135</link>
      <description>&lt;P&gt;Hi Andreas,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unfortunately, your code example doesn't work on its own&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;syntax error due to a missing bracket&lt;/LI&gt;&lt;LI&gt;'&lt;EM&gt;self&lt;/EM&gt;'-reference without being in a class&lt;/LI&gt;&lt;LI&gt;code requires a certain setup in the VRED editor&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;without some adjustments I was able to replicate your issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A few notes (as far as I understand the VRED API)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;A vrNodePtr or a vrdNode can exist in any node graph.&lt;/LI&gt;&lt;LI&gt;you can create a vrNodePtr (e.g. with toNode) with any integer, but only certain node's IDs are valid&lt;/LI&gt;&lt;LI&gt;you can try to locate a vrdNode (e.g. with vrNodeService.getNodeFromId) with any integer, but only certian node's IDs are valid&lt;/LI&gt;&lt;LI&gt;If you ask the &lt;STRONG&gt;scene&lt;/STRONG&gt; graph about the name of an &lt;STRONG&gt;animation&lt;/STRONG&gt; node, answers can't be valid.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;In your case,&amp;nbsp;&lt;EM&gt;new_anim_block_ptr&lt;/EM&gt; is a node from the &lt;STRONG&gt;animation&lt;/STRONG&gt; graph and you try to locate a &lt;STRONG&gt;scene&lt;/STRONG&gt; graph node with its ID. That's why the &lt;EM&gt;new_anim_block_vrdnode&lt;/EM&gt; is invalid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Select a scene node and look at the node editor. The selected node's ID is mentioned at the top entry.&lt;/P&gt;&lt;P&gt;But the node refers to &lt;EM&gt;many&lt;/EM&gt;&amp;nbsp;other nodes, all with their own IDs (all mentioned in brackets).&lt;/P&gt;&lt;P&gt;Your scene node has attachments, the 'AnimAttachment' as an ID, the AnimNode has an ID, ...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's not that easy &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 14:53:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/12616495#M3135</guid>
      <dc:creator>clemens_schlicker_audi</dc:creator>
      <dc:date>2024-03-05T14:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: addToAnimClip()</title>
      <link>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/12616521#M3136</link>
      <description>To check if functions vrAnimWidgets.findAnimClip or findAnimBlock have actually found a clip or block node with the provided name, you should use returned_node_ptr.isValid(). The functions always return a vrNodePtr object, also if no such node could be found. If it is not found, the node will then report that it is not valid and have ID 0.</description>
      <pubDate>Tue, 05 Mar 2024 15:01:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/12616521#M3136</guid>
      <dc:creator>sinje_thiedemann</dc:creator>
      <dc:date>2024-03-05T15:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: addToAnimClip()</title>
      <link>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/12616664#M3137</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;yeah the code was just a snipped, i delete it here, it is not working on its own.&lt;/P&gt;&lt;P&gt;Thanks, i could get the renaming done.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another question comes up:&lt;/P&gt;&lt;P&gt;Is there a way to check if an animation block already exist in a animation clip?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 15:30:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vred-forum/addtoanimclip/m-p/12616664#M3137</guid>
      <dc:creator>andreasK3K4G</dc:creator>
      <dc:date>2024-03-05T15:30:53Z</dc:date>
    </item>
  </channel>
</rss>

