Last active
December 15, 2015 10:59
-
-
Save chadcooper/5249714 to your computer and use it in GitHub Desktop.
Getting the actual size of an object in Vue programmatically isn’t as easy as you’d think. You essentially have to get the BoundingBox of the object and work with that. So here we have a wind turbine object, and we have selected the pole and need to know (programmatically) how tall this pole really is. If you look at that z-value in the size pro…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_object_size(vue_object): | |
""" Takes a input Vue object, gets it's bounding box, then does the | |
math to get the XYZ size of the object. Returns a X,Y,Z tuple of | |
the object size. | |
""" | |
bounding_box = vue_object.GetBoundingBox() | |
bb_min = bounding_box.GetMin() | |
bb_max = bounding_box.GetMax() | |
# Build our tuple of object XYZ size | |
object_size = (bb_max[0] - bb_min[0], bb_max[1] - bb_min[1], | |
bb_max[2] - bb_min[2]) | |
return object_size | |
>>> col = GetSelectedObjectByIndex(0) | |
>>> col | |
>>> scale = col.GetScale() | |
>>> print scale | |
(1.0, 1.0, 1.0) | |
>>> bb = col.GetBoundingBox() | |
>>> print bb | |
<VuePython.VUEBoundingBox; proxy of <Swig Object of type 'VUEBoundingBox *' at 0x0000000017884360> > | |
>>> print bb.GetMax() | |
(4024.3647753980426, -9026.798040135702, 216.7754350035159) | |
>>> print bb.GetMin() | |
(4019.764775016573, -9031.39804242452, 140.730600866553) | |
>>> | |
# Do the math | |
>>> z_size = bb.GetMax()[2] - bb.GetMin()[2] | |
>>> print z_size | |
76.044834137 | |
>>> | |
# Make a dict out of em | |
>>> d = {} | |
>>> d['Min'] = bb.GetMin() | |
>>> d['Max'] = bb.GetMax() | |
>>> print d | |
{'Max': (4024.3647753980426, -9026.798040135702, 216.7754350035159), 'Min': (4019.764775016573, -9031.39804242452, 140.730600866553)} | |
>>> | |
>>> print d['Max'][2] | |
216.775435004 | |
>>> | |
# | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment