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

    How to add coordinate into SU api

    Scheduled Pinned Locked Moved Developers' Forum
    20 Posts 5 Posters 2.2k Views 5 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.
    • Z Offline
      zps222
      last edited by

      Hi guys, if I build a model, and I want to export it into google earth, especially want to see it in a certain logitude and latitude, which means to add the coordinate into the modle it self.
      I know to change the KMZ can realize the same function, however, I just want realize it in ruby?
      So anyone can help me? Thank you.

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        If the model has previously been geo-located, look for a model-level attribute_dictionary named "GeoReference". It acts like a Ruby Hash and should contain the Lat and Lon for the model.

        dict = Sketchup.active_model.attribute_dictionary["GeoReference"] p dict.to_a

        There are a number of keys in the dictionary and I don't know exactly what they are used for, but I do believe this is where Google Earth and 3D Warehouse get the model's location data from.

        Hi

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

          What about ??
          Sketchup.active_model.shadow_info['Latitude'] Sketchup.active_model.shadow_info['Longitude']

          I believe these are set by the Model Info > Location feature.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            Maybe you're right, Dan. I remember the GeoReference dictionary isn't created until a model has been Geo Located the first time, so I made the assumption that it was being used. But it may be more complicated than that. (See signature.)

            Hi

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

              Do you mean x=10, y=10 etc... or do you mean real long/lat coordinates?
              If you simply want to move things to x/y/z I suggest you make your new geometry inside a group
              ents=model.active_entities grp=ents.add_group() ent=grp.entities

              your 'ent' now takes the geometry inside the group 'grp'.

              NOW we transform the group

              pt=Geom::point3d.new(10,10,0) tr=Geom::Transformation.new(pt) grp.transform!(tr)

              The 'grp' then moves from where it is to [10,10,0] or whatever coordinates you say in 'pt'

              if you don't want the geometry to remain grouped then add

              grp.explode

              TIG

              1 Reply Last reply Reply Quote 0
              • Z Offline
                zps222
                last edited by

                @tig said:

                Do you mean x=10, y=10 etc... or do you mean real long/lat coordinates?
                If you simply want to move things to x/y/z I suggest you make your new geometry inside a group
                ents=model.active_entities grp=ents.add_group() ent=grp.entities

                your 'ent' now takes the geometry inside the group 'grp'.

                NOW we transform the group

                pt=Geom::point3d.new(10,10,0) tr=Geom::Transformation.new(pt) grp.transform!(tr)

                The 'grp' then moves from where it is to [10,10,0] or whatever coordinates you say in 'pt'

                if you don't want the geometry to remain grouped then add

                grp.explode

                Thanks Tig. But I want to place my model into a real long/latitude coordinate. Not the default one.

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

                  OK ❓ that's even easier... all you have to do is set the long/lat for the model to what you want them to be ?
                  Sketchup.active_model.shadow_info['Latitude']=54.32 Sketchup.active_model.shadow_info['Longitude']=12.34
                  πŸ€“

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • Z Offline
                    zps222
                    last edited by

                    @tig said:

                    OK ❓ that's even easier... all you have to do is set the long/lat for the model to what you want them to be ?
                    Sketchup.active_model.shadow_info['Latitude']=54.32 Sketchup.active_model.shadow_info['Longitude']=12.34
                    πŸ€“

                    Yes, Tig!! It works !!

                    Thank you very very much~~

                    Have a good day~~

                    1 Reply Last reply Reply Quote 0
                    • Z Offline
                      zps222
                      last edited by

                      @tig said:

                      OK ❓ that's even easier... all you have to do is set the long/lat for the model to what you want them to be ?
                      Sketchup.active_model.shadow_info['Latitude']=54.32 Sketchup.active_model.shadow_info['Longitude']=12.34
                      πŸ€“

                      Another question is, if I build a model, and want to set the bottom of the model at a centain depth in the ocean, how to manage it?
                      Thanks

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

                        FYI

                        • Positive Latitudes are North of the equator; Negative are South.
                        • Positive Longitudes are East of the Prime Meridian; Negative are West.

                        @zps222 said:

                        Another question is, if I build a model, and want to set the bottom of the model at a centain depth in the ocean, how to manage it?

                        First, open your Preferences dialog. Go to the Extensions panel.
                        Check (turn ON,) the "Google Earth Ocean Modeling" extension.

                        Then browse to the Sketchup directory: "Plugins/Ocean" and read the ruby script 'ocean.rb'

                        It appears that you will need to move everything in your model, either:

                        • above the [0,0,0] origin, if you wish to place the model relative to the ocean floor, OR* below the [0,0,0] origin, if you wish to place the model relative to the ocean surface.
                          You will need to use the "Model on Ocean Floor" menu option that the Ocean extension adds to the Plugins menu.. BEFORE you upload the model to Google Earth.

                        I'm not here much anymore.

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

                          zps222, please wrap your code in a code block.

                          Edit your post. Hilite the entire ruby text, and click the code button on the Edit Toolbar.
                          .

                          I'm not here much anymore.

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

                            1. Wrap your script in a unique module. 1. Do NOT paste the entire 'ocean.rb' into your script. Instead, use require to make sure it's loaded.
                            
                            module Zps222
                              module OceanTest
                                require('Ocean/ocean.rb')
                            
                                # your code
                            
                                # do this BEFORE exporting model for surface ref
                                # change the 'if' to 'unless' for bottom ref
                                toggle_ocean() if is_on_floor_bottom()
                            
                                Sketchup.active_model.export("c;/2.kmz",false)
                            
                                UI.openURL("c;/2.kmz")
                            
                              end
                            end
                            
                            

                            Also you need to start using ( ) around your argument lists.
                            This can confuse Ruby:
                            face.pushpull -4000
                            Ruby may think you are trying to subtract integer 4000 from an object returned by the method on the left. Do this instead:
                            face.pushpull(-4000)
                            .

                            I'm not here much anymore.

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

                              By the way.. I've heard that Google Earth models have to be "approved".

                              Is this so? Does a user see his uploaded model right away, or is it invisible until it's approved?
                              Or is it only invisible to other users, until it's approved?

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • Z Offline
                                zps222
                                last edited by

                                @dan rathbun said:

                                FYI

                                • Positive Latitudes are North of the equator; Negative are South.
                                • Positive Longitudes are East of the Prime Meridian; Negative are West.

                                @zps222 said:

                                Another question is, if I build a model, and want to set the bottom of the model at a centain depth in the ocean, how to manage it?

                                First, open your Preferences dialog. Go to the Extensions panel.
                                Check (turn ON,) the "Google Earth Ocean Modeling" extension.

                                Then browse to the Sketchup directory: "Plugins/Ocean" and read the ruby script 'ocean.rb'

                                It appears that you will need to move everything in your model, either:

                                • above the [0,0,0] origin, if you wish to place the model relative to the ocean floor, OR* below the [0,0,0] origin, if you wish to place the model relative to the ocean surface.
                                  You will need to use the "Model on Ocean Floor" menu option that the Ocean extension adds to the Plugins menu.. BEFORE you upload the model to Google Earth.

                                Thans Dan.
                                I still can't figure it out.

                                For example, this is my example code:

                                # Create the new material
                                mats = Sketchup.active_model.materials
                                ct_mat = mats.add "Color_Texture"
                                ct_mat.color = "Red"
                                
                                # Draw a Face and set its material
                                ents = Sketchup.active_model.entities
                                face = ents.add_face [1000, -1000, -5000], [1000, 1000, -5000], [-1000, 1000, -5000], [-1000, -1000, -5000]
                                face.material = ct_mat
                                face.pushpull -4000
                                
                                Sketchup.active_model.shadow_info['Latitude']=29.060
                                Sketchup.active_model.shadow_info['Longitude']=-88.090
                                
                                Sketchup.active_model.export("c;/2.kmz",false)
                                
                                UI.openURL("c;/2.kmz")
                                
                                
                                # Copyright 2005-2009, Google, Inc.
                                
                                # This script enables placing a model in Google Earth relative to the ocean floor,
                                # instead of relative to ground (sea level).
                                
                                # Permission to use, copy, modify, and distribute this software for 
                                # any purpose and without fee is hereby granted, provided that the above
                                # copyright notice appear in all copies.
                                
                                # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
                                # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                                # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                                #-----------------------------------------------------------------------------
                                
                                def is_on_floor_bottom
                                  return Sketchup.active_model.get_attribute("GeoReference", "onOceanFloor") == "true";
                                end
                                
                                def toggle_ocean
                                  on_floor = !is_on_floor_bottom()
                                  puts on_floor
                                  if on_floor
                                    Sketchup.active_model.set_attribute "GeoReference", "onOceanFloor", on_floor.to_s;
                                  else
                                    Sketchup.active_model.attribute_dictionary("GeoReference").delete_key "onOceanFloor";
                                  end
                                end
                                
                                menu = UI;;menu("Plugins");
                                menu.add_separator;
                                item = menu.add_item($oceanStrings.GetString("Model on Ocean Floor")) { toggle_ocean }
                                menu.set_validation_proc(item) {
                                  is_on_floor_bottom() ? MF_CHECKED ; MF_UNCHECKED;
                                }
                                
                                1 Reply Last reply Reply Quote 0
                                • Z Offline
                                  zps222
                                  last edited by

                                  @dan rathbun said:

                                  By the way.. I've heard that Google Earth models have to be "approved".

                                  Is this so? Does a user see his uploaded model right away, or is it invisible until it's approved?
                                  Or is it only invisible to other users, until it's approved?

                                  Thanks Dan. I will try your code soon.

                                  For your question, I can instaneously see the model on google earth, but it's only confined in my laptop, not publiclly to the internet. If wanted to publicate it, as far as I know, there are 3 ways:
                                  the most comon way is to upload the model into "google 3D warehouse" to let people download them into to "local" google earth. The sencond way is to embed the google earth into the website and the locate the KMZ into the server, then on the website, people can see it. The third way is to get the permission to publize it into official google earth.

                                  1 Reply Last reply Reply Quote 0
                                  • Z Offline
                                    zps222
                                    last edited by

                                    @dan rathbun said:

                                    What about ??
                                    Sketchup.active_model.shadow_info['Latitude'] Sketchup.active_model.shadow_info['Longitude']

                                    I believe these are set by the Model Info > Location feature.

                                    Thank you Dan and Jim.
                                    Still, I can't figure it out.
                                    Simply as an example,

                                    # Access the Entities object
                                    model = Sketchup.active_model
                                    ent = model.entities
                                    
                                    # Create the 2-D shape of the axis
                                    axis = ent.add_face [0, -500, 0], [250, -433, 0],
                                                          [433, -250, 0], [500, 0, 0],
                                                          [433,250, 0], [250, 433, 0],
                                                          [0, 500, 0], [-250, 433, 0],
                                                          [-433, 250, 0], [-500, 0, 0],
                                                          [-433, -250, 0], [-250, -433, 0], [0, -500, 0]
                                    
                                    
                                    # Create the 3-D shape of the axis
                                    total_depth = -2060
                                    axis.pushpull total_depth
                                    
                                    #creat one simple 3-d vector, North at the bottom
                                    vector1 =ent.add_face [-500,0,0],[500,0,0],
                                                       [500,1500,0],[750,1500,0],
                                                       [0,2000,0],[-750,1500,0],
                                                       [-500,1500,0] 
                                    
                                    vector_depth=-50
                                    vector1.pushpull vector_depth
                                    

                                    Here is my simple code, if I want to they located at lat= 10, lon=10, how to manege it?

                                    Really appratiate.

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

                                      zps222,

                                      The description of the Google Earth Ocean Modeling extension says,
                                      "Adds the ability to model on the ocean floor after taking a snapshot from Google Earth."

                                      So try taking a shapshot first.

                                      I'm not here much anymore.

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

                                        .
                                        Here's some commands you can use at the console, for info:

                                        dicts=Sketchup.active_model.attribute_dictionaries dicts['GeoReference'].each { |key,value| p key.to_s + '=' + value.to_s }

                                        I'm not here much anymore.

                                        1 Reply Last reply Reply Quote 0
                                        • B Offline
                                          borg.stef
                                          last edited by

                                          how can i put a simple model in the required location? i did the following coding
                                          model = Sketchup.active_model
                                          pt = Geom::point3d.new(0,0,0)
                                          tr = Geom::Transformation.new(pt)
                                          model.transform!(tr)

                                          and it gives me this error:
                                          #<NoMethodError: undefined method `point3d' for Geom:Module>

                                          thankss

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

                                            @borg.stef said:

                                            ... and it gives me this error:
                                            #<NoMethodError: undefined methodpoint3d' for Geom:Module>`

                                            Because methods begin with lower case identifiers.
                                            Class (and Module,) indentifiers are titlecase.

                                            @borg.stef said:

                                            How can i put a simple model in the required location? I did the following coding:
                                            model = Sketchup.active_model pt = Geom::point3d.new(0,0,0) tr = Geom::Transformation.new(pt) model.transform!(tr)

                                            The model origin is already at [0,0,0], and there is a constant ORIGIN for it.
                                            So your code above does nothing.

                                            I'm not here much anymore.

                                            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