ZeroAxis R23 help



  • 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()
    


  • 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()
    


  • Hi x_nerve,

    thank you very much it does work now like expected!

    Best,
    Peter



  • 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



  • This post is deleted!


  • 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



  • 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()
    


  • 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 :D ):

    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()
    


  • 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



  • 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


Log in to reply