I think what you're looking for is called Axis-Aligned Bounding Box. In the simple case, if you have a single object you'd like to know the bounding box for, you could build a transformation matrix out of those coordinates, and multiply that with the transform of your object. That would give you a new transformation matrix, aligned to that object. However that would stop working once you move vertices around or when there is more than one object involved.
On Mon, 3 Dec 2018 at 23:38, James Kim <[email protected]> wrote: > I'm trying to get the size of any object using the bounding box > > def getSizes(self): > > objSize = cmds.ls(sl = True) > > > > #get the bounding box of x,y,z > sizeMinX = cmds.getAttr(objSize[0] + '.boundingBoxMinX') > sizeMaxX = cmds.getAttr(objSize[0] + '.boundingBoxMaxX') > sizeMinY = cmds.getAttr(objSize[0] + '.boundingBoxMinY') > sizeMaxY = cmds.getAttr(objSize[0] + '.boundingBoxMaxY') > sizeMinZ = cmds.getAttr(objSize[0] + '.boundingBoxMinZ') > sizeMaxZ = cmds.getAttr(objSize[0] + '.boundingBoxMaxZ') > > #get the sizes > if (sizeMinX < 0 and sizeMaxX > 0) or (sizeMaxX < 0 and sizeMinX > 0): > sizeX = abs(sizeMinX) + abs(sizeMaxX) > else: > sizeX = abs(sizeMaxX) - abs(sizeMinX) > > > if (sizeMinY < 0 and sizeMaxY > 0) or (sizeMaxY < 0 and sizeMinY > 0): > sizeY = abs(sizeMinY) + abs(sizeMaxY) > else: > sizeY = abs(sizeMaxY) - abs(sizeMinY) > > > if (sizeMinZ < 0 and sizeMaxZ > 0) or (sizeMaxZ < 0 and sizeMinZ > 0): > sizeZ = abs(sizeMinZ) + abs(sizeMaxZ) > else: > sizeZ = abs(sizeMaxZ) - abs(sizeMinZ) > > > This works fine when the object is perpendicular to the x,y, or z axis > however when i rotate the object it gives me different sizes. for example > if i have a cube(10,10,10) it will return these values normally but when i > rotate the object it will give me different values. > Is there a way to get the bounding box of the object not in world space? > > -- > 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/3cab85d2-1c4e-4ae5-9ca6-15be3f3307a5%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/3cab85d2-1c4e-4ae5-9ca6-15be3f3307a5%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAFRtmOCp4QK8Y1fzwCp2sAH5ucc%2BO6hR%3D32ZfnJyptxhY5Wdmg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
