Results 1 to 7 of 7
  1. #1

    How to define the order of Objects ?

    Hi

    Liero made that great "Export to SVG" Script.

    My question is, how to get the correct order of Objects depending on how they lay on each other ?
    At the moment the Script measures only the distance to the camera of each Object which results in a incorrect order.
    See here.

    Is there any other way to detect the correct order ?
    Maybe a more "physical" way ?
    I mean basically the Objects are already correct in the Viewport and Blender already should "know" how the Objects lay on and to each other. From this knowledge the Script could take the correct order for the SVG Export... maybe I'm wrong.

    What do you mean ?

    Kind regards
    Alain
    Artwork - Farnsworth House
    Equipment - Intel Pentium 2.8 GHz 2 Cores, 8 GB RAM, GeForce GTX TITAN 8GB, Blender 2.72, Win 7 64 Bit, NVIDIA Driver current version



  2. #2
    why don't you ask Liero?


    I think the order is the way they are created and added to the list of objects !



    happy bl
    Nice 3D models = 25 % K.I.S.S + 25 % common sense + 25 % Inspiration + 25 % Knowledge
    Win 10 64 bits / Thanks and a Happy 2.79 with Cycles



  3. #3
    Member proxe's Avatar
    Join Date
    Mar 2012
    Location
    Unknown
    Posts
    921
    Not sure what you mean by the order the objects lay on each other, one way to sort objects based on the order is to create a list of lists of the objects you want, with the axis in question as the first value (i.e. object.location[0]) of each sub list then to sort the main list with .sort or sorted()
    :: proxeIO :: Addons :: GitHub ::



  4. #4
    @proxe
    Thanks for the hint.
    How can I sort "list.sort()" by the first item and then by the second item and then by the third item and so on .. ?

    Edit:
    It seems that it does it automatically that way, right ?

    Edit 2:
    How can I force .sort to sort only one specific item ?
    Last edited by Alain; 24-Sep-16 at 00:40.
    Artwork - Farnsworth House
    Equipment - Intel Pentium 2.8 GHz 2 Cores, 8 GB RAM, GeForce GTX TITAN 8GB, Blender 2.72, Win 7 64 Bit, NVIDIA Driver current version



  5. #5
    Member proxe's Avatar
    Join Date
    Mar 2012
    Location
    Unknown
    Posts
    921
    Something like this?

    Code:
    for i in range(3):
      list.sort(key=lambda x: x[i])
    range could be fed with the list length with len(list)

    If you want to use the second item for sorting; list.sort(key=lambda x: x[1])
    Last edited by proxe; 24-Sep-16 at 01:34.
    :: proxeIO :: Addons :: GitHub ::



  6. #6
    Thanks, it works.

    Other question:
    How can I go through each vertex of a Meshobject and storing only the distance from the vertex to the Camera Locations which is the closest to the Camera ?

    Liero made this nice Export SVG Script. And I'm trying to change this part to my needs.

    Code:
                # remover objetos con coordenadas no validas
                sel_valid = [o for o in sel if str_xy(o.matrix_world.to_translation())[4]]
    
                # ordenar los objetos segun distancia al visor -usa origen de objetos-
                if wm.order_obj:
                    distancia = [(round((cam_co-o.location).length_squared,5), round(o.location.z,5), o.name) for o in sel_valid]
                    distancia.sort(key=lambda x: x[1])
                    print (distancia)
                    sel_valid = [sce.objects[d[2]] for d in distancia]
    Artwork - Farnsworth House
    Equipment - Intel Pentium 2.8 GHz 2 Cores, 8 GB RAM, GeForce GTX TITAN 8GB, Blender 2.72, Win 7 64 Bit, NVIDIA Driver current version



  7. #7
    For selected mesh objects, nearest vertex per object to camera object.
    nearest_first variable is the list of object names, starting the nearest object to the camera.

    Code:
    import bpy
    
    
    def distance(loc0,loc1):
        return (loc0-loc1).length
    
    
    cam = bpy.data.objects['Camera'].location
    obj = {}
    for o in bpy.context.selected_objects:
    
    
        mat = o.matrix_world
        min_dist = min([distance(mat*i.co,cam) for i in o.data.vertices])
        obj[o.name] = min_dist    
    
    
    nearest_first = sorted(obj, key=obj.get)    
    print (nearest_first)
    Last edited by JuhaW; 09-Mar-17 at 05:49.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •