Someone please make this simple Ruby

I see what you mean.

If you ignore all of the ‘bells and whistles’, the tool can still operate as soon as it is opened to pull faces until they hit a face or reach the maximum distance with a single click.

The face highlighting feature is for multiple face selection using the CTRL key. But that does require pressing another button, Push-Pull.

It needs to have a prompt of some sort if the ability to modify the maximum distance is to be retained… unless the maximum distance is unchangeable. One area where it’s overly complex is that it’s using dialogs. It could use a prompt.

There are a couple of things you noted. One is specifying a direction with the mouse. Would it be better to just click? You could have two extensions: one that pushes and one that pulls with keyboard shortcuts assigned (In and Out, ctrl + i and ctrl + o). That way you could do either one or the other (push or pull) without the extra mouse action.

Anyway, if you try getting your code working people here can take a look at it.

1 Like

The Max Distance limits the push-pull. So basically “Go 'till you hit or reach the limit”. I don’t know how SketchUp handles infinity and beyond but beyond infinity seems like a problem for philosophers;^)! I think it would cause problems.

I tried different defaults for the Max Distance. I settled on 20ft… only because that’s kind of typical of the size of things I typically draw. But there is an input field to change it if shorter or longer is needed.

2 Likes

Was referencing @FJAY’s design parameter…

1 Like

I ran into a bunch of problems. Bugsplats, faces flipping, even vs odd numbers of edges of pushed faces. I’ve mostly stayed with perpendicular face to face push-pulling (simple first) and only tested extruding to a few other face orientations/edges. I may begin searching out those gaps you mention… this is a fun one!

2 Likes

If you manage to implement this Ruby feature, you will become a hero to many SketchUp modelers worldwide. You could save thousands of hours for countless users.

1 Like

Perhaps we can refer to the format of Fredo’s ‘Joint Push Pull’. This format makes the directionality of the faces being modified very intuitive and straightforward. Like this.

Alternatively, even if it’s not in a box format like that, it would be helpful if the face to be modified is intuitively indicated with an arrow.



(Assuming the Ruby feature is named JFD Pushpull.) The steps are as follows:

  1. Press the pre-configured JFD Pushpull shortcut key.
  2. Click on the face you want to modify with the mouse.
  3. Move the mouse to set the direction (an arrow will appear to indicate the direction intuitively).
  4. Click to confirm the direction.
  5. BOOM!

Honestly, the maximum extension length doesn’t seem important enough to set every time. Most modelers already have a general scale they work within. It can just be set once in the menu bar.


1 Like

That’s very funny!

I made a bunch of versions that I showed you… but I thought you were going to make it… then you could be a hero to modelers around the world!

You mentioned (and your code seemed to show) a few different ways that the tool could work (e.g., highlighting, double clicking, mouse movement). How do you want it to work? I see you are posting now…

1 Like

I feel like a three-year-old who knows nothing about coding. The script I shared was just copied and pasted from what the AI provided. I’ve realized there’s a significant limitation in communicating with AI, which is why I wrote a post in the community. There are many things I want to try, but I’m getting older and feel it’s too challenging to start learning to code from scratch. It’s quite sad.

I’ve been using 3D Max professionally for over ten years, and there are so many features I want to bring over to other programs. For example, splitting the viewport into four sections, toggling between different views (east, west, south, north, and iso) with a single click, and other convenient features that have been around since 2008. It’s disappointing that such convenient features still don’t exist in SketchUp. Of course, SketchUp is a great program with its own advantages.

To get to the point,
In the video you posted, focus on your mouse pointer. The goal is to create convenient features to reduce work fatigue, but it seems like the frequency of mouse clicks has increased and the movement path has become longer. I think this approach might not be ideal in the long run.

However, I fully respect and sincerely appreciate your consideration, kindness, effort, and skill.

I know how you feel.

Finally, I just made a joke out of it. The namespace I wrap all of my code in is: IDKProgramming. If you are Korean you may not know that in English, “IDK” means, “I Don’t Know”.

For those things you are good at doing, you don’t criticize yourself for using the tools you need. So why be discouraged by using tools that help you before you are good at something?

I’m not young either. I learned how to flowchart pseudocode, the basic idea of an algorithm, and how to type out html over 20 years ago. But circumstances never worked out for me to learn and practice so I always ended up going back to shovel work.

Day after day I failed over and over and over again. It was so frustrating that I had to adjust my expectations and take what I could get:

You are more than 1% of the way there!

You’re welcome. It helps me to get better and is a lot of fun!

So, I’ll help you make the extension but I won’t make it for you.


Moving along…
We already changed face.move to face.pushpull.

The registration / registrar file that I gave you has the same name as the name of your extension folder. This is the file that tells SketchUp your extension name and where to look for the ‘main’ file. They both go in your Plugins folder. Something like:

C:\Users\YOURUSERNAME\AppData\Roaming\SketchUp\SketchUp 2024\SketchUp\Plugins\

jhj_push(folder) /main.rb
jhj_push.rb

Inside of the jhj_push folder, you’ll have your ‘main’ ruby file. In this case we will name it, “main.rb”. This is where your code goes.

I reworked the registration file, hopefully making it easier to read:

Registration file, "jhj_push.rb"
require 'sketchup.rb'
require 'extensions.rb'

module JHJ # This is your JHJ module/namespace. All of your code needs to be wrapped in this module.
  module PushTool # This is your Push Tool module. For now, all of your code needs to be in this module.
    # So, all of the code in your extension files is wrapped in these.

    # Extension version
    VERSION = "1.0.0"

    # Extension information
    EXTENSION_NAME = "JHJ Push Tool"
    # This line tells SketchUp to load the file 'jhj_push/main.rb' when SketchUp is loaded.
    LOADER_PATH = File.join(File.dirname(__FILE__), 'jhj_push', 'main.rb')
    CREATOR = "JHJ"
    COPYRIGHT = "©2024 JHJ"
    DESCRIPTION = "An example extension for pushing faces to a maximum distance."

    # SketchupExtension instance
    extension = SketchupExtension.new(EXTENSION_NAME, LOADER_PATH)
    extension.version = VERSION
    extension.creator = CREATOR
    extension.copyright = COPYRIGHT
    extension.description = DESCRIPTION

    # Register extension with the SketchupExtensionManager
    Sketchup.register_extension(extension, true)

  end
end

The extension basically works as it is but there are some problems. First, turn on the Ruby Console (Extensions->Developer->Ruby Console) and leave it on. This way it will open when SketchUp is opened.

Also, you don’t need to make shortcuts in the code. You have menu items in the code that you can use to make shortcuts.

Menu Code
unless file_loaded?(__FILE__)
      # JHJ Push 메뉴 생성
      menu = UI.menu('Plugins').add_submenu('JHJ Push')
      
      menu.add_item('Maximum Distance Setting') {
        show_max_distance_settings_dialog
      }

      menu.add_item('Extend') {
        activate
      }

      UI.add_context_menu_handler do |context_menu|
        context_menu.add_item('Extend') {
          activate
        }
      end

     file_loaded(__FILE__)

SketchUp uses those menu items to make keyboard shortcuts. I added CTRL+Q for the shortcut:

Back to the extension, in SketchUp, in the Ruby Console. If you select a face and use a keyboard shortcut, the face will pull and you’ll see the error in the Ruby Console:

Error: #<TypeError: reference to deleted Face>
C:/Users/YOURUSERNAME/AppData/Roaming/SketchUp/SketchUp 2024/SketchUp/Plugins/jhj_push/main.rb:38:in `all_connected'

It’s a reference to a deleted face on line 38 of the main.rb file.

Problem code:
# lines 35-40
face.pushpull(distance)

      # 연장된 면과 연결된 모든 엔티티를 그룹화
      new_entities = face.all_connected
      group = model.entities.add_group(new_entities)
      group.name = "Extended Face Group"

You could try to figure that out… but the question is: Why are you grouping? If you only want to pushpull the face, then you can remove the problem code that’s trying to create a group of the pushed face and all connected entities.

main.rb
require 'sketchup.rb'
module JHJ
  module PushTool
    extend self

    @max_extension = 10000.mm

    def show_max_distance_settings_dialog
      prompts = ['Maximum Extension Length (in mm):']
      defaults = [@max_extension.to_s]
      input = UI.inputbox(prompts, defaults, 'Push Tool Settings')

      @max_extension = input[0].to_f.mm if input
    end

    def extend_face(face)
      model = Sketchup.active_model
      entities = model.entities
      normal = face.normal

      ray = [face.bounds.center, normal]
      hit = model.raytest(ray, true)

      if hit
        point = hit[0]
        distance = point.distance(face.bounds.center)
        distance = @max_extension if distance > @max_extension
      else
        distance = @max_extension
      end

      face.pushpull(distance)
    end

    def activate
      model = Sketchup.active_model
      selection = model.selection
      face = selection.grep(Sketchup::Face).first

      if face
        extend_face(face)
      else
        UI.messagebox("No face selected.")
      end
    end

    unless file_loaded?(__FILE__)
      # JHJ Push 메뉴 생성
      menu = UI.menu('Plugins').add_submenu('JHJ Push')
      
      menu.add_item('Maximum Distance Setting') {
        show_max_distance_settings_dialog
      }

      menu.add_item('Extend') {
        activate
      }

      UI.add_context_menu_handler do |context_menu|
        context_menu.add_item('Extend') {
          activate
        }
      end

     file_loaded(__FILE__)
    end
  end
end

This version is Select Face → Shortcut → BOOM!

From this point we could try to make the code better. Try to add one of the features you mentioned above and post the code here.

???:

This version is Shortcut → Select Face → Move Mouse → BOOM!

2 Likes

I couldn’t understand most of the sentences you wrote above because my English skills are not sufficient. However, the feature you demonstrated in the last video perfectly meets the functionality I initially wanted from Ruby. Therefore, would you be willing to share the Ruby code you showed in the video? You mentioned that you would help me make it but wouldn’t make it for me, but I don’t have the ability to understand and apply your code. I just want to install and use the Ruby extension like a typical SketchUp user by clicking the install button in the Extension Manager. Thank you sincerely for your assistance.

1 Like

The extension I showed only works partially. It’s using icons and it needs at least eight of them to correctly show an arrow pointing away or pointing towards faces depending on which direction the face is oriented and the orientation of the camera. So far I keep getting it wrong. But I’ll keep trying and get back to you when I have something.

1 Like

Your passion moves me deeply. Thank you JFD!!!