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

    Ruby scripting issues

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 322 Views 3 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.
    • N Offline
      nransome
      last edited by

      Hi,

      I am trying to automate this workflow: https://www.youtube.com/watch?v=_bbMv5uXUCM

      I am using a script which exports height curves as dwg and orthophoto as jpg from ArcGIS. These two the can be intersected to make a detailed surface with high quality satellite texture on it.

      This can be done within SketchUp already, but it is not accurate enough for this purpose.

      I have made the first part that gets the image into SketchUp, asks for dimensions and extrudes it, but I am having trouble understanding how to get the FromContoursTool to work.

      This is the first part:

      
      # First we pull in the standard API hooks.
      require 'sketchup.rb'
      
      # A new menu item is added to SketchUp.
      UI.menu("Extensions").add_item("GIS til SketchUp") {
        UI.messagebox("Let's go!") 
      
      # A box asking for the dimensions of the data area.
       results = inputbox(["Length ", "Width; "], ["?", "?"], ["", ""], "Dimensioner pƄ udtrƦk")
      
      # Width and length are converted to integers.
       length = results[0].to_i
       width = results[1].to_i
      
      # A box asks for an image location. The image is exploded.
       chosen_image = UI.openpanel("Open Image File", "c;/", "Image Files|*.jpg;*.png;||")
       model = Sketchup.active_model 
       image = model.active_entities.add_image(chosen_image, ORIGIN, length, width)
       entities = image.explode
      
      # A face is drawn.
       model = Sketchup.active_model
       entities = model.active_entities
       pts = []
       pts[0] = [0, 0, 0]
       pts[1] = [length, 0, 0]
       pts[2] = [length, width, 0]
       pts[3] = [0, width, 0]
      
      # The face is extruded to a volume.
       face = entities.add_face(pts)
       status = face.pushpull(100, true)
      }
      
      

      This is the second part:

      
      # A new menu item is added to SketchUp.
      UI.menu("Extensions").add_item("Contours") {
        UI.messagebox("Let's Go") 
      
       # First we pull in the standard API hooks.
       require 'sketchup.rb'
       require 'extensions.rb'
       Sketchup;;require 'su_sandbox/GeometryHelpers'
        
       model = Sketchup.active_model # Sketchup active model
        se = model.active_entities # Sketchup Active Entities.  Allows working inside a component.
         ss = model.selection # Model selection, if it exists
          if ss.length == 0 then ss = se end  # otherwise use the whole model. 
       
      
       # edges = [] # create empty array
       
       # se.each do |e|
        # if e.is_a? Sketchup;;Edge # if e is a sketchup edge
         # edges << e # add to e
          # ss.add e # add e to selection
         # end
        # end
        
       
       Sketchup.active_model.select_tool FromContoursTool
      }
      
      

      Any help would be appreciated - I'm finding it challenging finding documentation on what I'm trying to do. Or if there is a good post already that I have overlooked, please point me in the right direction.

      All the best,
      Nicholas

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

        The code is:
        Sketchup::active_model.select_tool(FromContoursTool.new())
        since it's a Tool and therefore needs a .new() to initialize it...

        TIG

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

          # First we pull in the standard API hooks. require 'sketchup.rb' require 'extensions.rb' Sketchup::require 'su_sandbox/GeometryHelpers'

          (1) They do not really "pull in the API hooks".

          (2) You only require scripts and libraries, if this script (which has the require statements,) are going to use what is defined in them.

          And your script uses nothing in those two files. (The files are located in the "Tools" sub-directory, of SketchUp program directory. They are not scrambled and can be read. Also everything defined in the "extensions.rb" file, is explained in the API dictionary under the SketchupExtensions class.)

          (3) require statements are always best located at the top of a file, since they should be dependencies. If they cannot be loaded, the rest of the script should not be run, because a LoadError exception will be raised.

          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