sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Get X,Y,Z of active_model with Ruby

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 486 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • kimpastroK Offline
      kimpastro
      last edited by

      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.getZ

      the 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.

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • kimpastroK Offline
          kimpastro
          last edited by

          @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
          }
          end
          
          

          Thanks again, the bound method that you've explained, resolved a few other things.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            The origin of the active_model is [0,0,0], which is referenced as ORIGIN.

            If the model came from Google Earth, then the real world co-ordinates (in inches) will be in the GeoReference attribute 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
            
            

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @dan rathbun said:

              The origin of the active_model is [0,0,0], which is referenced as ORIGIN.

              If the model came from Google Earth, then the real world co-ordinates (in inches) will be in the GeoReference attribute 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

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement