AttributeError: 'list' object has no attribute 'FindTrack'



  • Hi, I am trying to transfer pos of one obj on the other obj but I am getting this error AttributeError: 'list' object has no attribute 'FindTrack'

    I am not sure how to sort it out.
    Thanks for any help

    import c4d
    #Welcome to the world of Python
    
    desc_x = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
                        c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))
    
    desc_y = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION,c4d.DTYPE_VECTOR, 0),  
                        c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))
        
    desc_z = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
                        c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0))
    
    def createPositionTracks(object):
        
        trackPosX = object.FindTrack(desc_x)
        trackPosY = object.FindTrack(desc_y)
        trackPosZ = object.FindTrack(desc_z)
        
        
        if trackPosX is None:  
            track = c4d.CTrack(object, desc_x)
            object.InsertTrackSorted(track)
            
        if trackPosY is None:  
            track = c4d.CTrack(object, desc_y)
            object.InsertTrackSorted(track)
            
        
        if trackPosZ is None:
            track = c4d.CTrack(object, desc_z)
            object.InsertTrackSorted(track)
            
    def setPositionKey(object, time, pos):
        
        trackPosX = object.FindTrack(desc_x)
        trackPosY = object.FindTrack(desc_y)
        trackPosZ = object.FindTrack(desc_z)
        
        curvePosX = trackPosX.GetCurve()
        curvePosY = trackPosY.GetCurve()
        curvePosZ = trackPosZ.GetCurve()
        
        keydict = curvePosX.AddKey(time)
        key = keydict["key"]
        key.SetValue(curvePosX,pos.x)
       
        keydict = curvePosY.AddKey(time)
        key = keydict["key"]
        key.SetValue(curvePosY,pos.y)
       
        keydict = curvePosZ.AddKey(time)
        key = keydict["key"]
        key.SetValue(curvePosZ,pos.z)
        
        return True
        
    def main():
        
        source = [c4d.ID_USERDATA,1]
        target = [c4d.ID_USERDATA,2]
        offset = [c4d.ID_USERDATA,3]
        
        if source is not None and target is not None:
            t = doc.GetTime()
            createPositionTracks(target)
            setPositionKey(target,t,source.GetAbsPos() + offset)
            
    


  • Hi,

    well, that means that you try invoke FindTrack() on a list object, which will cause the exception, as the list type has no method called FindTrack(). I assume you meant to call BaseList2D.FindCTrack() ?

    Apart from that typo in the method name, you also wrote target = [c4d.ID_USERDATA,2] where you probably meant to write target = some_node[c4d.ID_USERDATA,2], which makes target a list and not a BaseList2D as you probably intended.

    Cheers
    zipit



  • Hi Zipit,

    Thanks for reply. Yes I have made a mistake typing FindTrack(). It should be FindCTrack().
    Can you explain what do you mean by some_node?
    Thanks again:)



  • when I having target = op[c4d.ID_USERDATA,2] it;s coming with this error : AttributeError: parameter access failed



  • Ok I figured it out :)

    import c4d
    #Welcome to the world of Python
    
    desc_x = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
                        c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))
    
    desc_y = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION,c4d.DTYPE_VECTOR, 0),  
                        c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))
        
    desc_z = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
                        c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0))
    
    def createPositionTracks(object):
        
        trackPosX = object.FindCTrack(desc_x)
        trackPosY = object.FindCTrack(desc_y)
        trackPosZ = object.FindCTrack(desc_z)
        
        
        if trackPosX is None:  
            track = c4d.CTrack(object, desc_x)
            object.InsertTrackSorted(track)
            
        if trackPosY is None:  
            track = c4d.CTrack(object, desc_y)
            object.InsertTrackSorted(track)
            
        
        if trackPosZ is None:
            track = c4d.CTrack(object, desc_z)
            object.InsertTrackSorted(track)
            
    def setPositionKey(object, time, pos):
        
        trackPosX = object.FindCTrack(desc_x)
        trackPosY = object.FindCTrack(desc_y)
        trackPosZ = object.FindCTrack(desc_z)
        
        curvePosX = trackPosX.GetCurve()
        curvePosY = trackPosY.GetCurve()
        curvePosZ = trackPosZ.GetCurve()
        
        keydict = curvePosX.AddKey(time)
        key = keydict["key"]
        key.SetValue(curvePosX,pos.x)
       
        keydict = curvePosY.AddKey(time)
        key = keydict["key"]
        key.SetValue(curvePosY,pos.y)
       
        keydict = curvePosZ.AddKey(time)
        key = keydict["key"]
        key.SetValue(curvePosZ,pos.z)
        
        return True
        
    def main():
        o = op.GetObject()
        source = o[c4d.ID_USERDATA,1]
        target = o[c4d.ID_USERDATA,2]
        offset = o[c4d.ID_USERDATA,3]
        
        if source is not None and target is not None:
            t = doc.GetTime()
            createPositionTracks(target)
            setPositionKey(target,t,source.GetAbsPos() + offset)
            
    


  • So Did I missed the actual link to my null object?



  • Hi,

    woah, a lot of text here ;) Jeah, op would be a candidate for a node. I can't tell you that, you have to know where you want to get your data from.

    I am also not quite sure, what your last question means.

    Cheers
    zipit



  • I have my user date applied on to the null plus python tag is also sitting on the null.
    So I think in def main():
    I need to get the tag first and then null in order to read the data from userdata......
    That's make sense for me anyway)
    Thanks



  • Hello and thanks for the question,

    Nice you end up by solving your issue, i would like to point you to our example on Github where you will find the same kind of script but with undo system and cloning the whole track, removing the existing one (if it does)

    For your next threads, please help us keeping things organised and clean. I know it's not your priority but it really simplify our work here.

    I've added the tags and marked this thread as a question so when you considered it as solved, please change the state :)

    Cheers
    Manuel.



  • @m_magalhaes

    Thanks.

    Next time I will follow the instruction.
    Thanks