Here is a bit of old code, that i now can share... using python pymel here, 
think you can look through it and see if it helps you

On Monday, January 2, 2017 at 12:55:10 AM UTC+5:30, [email protected] 
wrote:
>
> Hello, 
>
> ive got a script which duplicates a mesh 10 times. I just want to offset 
> the mesh each time it is duplicated so it lines the meshes up side by side. 
> But in order to do that for any mesh i wanted to use the bounding box info 
> to find the x width of the mesh. 
>
> It has min and max bounding box values and neither seem to represent the 
> correct width of my mesh. How can you even have a min or a max bounding 
> box? surely the bounding box is the exact size of the mesh right? 
>
> anyway, just wanted to ask if this is the correct way to find the width of 
> a mesh 
>
> thanks, 
> Sam 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/d340d911-6464-4fab-b077-50a60de4150d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import pymel.core as pm
import pymel.core.datatypes as dt

class SelectionError(Exception):
    ''' Selection based errors '''
    pass

def getSelection(num=1, flat=True):
    ''' Gets selection based on number specified '''
    sel = pm.ls(sl=1, fl=flat)
    if sel != []:
        if num == -1:
            return sel
        elif num == 1:
            return sel[0]
        else:
            return sel[:num]
    elif sel == []:
        raise SelectionError("Nothing Selected!")


def duplicateArray(objA=None, noCopies=9, direction="+x", adj=0):
    ''' Duplicate Array of Objects '''
    if objA == None:
        objA = getSelection()
    else:
        objA = pm.PyNode(objA)
    if isinstance(objA, pm.nodetypes.Transform):
        result = [objA]
        width = getWidth(objA)
        dup = pm.duplicate(objA)[0]
        result.append(dup)
        if "+x" in direction or "+X" in direction:
            pos = dup.t.get()
            pm.move(pos.x + width[0] + adj, pos.y, pos.z)
        elif "-x" in direction or "-X" in direction:
            pos = dup.t.get()
            pm.move(pos.x - width[0] + adj, pos.y, pos.z)
        if "+y" in direction or "+Y" in direction:
            pos = dup.t.get()
            pm.move(pos.x, pos.y + width[1] + adj, pos.z)
        elif "-y" in direction or "-Y" in direction:
            pos = dup.t.get()
            pm.move(pos.x, pos.y - width[1] + adj, pos.z)
        if "+z" in direction or "+Z" in direction:
            pos = dup.t.get()
            pm.move(pos.x, pos.y, pos.z + width[2] + adj)
        elif "-z" in direction or "-Z" in direction:
            pos = dup.t.get()
            pm.move(pos.x, pos.y, pos.z - width[2] + adj)
        for i in xrange(noCopies-1):
            dup = pm.duplicate(st=True)[0]
            result.append(dup)
        return result

Reply via email to