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

    ZeroAxis R23 help

    Cinema 4D SDK
    python r23
    3
    11
    1.6k
    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.
    • P
      peXel
      last edited by Manuel

      Hi There,

      I had for R21 this script. It was working like reset PSR, but for the object axis only.
      Could anyone help me please to get this great little helper back for the R23?

      Thank you very much,

      Best,
      Peter

      import c4d
      
      from c4d import Vector as V
      
      def main():
      
          if op is None or not op.CheckType(c4d.Opoint):
              return False
      
          ObjMatrix = op.GetMg()
      
          ObjPoints = op.GetAllPoints()
      
          Pcount = op.GetPointCount()
      
          doc.StartUndo()
          doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
          op.SetAbsRot(V(0))
          op.SetAbsPos(V(0))
          op.Message(c4d.MSG_UPDATE)
          NewMatrix = op.GetMg()
      
          for point in xrange(Pcount):
              op.SetPoint(point,~NewMatrix*ObjMatrix*ObjPoints[point])
      
          op.Message(c4d.MSG_UPDATE)
          c4d.EventAdd()
          doc.EndUndo()
      
      if __name__=='__main__':
      
          main()
      
      1 Reply Last reply Reply Quote 0
      • X
        x_nerve
        last edited by

        Hi:

        Your code should run in R23. The following provides additional reset axis code.Unless you're talking about point location resetting, which is non-destructive modeling, and if you want to implement it, you'll need to consider point deletion, etc. It's recommended to use the Python plug-in or the Python tag.

        import c4d
        
        #from c4d import Vector as V
        
        def main():
            #if op is None or not op.CheckType(c4d.Opoint):
                #return False
        
            ObjMatrix = op.GetMg()
            ObjMatrix.off = c4d.Vector(0, 0, 0)
        
            #ObjPoints = op.GetAllPoints()
        
            #Pcount = op.GetPointCount()
        
            doc.StartUndo()
            doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
            #op.SetAbsRot(V(0))
            #op.SetAbsPos(V(0))
            op.Message(c4d.MSG_UPDATE)
            #NewMatrix = op.GetMg()
        
            point = [ op.GetAllPoints()[i] * op.GetMg() * ~ObjMatrix
                        for i in range(op.GetPointCount()) ]
            
            op.SetMg(ObjMatrix)
            op.SetAllPoints(point)
            op.Message(c4d.MSG_UPDATE)
            c4d.EventAdd()
            doc.EndUndo()
        
        if __name__=='__main__':
            main()
        
        1 Reply Last reply Reply Quote 0
        • P
          peXel
          last edited by

          Hi x_nerve,

          thank you very much it does work now like expected!

          Best,
          Peter

          1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand
            last edited by ferdinand

            Hi @peXel,

            thank you for reaching out to us and thanks to @x_nerve for jumping in. Can we considered this question to be solved or are there any follow up questions?

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • P
              peXel
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • P
                peXel
                last edited by

                Hi There,

                the script is not working properly sadly. It does set the axis back to 0,0,0, but it stays it's orientation.
                It needs to copy the axis orientation same as the object one up in hierarchy, see original code.
                What did change inside the SDK and how do I get this behavior back again?

                Thank you very much for your help, it's a great helper for everybody if it does work again

                Best,
                Peter

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

                  Hi:

                  @peXel

                  Sorry, I was negligent. The reset code of rotation and zoom is as follows.

                  import c4d
                  
                  #from c4d import Vector as V
                  
                  def main():
                      
                      if op.CheckType(c4d.Opolygon):
                  
                          #if op is None or not op.CheckType(c4d.Opoint):
                              #return False
                      
                          ObjMatrix = c4d.Matrix() #op.GetMg()
                      
                          #ObjPoints = op.GetAllPoints()
                      
                          #Pcount = op.GetPointCount()
                      
                          doc.StartUndo()
                          doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
                          #op.SetAbsRot(V(0))
                          #op.SetAbsPos(V(0))
                          op.Message(c4d.MSG_UPDATE)
                          #NewMatrix = op.GetMg()
                      
                          point = [ op.GetAllPoints()[i] * op.GetMg() * ~ObjMatrix
                                      for i in range(op.GetPointCount()) ]
                      
                          op.SetMg(ObjMatrix)
                          op.SetAllPoints(point)
                          op.Message(c4d.MSG_UPDATE)
                          c4d.EventAdd()
                          doc.EndUndo()
                          
                      else:
                          doc.StartUndo()
                          doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
                  
                          op.SetMg(c4d.Matrix())
                  
                          op.Message(c4d.MSG_UPDATE)
                          c4d.EventAdd()
                          doc.EndUndo()
                  
                  if __name__=='__main__':
                      main()
                  
                  1 Reply Last reply Reply Quote 0
                  • ferdinandF
                    ferdinand @peXel
                    last edited by ferdinand

                    Hi @peXel,

                    thank you for reaching out to us. Unfortunately it is not quite clear to me what you expect from this script and what you do consider to be not working in your first version. If your request was simply about the NameError your first script is throwing in R23, that is because Cinema switched from Python 2.7 to Python 3.7. Which in turn means that xrange is finally gone now in Cinema's Python. You have to use range now (which does not really change much for you). Below you will find a "fixed" version (I just removed the x from xrange 😄 😞

                    Cheers,
                    Ferdinand

                    import c4d
                    from c4d import Vector as V
                    
                    def main():
                    
                        if op is None or not op.CheckType(c4d.Opoint):
                            return False
                    
                        ObjMatrix = op.GetMg()
                        ObjPoints = op.GetAllPoints()
                        Pcount = op.GetPointCount()
                    
                        doc.StartUndo()
                        doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
                        op.SetAbsRot(V(0))
                        op.SetAbsPos(V(0))
                        op.Message(c4d.MSG_UPDATE)
                        NewMatrix = op.GetMg()
                    
                        for point in range(Pcount):
                            op.SetPoint(point,~NewMatrix*ObjMatrix*ObjPoints[point])
                    
                        op.Message(c4d.MSG_UPDATE)
                        c4d.EventAdd()
                        doc.EndUndo()
                    
                    if __name__=='__main__':
                        main()
                    

                    MAXON SDK Specialist
                    developers.maxon.net

                    1 Reply Last reply Reply Quote 0
                    • P
                      peXel
                      last edited by

                      Hi Zipit,

                      yes that's it, now it's working like expected. Should be integrated in our main C4D core, like reset PSR
                      Thanks for solving it!
                      Yes it was just removing the x, because I don't have any clue about Python 2.7 or 3.7 or even changes sadly.
                      It's really a pitty that there's no convert 2.7 to 3.7 script button for nonprogrammers 🙂

                      Best,
                      Peter

                      1 Reply Last reply Reply Quote 0
                      • ferdinandF
                        ferdinand
                        last edited by ferdinand

                        Hi @peXel,

                        I am happy to help 😉

                        It's really a pitty that there's no convert 2.7 to 3.7 script button for nonprogrammers 🙂

                        Actually there is one 😉 It even comes with Python. We have also a migration guide.

                        Cheers,
                        Ferdinand

                        MAXON SDK Specialist
                        developers.maxon.net

                        1 Reply Last reply Reply Quote 0
                        • P
                          peXel
                          last edited by

                          That are great news, but sadly I am not a Phyton User

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