Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to refresh a deleted object link in Python?

    Cinema 4D SDK
    4
    6
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • orestiskonO
      orestiskon
      last edited by m_adam

      Hi all,

      I noticed when I use link fields or in/exclude lists, and I delete an object from the Object Manager, the link field or in/exclude list fails to refresh.

      link_object_refresh_xpresso2.c4d

      Please take a look at the attached example. I have a python node in xpresso which drives the cube along the spline. If you hit play, you will see the cube moving across the spline.

      Now stop the playback, select the spline and delete it, and hit play again.
      The cube will keep moving along the path as if nothing changed.

      How can I refresh the link's information, so it will output "None" instead of a non-existent object?

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi @orestiskon this shouldn't happens, looks like an issue within Xpresso which seems to do a copy of the spline, so two solutions:

        1- Check the document of the spline like so

        import c4d
        
        
        def main():
            global spline
            global obj
            global time
        
            if spline.GetDocument() is not None:
                SplineHelp = c4d.utils.SplineHelp()
                SplineHelp.InitSpline(spline)
                offset = SplineHelp.GetOffsetFromReal(time, 0)
                pos = SplineHelp.GetPos(offset)
                obj.SetAbsPos(pos)
        

        And the other solution is to use python to retrieve the link and not anymore xpresso

        import c4d
        
        
        def main():
            global obj
            global time
        
            spline = op.GetNodeMaster().GetOwner()[c4d.ID_USERDATA,1]
        
            if spline is not None:
                SplineHelp = c4d.utils.SplineHelp()
                SplineHelp.InitSpline(spline)
                offset = SplineHelp.GetOffsetFromReal(time, 0)
                pos = SplineHelp.GetPos(offset)
                obj.SetAbsPos(pos)
        

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • orestiskonO
          orestiskon
          last edited by

          Thanks Maxime, that's helpful.
          I already went with the second solution as a workaround, since I noticed it happened when exporting the link with xpresso as well. I wanted to avoid unnecessary python nodes so I was hoping there was a function to force-refresh the object to update its lists and links, but it's good there are workarounds for it.

          N 1 Reply Last reply Reply Quote 0
          • N
            nophoto @orestiskon
            last edited by nophoto

            @orestiskon

            In XPresso you should pay attention to the order of the nodes in the X-Manager. The nodes should be arranged in the order in which they where calcultated.

            In your scene it looks looks like this:
            Bildschirmfoto 2020-08-25 um 22.14.25.jpg

            If the python nodes is moved to the end of the list...
            Bildschirmfoto 2020-08-25 um 22.14.40.jpg
            ...everything works as expected.

            Cheers
            Peter

            orestiskonO 1 Reply Last reply Reply Quote 2
            • orestiskonO
              orestiskon @nophoto
              last edited by orestiskon

              @nophoto Hi Peter.
              I usually do put the nodes in order, especially when there are dependencies that matter.
              However I can't reproduce here that putting them in order fixes the issue. Deleting the spline still doesn't prevent the python node from reading the previous object instead of None, and the Cube still glides on the ghost spline.
              You can check the video for a demonstration:
              https://app.box.com/s/ywuozns0z3ezp83f72q5epxvyl7b89b8

              1 Reply Last reply Reply Quote 0
              • X
                x_nerve
                last edited by x_nerve

                Hi:

                It feels like a good question, otherwise I wouldn't have known that XPresso had this problem.I think your problem is that XPresso Tag adds links to user data.If you add user data links to Python nodes, you will have no problem putting splines in the links.Or drag the spline directly to XPresso manager, output the object, there will be no problem.

                import c4d
                #Welcome to the world of Python
                
                def main():
                    #global spline
                    global obj
                    global time
                
                    spline = op[c4d.ID_USERDATA,1]
                
                    if spline != None:
                        SplineHelp = c4d.utils.SplineHelp()
                        SplineHelp.InitSpline(spline)
                        offset = SplineHelp.GetOffsetFromReal(time, 0)
                        pos = SplineHelp.GetPos(offset)
                        #print(pos)
                        obj.SetAbsPos(pos)
                

                7854567857885.jpg

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post