Get X,Y,Z of active_model with Ruby
-
Hi, I swear I do a lot of research about this issue but can't find anything or can't understanding anything about what I've found.
Just need to get the value of x,y and z of a active_model, because i'm gonna to export the project in json format and need when import to continue with they respective position.
Ex:
my_model['x'] = Sketchup.active_model.getX
my_model['y'] = Sketchup.active_model.getY
my_model['z'] = Sketchup.active_model.getZthe getX getY and getZ is what i need.
If someone could help me or just link a topic about this explanation, will help me a lot.
thanks so much guys.
-
Your cod-example is very very unclear.

What "XYZ" of the 'model' are you seeking ?
Please explain yourself better...I'll throw in some ideas that might help, meanwhile...
bounds = Sketchup.active_model.bounds center = bounds.center ### the center point of the model's bounding box, which includes XYZ coordinates. min = bounds.min ### the minimum point of the model's bounding box, which includes XYZ coordinates. max = bounds.max ### the maximum point of the model's bounding box, which includes XYZ coordinates. xdim = bounds.width ### the width [X/red] dimension of the model's bounding box, in inches. ydim = bounds.height ### the height [Y/green] dimension of the model's bounding box, in inches. zdim = bounds.depth ### the depth [Z/blue] dimension of the model's bounding box, in inches. ### to get the three x,y,z values in inches [aka Float] of a point3d reference use... x,y,z = point.to_a ### to get a single coordinate value in current model-units [aka Length] of a point3d reference use... x = point.x ### etc... there are lots of permutations... -
@tig said:
Your cod-example is very very unclear.

What "XYZ" of the 'model' are you seeking ?
Please explain yourself better...I'll throw in some ideas that might help, meanwhile...
bounds = Sketchup.active_model.bounds > center = bounds.center ### the center point of the model's bounding box, which includes XYZ coordinates. > min = bounds.min ### the minimum point of the model's bounding box, which includes XYZ coordinates. > max = bounds.max ### the maximum point of the model's bounding box, which includes XYZ coordinates. > xdim = bounds.width ### the width [X/red] dimension of the model's bounding box, in inches. > ydim = bounds.height ### the height [Y/green] dimension of the model's bounding box, in inches. > zdim = bounds.depth ### the depth [Z/blue] dimension of the model's bounding box, in inches. > ### to get the three x,y,z values in inches [aka Float] of a point3d reference use... > x,y,z = point.to_a > ### to get a single coordinate value in current model-units [aka Length] of a point3d reference use... > x = point.x > ### etc... there are lots of permutations... >TIG, first of all thanks for reply.
I misunderstood the whole thing.
The "model" I've mentioned actually is the entity that contain all children entities.What I do was something like that:
if not is_children? position; { x; entity.transformation.origin.x, y; entity.transformation.origin.y, z; entity.transformation.origin.x } endThanks again, the bound method that you've explained, resolved a few other things.
-
The origin of the
active_modelis[0,0,0], which is referenced asORIGIN.If the model came from Google Earth, then the real world co-ordinates (in inches) will be in the
GeoReferenceattribute dictionary.mdl = Sketchup;;active_model if mdl.georeferenced? && !mdl.attribute_dictionary('GeoReference',false).nil? [ mdl.get_attribute('GeoReference', 'ModelTranslationX', 0.0), mdl.get_attribute('GeoReference', 'ModelTranslationY', 0.0), mdl.get_attribute('GeoReference', 'ModelTranslationZ', 0.0) ] else ORIGIN.to_a end -
@dan rathbun said:
The origin of the
active_modelis[0,0,0], which is referenced asORIGIN.If the model came from Google Earth, then the real world co-ordinates (in inches) will be in the
GeoReferenceattribute dictionary.> mdl = Sketchup;;active_model > if mdl.georeferenced? && > !mdl.attribute_dictionary('GeoReference',false).nil? > [ > mdl.get_attribute('GeoReference', 'ModelTranslationX', 0.0), > mdl.get_attribute('GeoReference', 'ModelTranslationY', 0.0), > mdl.get_attribute('GeoReference', 'ModelTranslationZ', 0.0) > ] > else > ORIGIN.to_a > end >Or
Model.point_to_utm
http://www.sketchup.com/intl/en/developer/docs/ourdoc/model#point_to_utm
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement