Problems with c4d.utils.Neighbor



  • On 08/02/2013 at 08:57, xxxxxxxx wrote:

    Hi everyone,

    I want to convert an edge to a point selection and then get the corresponding neighboring polys.
    If I want to use the neighbor class it doesn't seem to work properly. If I try to initialize it the following way

        obj = doc.GetActiveObject()
        nb = c4d.utils.Neighbor
        nb.Init(obj,None)
        poly_a, poly_b = nb.GetEdgePolys(point_a,point_b)
    

    the console says:

    TypeError: descriptor 'Init' requires a 'c4d.utils.Neighbor' object but received a 'c4d.PolygonObject'
    

    Though the SDK clearly states that Init requires a PolygonObject and optionally a BaseSelect.

    What am I doing wrong here? Might be a stupid question, but I didn't use python for a long time in Cinema and the SDK always gives me headaches...

    Kind Regards



  • On 08/02/2013 at 08:59, xxxxxxxx wrote:

    You did not instantiate the Neighbor class. You just assigned the class itself to a new variable.

    nb = c4d.utils.Neighbor()
    

    The reason for the error message is, that you can call the Init() function the procedural way, too:

    nb = c4d.utils.Neighbor()
      
    nb.Init(obj, None)
    # same as
    c4d.utils.Neighbor.Init(nb, obj, None)
    


  • On 08/02/2013 at 10:50, xxxxxxxx wrote:

    you can also compute the indices for yourself.

    subindex = edge_index%4
    cpoly = obj.GetPolygon((edge_index - subindex )/4)
      
    if subindex  == 0:
    	a, b = cpoly.a, cpoly.b
    if subindex  == 1:
    	a, b = cpoly.b, cpoly.c
    if subindex  == 2:
    	a, b = cpoly.c, cpoly.d
    if subindex  == 3:
    	a, b = cpoly.d, cpoly.a
    

    you will have to do half the work with the neighbour class anyway :)

    edit: assuming that cpoly.c != cpoly.d, if not 2 is a,b = cpoly.c, cpoly.a



  • On 09/02/2013 at 04:34, xxxxxxxx wrote:

    Works fine now. Thank you.🙂 The small mistakes...😲


Log in to reply