sketchucation logo sketchucation
    • Login
    ๐Ÿ›ฃ๏ธ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Ai plugin

    Scheduled Pinned Locked Moved Extensions & Applications Discussions
    1 Posts 1 Posters 39 Views 1 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.
    • L Offline
      L i am
      last edited by

      Hi guys I asked AI to write a script for a simple round corner plugin, to test the ability of AI to write unusable ruby script. If anyone has any idea of how to test the response that would be cool. I am not computer smart to test it myself. Here it is

      Hi could you design a ruby script that would be similar to round corners. That I cn import into sketchup 2017
      ChatGPT said:

      Absolutely ๐Ÿ‘ โ€” I can design a Ruby plugin script for SketchUp 2017 that behaves like the RoundCorner extension (by Fredo6), but in a simplified, open version you can edit and learn from.

      Before I write the code, could you please confirm a few details so I tailor it correctly:

      ๐Ÿ”ง Quick questions

      Functionality scope โ€” do you want it to:

      (A) Round or bevel selected edges of a solid or surface (simple chamfer/fillet), or

      (B) Work like RoundCorner, i.e. automatically round edges between faces with a radius you type in?

      Complexity level

      (A) Basic (manually enter a radius, applies to straight edges only), or

      (B) Intermediate (detects edge loops and creates rounded geometry around corners)?

      UI preference

      (A) Command from the Plugins menu,

      (B) Toolbar button with icon, or

      (C) Both?

      Would you like the rounded edges to be real geometry (faces and arcs), or just a visual smoothing (soften edges only)?

      Once you confirm, Iโ€™ll generate a ready-to-install .rb file you can drop into your SketchUp 2017/Plugins folder (and a .rbz if you prefer zipped format).
      Iโ€™ll also include inline comments so you can tweak it yourself later.

      You said:
      yes please but not i zipped format
      are you working on it?
      ChatGPT said:
      Thought for 34s

      Yep โ€” I made a ready-to-install single Ruby file plugin for SketchUp 2017 you can drop straight into your Plugins folder (not zipped).

      Important: robust, production-quality filleting/chamfering in all geometry cases is quite complex. This script gives you:

      A simple, editable Chamfer (bevel) command that tries to cut a small flat face at each selected edge (only runs on edges with exactly two adjacent faces).

      A Soften/Smooth command that simply softens selected edges (visual smoothing only).

      A menu entry and a toolbar button.

      Inputbox UI for chamfer distance and an explanatory warning.

      This is a practical, editable starting point โ€” it will handle many straightforward edges but will fail or need manual cleanup on complex topology (non-manifold edges, very short edges, very tight angles, or highly tessellated geometry). Iโ€™ve commented the code so you can extend it later (e.g., add proper arc fillets, support edge loops, improve stitching).

      Installation

      Copy the entire code below into a plain text file named roundish_chamfer.rb.

      Place that file in your SketchUp 2017 Plugins folder:

      Windows: C:\Users<you>\AppData\Roaming\SketchUp\SketchUp 2017\SketchUp\Plugins\

      macOS: ~/Library/Application Support/SketchUp 2017/SketchUp/Plugins/

      Restart SketchUp. Youโ€™ll find the menu: Plugins โ†’ Roundish and a toolbar button.

      The Ruby plugin (paste into roundish_chamfer.rb)

      Roundish Chamfer plugin for SketchUp 2017

      Simple chamfer (flat bevel) on selected edges + soften/smooth utility

      NOTE / LIMITATIONS:

      - This is a simple, best-effort chamfer. It works on edges with exactly two adjacent faces.

      - It creates small flat bevel faces by offsetting endpoints into the two faces' planes.

      - Complex topology (non-manifold edges, tiny edges, or faces with curved tessellation)

      may produce wrong geometry or require manual cleanup.

      - Use small chamfer distances relative to edge length. The code skips edges shorter than 2*distance.

      Drop this file into your SketchUp Plugins folder and restart SketchUp.

      require 'sketchup.rb'
      require 'extensions.rb'

      module RoundishChamfer
      PLUGIN_NAME = "Roundish"
      PLUGIN_VERSION = "0.1"

      Helpers

      def self.valid_edge_for_chamfer?(edge, dist)
      return false unless edge.is_a?(Sketchup::Edge)
      return false unless edge.faces.length == 2
      p1 = edge.start.position
      p2 = edge.end.position
      return false if p1.distance(p2) <= 2.0 * dist + 1e-6
      true
      end

      Build chamfer for a single edge (best-effort)

      def self.chamfer_edge(entities, edge, distance)
      # Only handle edges with exactly two faces
      return nil unless edge.faces.length == 2

      f1, f2 = edge.faces
      v1 = edge.start.position
      v2 = edge.end.position
      edge_vec = v2 - v1
      edge_len = edge_vec.length
      return nil if edge_len <= 2.0 * distance + 1e-6
      
      # For stability, ensure normals are consistent
      n1 = f1.normal
      n2 = f2.normal
      
      # direction perpendicular to edge but lying in face plane
      # For endpoint v1 compute directions using cross product with the edge vector
      dir1_v1 = n1.cross(edge_vec).normalize rescue nil
      dir2_v1 = n2.cross(edge_vec).normalize rescue nil
      return nil if dir1_v1.nil? || dir2_v1.nil?
      
      avg_dir_v1 = (dir1_v1 + dir2_v1)
      if avg_dir_v1.length < 1e-6
        # faces are opposite / flat - fall back to single face offset
        avg_dir_v1 = dir1_v1
      end
      avg_dir_v1 = avg_dir_v1.normalize
      
      # For endpoint v2 we use -edge_vec as the local edge direction
      dir1_v2 = n1.cross(-edge_vec).normalize rescue nil
      dir2_v2 = n2.cross(-edge_vec).normalize rescue nil
      return nil if dir1_v2.nil? || dir2_v2.nil?
      avg_dir_v2 = (dir1_v2 + dir2_v2)
      if avg_dir_v2.length < 1e-6
        avg_dir_v2 = dir1_v2
      end
      avg_dir_v2 = avg_dir_v2.normalize
      
      # New offset points
      p1_new = v1.offset(avg_dir_v1, distance)
      p2_new = v2.offset(avg_dir_v2, distance)
      
      # Ensure points are not too close
      if p1_new.distance(p2_new) < 1e-6
        return nil
      end
      
      # Create the chamfer geometry inside a temporary group so we can union it in cleanly
      group = entities.add_group
      ge = group.entities
      
      # Create vertices as construction points via small edges (we must create geometry)
      e_v = ge.add_line(p1_new, p2_new)             # center short edge of chamfer
      e1 = ge.add_line(p1_new, v1)                  # tie back to original v1
      e2 = ge.add_line(p2_new, v2)                  # tie back to original v2
      
      # Attempt to form faces for the chamfer: three faces to replace the corner:
      # face A: p1_new -> p2_new -> v2 -> v1 (but depending on topology may not be planar)
      # We'll attempt to create quad face (p1_new, p2_new, v2, v1) if possible, otherwise create triangles.
      begin
        # Try quad first
        quad = ge.add_face(p1_new, p2_new, v2, v1)
        if quad
          quad.reverse! if quad.normal && quad.normal.samedirection?(edge.faces[0].normal) == false
        end
      rescue => e
        # fallback to two triangular faces
        begin
          ge.add_face(p1_new, p2_new, v2)
        rescue
        end
        begin
          ge.add_face(p1_new, v2, v1)
        rescue
        end
      end
      
      # Attempt to clean up by erasing the middle segment on original geometry:
      # We cannot safely remove original edge directly because of shared topology.
      # Instead mark the group for user to inspect; user can manually delete the original edge segment or use Solid tools.
      group
      

      end

      Main action: Chamfer selected edges

      def self.run_chamfer
      model = Sketchup.active_model
      sel = model.selection
      unless model && sel
      UI.messagebox("No active model or selection.")
      return
      end

      prompts = ["Chamfer distance (in model units):", "Auto-soften chamfer edges? (Yes/No)"]
      defaults = [model.options['UnitsOptions']['LengthUnit'] == nil ? 5.mm : 5.mm, "Yes"]
      results = UI.inputbox(prompts, defaults, "Roundish โ€” Simple Chamfer")
      return unless results
      distance = results[0].to_f
      soften_yes = results[1].to_s.downcase.start_with?('y')
      
      model.start_operation("#{PLUGIN_NAME} Chamfer", true)
      begin
        ents = model.active_entities
        created_groups = []
        target_edges = sel.grep(Sketchup::Edge)
        if target_edges.empty?
          UI.messagebox("Please select one or more edges and try again.")
          model.commit_operation
          return
        end
      
        skipped = 0
        target_edges.each do |e|
          if valid_edge_for_chamfer?(e, distance)
            g = chamfer_edge(ents, e, distance)
            created_groups << g if g
          else
            skipped += 1
          end
        end
      
        # Optionally soften edges inside created groups
        if soften_yes
          created_groups.each do |g|
            next unless g && g.is_a?(Sketchup::Group)
            g.entities.grep(Sketchup::Edge).each do |ed|
              ed.soft = true
              ed.smooth = true
            end
          end
        end
      
        model.commit_operation
        msg = "Chamfer operation completed. Created #{created_groups.length} chamfer group(s)."
        msg += " Skipped #{skipped} edge(s) (too short or not two-faced)." if skipped > 0
        UI.messagebox(msg)
      rescue Exception => ex
        model.abort_operation
        UI.messagebox("Error during chamfer: #{ex.message}")
        raise
      end
      

      end

      Soften / smooth selected edges (visual only)

      def self.run_soften
      sel = Sketchup.active_model.selection
      edges = sel.grep(Sketchup::Edge)
      if edges.empty?
      UI.messagebox("Select edges and run 'Soften selected edges'.")
      return
      end
      edges.each do |e|
      e.soft = true
      e.smooth = true
      end
      UI.messagebox("Softened #{edges.length} edges.")
      end

      Build UI: menu + toolbar

      unless file_loaded?(FILE)
      menu = UI.menu("Plugins")
      submenu = menu.add_submenu(PLUGIN_NAME)
      submenu.add_item("Chamfer selected edges...") {
      self.run_chamfer
      }
      submenu.add_item("Soften (visual) selected edges") {
      self.run_soften
      }

      # Toolbar
      toolbar = UI::Toolbar.new(PLUGIN_NAME)
      cmd = UI::Command.new("Chamfer selected edges...") {
        self.run_chamfer
      }
      cmd.small_icon = cmd.large_icon = nil # user can add icons if desired
      cmd.tooltip = "Roundish โ€” Simple Chamfer"
      toolbar.add_item(cmd)
      
      cmd2 = UI::Command.new("Soften selected edges") {
        self.run_soften
      }
      cmd2.small_icon = cmd2.large_icon = nil
      cmd2.tooltip = "Roundish โ€” Soften selected edges visually"
      toolbar.add_item(cmd2)
      
      toolbar.show
      
      file_loaded(__FILE__)
      

      end

      end # module RoundishChamfer

      How to use (quick)

      Select one or more edges in your model (hold Shift to pick multiple).

      Plugins โ†’ Roundish โ†’ Chamfer selected edges...

      Enter a small chamfer distance (model units). Use small numbers relative to edge length.

      The plugin will create a small group for each chamfer it could build. Inspect and clean up if necessary.

      Or use Soften (visual) selected edges to smooth them visually (no geometry change).

      Next steps / improvements I can add (if you want)

      A true arc fillet routine that builds rounded arcs with configurable segments and stitches them into neighboring faces (more geometry math / topology handling).

      Edge-loop detection to fillet/chamfer whole loops automatically.

      Improved stitching to remove/replace original edge segments and avoid user cleanup.

      Toolbar icons and a preferences dialog.

      If youโ€™d like, I can now:

      Add an actual arc fillet implementation (I can do a best-effort fillet algorithm next) โ€” tell me to proceed and Iโ€™ll extend the plugin to attempt real fillets with a configurable segment count, or

      Improve the chamfer to directly replace original geometry instead of creating groups.

      Which would you prefer?

      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