IDK Compilation

The SU 2023 Outliner has some quirks that sometimes interfere with GTD (Getting Things Done!), as discussed here:

Summary

[(SU Outliner 2023 seems different)]

One of these matters of funky business is the number of clicks it takes to Rename Groups (the quintuple L-click). Here I’ve tried to create a work-around in the form of a Toolbar extension. The extension creates Groups from selected components and prompts for a New Group Name. This avoids clicking the Group in the Outliner in order to rename the Group. It is also available from the R-click context menu.

Group Namer:

Select components and press the Group Namer Toolbar button. A Group will be created and a prompt will pop-up asking for a “New Group Name”

Input the new group name and press “Enter” or “OK”.

The new group is then created and can be undone using Undo or Ctrl+z.

Context Menu view:

For those who might like to try it (Caution… danger… et cetera):

Registration Code
###########################################################################
# Copyright 2023 IDK_Programming
########################################################################### 

# Group_Namer - "As-Is" / "Use at Your Own Risk" Disclaimer

#  By using the [Group_Namer] SketchUp extension ("the Extension"), you acknowledge and agree to the following terms:

#  1. No Warranty or Guarantee: The Extension is provided "as is," without any warranty, express or implied. The creators, developers, or distributors of the Extension make no representations or warranties of any kind concerning the functionality, accuracy, reliability, or suitability for any purpose of the Extension.

#  2. Limited Liability: In no event shall the creators, developers, or distributors of the Extension be liable for any damages, whether direct, indirect, incidental, special, or consequential, arising out of the use or inability to use the Extension, including but not limited to damages for loss of profits, data, or business interruption.

#  3. User Responsibility: You are solely responsible for the installation, use, and consequences of using the Extension. It is your responsibility to evaluate the Extension's compatibility with your specific SketchUp version, system configuration, and other relevant factors.

#  4. No Support or Maintenance: The creators, developers, or distributors of the Extension are under no obligation to provide support, updates, or maintenance for the Extension. They may, at their sole discretion, offer support or updates, but this is not guaranteed.

#  5. Indemnification: You agree to indemnify and hold harmless the creators, developers, or distributors of the Extension from any claims, damages, liabilities, or expenses arising out of your use of the Extension.

#  6. User Acceptance: By installing and using the Extension, you indicate your acceptance of these terms and conditions. If you do not agree with any part of this disclaimer, you should immediately uninstall and cease using the Extension.

###########################################################################
# TESTED IN SKETCHUP Pro 2023 (VERSION 23.0.419 64-BIT) on WINDOWS 11.
###########################################################################

require 'sketchup.rb'
require 'extensions.rb' 
    
module IDK_Programming
	
	module IDK_Programming_Group_Namer
	PLUGIN_NAME = "Group_Namer"
	
	# Plugin information
	PLUGIN_ID = File.basename(__FILE__, "Main.rb") 
	PLUGIN_ROOT = File.dirname(__FILE__)
	PLUGIN_DIR = File.join( PLUGIN_ROOT, PLUGIN_ID ) 

		unless file_loaded?( __FILE__ )
		  LOADER = File.join(PLUGIN_DIR, "Main.rb") 
		  EXTENSION = SketchupExtension.new( 'Group_Namer', 'IDK_Programming_Group_Namer/Main.rb' )
		  EXTENSION.creator     = "IDK_Programming"
		  EXTENSION.description = "A toolbar extension that creates a component group, with a prompt for a group name."
		  EXTENSION.version     = "0.1"
		  EXTENSION.copyright   = "IDK_Programming"
		  Sketchup.register_extension(EXTENSION, true)
		  
		  file_loaded( __FILE__ )
		end
	end
end

###########################################################################
#  Acknowledgements: Useful contributions from SketchUp Community Forum:

#  @DanRathbun
#  @Dezmo

#  Any errors are the author's alone.
Main
module IDK_Programming
  module Group_Namer
    extend self
    @@loaded = false unless defined?(@@loaded)

    def create_new_group(selected_entities)
      model = Sketchup.active_model

      # Start a new operation for undo
      model.start_operation('Create New Group', true)

      begin
        # Create a new group
        new_group = model.entities.add_group(selected_entities)

        # Prompt for new group name
        new_group_name = UI.inputbox(['New Group Name'], [''])[0]
        new_group.name = new_group_name

        new_group
      rescue StandardError => e
        puts "Error creating group: #{e.message}"
        model.abort_operation
      else
        # Commit the operation (undo point)
        model.commit_operation
      end
    end

    unless @@loaded
      cmd1 = UI::Command.new("Create and Name Group") { create_new_group(Sketchup.active_model.selection.to_a) }
      cmd1.small_icon = File.join(File.dirname(__FILE__), 'Icons/Group-Name.png')
      cmd1.large_icon = File.join(File.dirname(__FILE__), 'Icons/Group-Name.png')
      cmd1.tooltip = "Group Namer"
      cmd1.status_bar_text = "Create and name a new group of components using a prompt."
      cmd1.set_validation_proc {
        if Sketchup.active_model.selection.grep(Sketchup::ComponentInstance).first
          MF_ENABLED
        else
          MF_GRAYED | MF_DISABLED
        end
      }

      UI.add_context_menu_handler do |context_menu|
        if Sketchup.active_model.selection.grep(Sketchup::ComponentInstance).first
          context_menu.add_item(cmd1)
        end
      end

      toolbar1 = UI::Toolbar.new("Group Namer.")
      toolbar1.add_item(cmd1)
      toolbar1.restore
      @@loaded = true
    end
  end # module Group_Namer
end # module IDK_Programming

IDK_Programming_Group_Namer.rbz (11.8 KB)

Thanks to those who have previously helped me and provided examples! @DanRathbun @dezmo

1 Like

I created a little suite of utilities for grouping, naming, and tagging.

This extension adds another prompt after the New Group Name prompt for inputting a New Tag Name that will be created and added to the new group.

Group, Name, and Tag

Select components and press the Toolbar button to create the New Group and enter the 1st prompt:

Name the group.

The New Group Tag prompt will appear next.

Enter a New Group Tag name.

Press, “OK” or “Enter”. The newly named group will be created with the new tag applied.

Also available in the Context Menu. Press Undo or Ctrl+z to undo.

For those who might find this useful (Danger, careful, watch out, etc.)

Registration Code
###########################################################################
# Copyright 2023 IDK_Programming
########################################################################### 

# Group_Name_Tag - "As-Is" / "Use at Your Own Risk" Disclaimer

#  By using the [Group_Name_Tag] SketchUp extension ("the Extension"), you acknowledge and agree to the following terms:

#  1. No Warranty or Guarantee: The Extension is provided "as is," without any warranty, express or implied. The creators, developers, or distributors of the Extension make no representations or warranties of any kind concerning the functionality, accuracy, reliability, or suitability for any purpose of the Extension.

#  2. Limited Liability: In no event shall the creators, developers, or distributors of the Extension be liable for any damages, whether direct, indirect, incidental, special, or consequential, arising out of the use or inability to use the Extension, including but not limited to damages for loss of profits, data, or business interruption.

#  3. User Responsibility: You are solely responsible for the installation, use, and consequences of using the Extension. It is your responsibility to evaluate the Extension's compatibility with your specific SketchUp version, system configuration, and other relevant factors.

#  4. No Support or Maintenance: The creators, developers, or distributors of the Extension are under no obligation to provide support, updates, or maintenance for the Extension. They may, at their sole discretion, offer support or updates, but this is not guaranteed.

#  5. Indemnification: You agree to indemnify and hold harmless the creators, developers, or distributors of the Extension from any claims, damages, liabilities, or expenses arising out of your use of the Extension.

#  6. User Acceptance: By installing and using the Extension, you indicate your acceptance of these terms and conditions. If you do not agree with any part of this disclaimer, you should immediately uninstall and cease using the Extension.

###########################################################################
# TESTED IN SKETCHUP Pro 2023 (VERSION 23.0.419 64-BIT) on WINDOWS 11.
###########################################################################

require 'sketchup.rb'
require 'extensions.rb' 
    
module IDK_Programming
	
	module IDK_Programming_Group_Name_Tag
	PLUGIN_NAME = "Group_Name_Tag"
	
	# Plugin information
	PLUGIN_ID = File.basename(__FILE__, "Main.rb") 
	PLUGIN_ROOT = File.dirname(__FILE__)
	PLUGIN_DIR = File.join( PLUGIN_ROOT, PLUGIN_ID ) 

		unless file_loaded?( __FILE__ )
		  LOADER = File.join(PLUGIN_DIR, "Main.rb") 
		  EXTENSION = SketchupExtension.new( 'Group_Name_Tag', 'IDK_Programming_Group_Name_Tag/Main.rb' )
		  EXTENSION.creator     = "IDK_Programming"
		  EXTENSION.description = "A toolbar extension that creates a component group and tag, with prompts for a group name, and a tag name."
		  EXTENSION.version     = "0.1"
		  EXTENSION.copyright   = "IDK_Programming"
		  Sketchup.register_extension(EXTENSION, true)
		  
		  file_loaded( __FILE__ )
		end
	end
end

###########################################################################
#  Acknowledgements: Useful contributions from SketchUp Community Forum:

#  @DanRathbun
#  @Dezmo

#  Any errors are the author's alone.
Main
module IDK_Programming
    module Group_Name_Tag
      extend self
      @@loaded = false unless defined?(@@loaded)
  
      def create_new_group_tag(selected_entities)
        model = Sketchup.active_model
  
        # Start a new operation for undo
        model.start_operation('Create New Group and Tag', true)
  
        begin
          new_group = create_group(selected_entities)
          assign_group_name(new_group)
          assign_group_tag(new_group)
          
          new_group
        rescue StandardError => e
          display_error_message("Error creating group: #{e.message}")
          model.abort_operation
        else
          model.commit_operation
        end
      end
  
      def create_group(selected_entities)
        model = Sketchup.active_model
        model.entities.add_group(selected_entities)
      end
  
      def assign_group_name(group)
        new_group_name = UI.inputbox(['New Group Name'], [''])[0]
        group.name = new_group_name
      end
  
      def assign_group_tag(group)
        new_group_tag = UI.inputbox(['New Group Tag'], [''])[0]
        new_layer = create_layer_with_tag(new_group_tag)
        group.layer = new_layer
      end
  
      def create_layer_with_tag(tag)
        model = Sketchup.active_model
        new_layer = model.layers.add(tag)
        new_layer.color = Sketchup::Color.new(255, 0, 0) # Set layer color (optional)
        new_layer
      end
  
      def display_error_message(message)
        UI.messagebox(message)
      end
  
      unless @@loaded
        def create_new_group_tag_command
          create_new_group_tag(Sketchup.active_model.selection.to_a)
        end
  
        def create_command(title, icon_path, tooltip, status_bar_text, validation_proc)
          cmd = UI::Command.new(title) { create_new_group_tag_command }
          cmd.small_icon = File.join(File.dirname(__FILE__), icon_path)
          cmd.large_icon = File.join(File.dirname(__FILE__), icon_path)
          cmd.tooltip = tooltip
          cmd.status_bar_text = status_bar_text
          cmd.set_validation_proc(&validation_proc)
          cmd
        end
  
        CMD = create_command(
          'Create, Name, and Tag Group',
          'Icons/Group-Name-Tag.png',
          'Group, Name, and Tag.',
          'Create a new named group of components and apply a new tag to the group using prompts.',
          -> {
            selection = Sketchup.active_model.selection
            selection.grep(Sketchup::ComponentInstance).first ? MF_ENABLED : MF_GRAYED | MF_DISABLED
          }
        )
  
        UI.add_context_menu_handler do |context_menu|
          selection = Sketchup.active_model.selection
          context_menu.add_item(CMD) if selection.grep(Sketchup::ComponentInstance).first
        end
  
        toolbar = UI::Toolbar.new('Group and Tag names.')
        toolbar.add_item(CMD)
        toolbar.restore
  
        @@loaded = true
      end
    end # module Group_Name_Tag
  end # module IDK_Programming

moved from gallery to extension, since you’re introducing an extension :wink:

1 Like

I saw your post to someone this evening suggesting making one place for all of the stuff and I though a stuff place I ought to have! Wherever it is… it’s good ;^)!

well yes, Royce is posting work in progress and finished designs, so it’s gallery themed. But he is posting a separate (32) thread for every update or new design, hence the advice.

Here you’re showing an extension you made to name stuff, so it belongs in the extension sector. But as of your models and WIP, they are most welcome in the gallery.

It’s a simple matter of “where to look”. If next week someone is looking for a renaming tool, they wont look in the gallery, but they’ll search the extension forum :slight_smile:

1 Like

Another utility for Naming the Components in a Selected Group:

Select Group and press Rename Selected Components in Group Toolbar button.

Enter a name for the components.

Press “Enter” or “OK” to rename the components in the selected group.

Main
module IDK_Programming
  module Rename_Comps_In_Group
    @@loaded = false

    def self.create_new_group(selection)
      model = Sketchup.active_model

      # Check if a group is selected
      if selection.empty? || !selection[0].is_a?(Sketchup::Group)
        UI.messagebox("Please select a group.")
      else
        selected_group = selection[0]

        # Prompt for component name
        prompts = ['Enter a name for the components:', '']
        defaults = ['Component Name']
        result = UI.inputbox(prompts, defaults, 'Component Name')

        if result
          component_name = result.first.strip

          # Start an undoable operation
          model.start_operation('Name Components')

          # Store the previous component names for undo
          previous_names = []

          # Update the component names
          selected_group.entities.grep(Sketchup::ComponentInstance).each do |component|
            previous_names << component.definition.name
            component.definition.name = component_name
          end

          # Commit the operation
          model.commit_operation

          # Define an undo method to restore the previous component names
          model.define_singleton_method(:undo_name_components) do
            selected_group.entities.grep(Sketchup::ComponentInstance).each_with_index do |component, index|
              component.definition.name = previous_names[index]
            end
          end

        else
          UI.messagebox("Operation canceled.")
        end
      end
    end

    unless @@loaded
      cmd_rename = UI::Command.new("Rename components in selected group") { create_new_group(Sketchup.active_model.selection.to_a) }
      cmd_rename.small_icon = File.join(File.dirname(__FILE__), 'Icons/Rename-Comps.png')
      cmd_rename.large_icon = File.join(File.dirname(__FILE__), 'Icons/Rename-Comps.png')
      cmd_rename.tooltip = "Rename Components in Group"
      cmd_rename.status_bar_text = "Rename components in a selected group."
      cmd_rename.set_validation_proc {
        if Sketchup.active_model.selection.any? { |entity| entity.is_a?(Sketchup::Group) }
          MF_ENABLED
        else
          MF_GRAYED | MF_DISABLED
        end
      }

      UI.add_context_menu_handler do |context_menu|
        if Sketchup.active_model.selection.any? { |entity| entity.is_a?(Sketchup::Group) }
          context_menu.add_item(cmd_rename)
        end
      end

      toolbar_rename = UI::Toolbar.new("Rename Components")
      toolbar_rename.add_item(cmd_rename)
      toolbar_rename.restore

      @@loaded = true
    end
  end # module Rename_Comps_In_Group
end # module IDK_Programming

IDK_Programming_Rename_Comps_In_Group.rbz (6.2 KB)

1 Like

I like looking a Royce’s models and progress. But yes, could/should be a single collection.

Should have named my thread, “IDK -where to put- Compilation”. ;^)

How about
’ A repository of extensions I have developed that you may or may not find useful.’

Tag Components in Selected Group.

Select group, press Toolbar button, input tag name.

The new tag is applied to all components in the selected group.

Main
module IDK_Programming
    module Tag_Comps_In_Group
      TOOLBAR_NAME = "Tag Components in Group Toolbar".freeze
      BUTTON_NAME = "Apply Tag".freeze
      TOOLTIP = "Apply new tag to components in a group.".freeze
      STATUS_BAR_TEXT = "Create and apply new tag to components in a group".freeze
  
      def self.apply_layer_to_group_components
        tag_name = UI.inputbox(["Enter tag name"], ["New Tag"])[0]
        selected_group = Sketchup.active_model.selection.first
  
        Sketchup.active_model.start_operation("Apply new tag to components in a group", true)
  
        begin
          new_layer = create_tag(tag_name)
          apply_tag_to_components(selected_group.entities, new_layer)
  
          Sketchup.active_model.commit_operation
  
          puts "Tag applied successfully."
        rescue => e
          Sketchup.active_model.abort_operation
          puts "Error: #{e.message}"
        end
      end
  
      def self.create_tag(tag_name)
        model = Sketchup.active_model
        model.layers.add(tag_name)
      end
  
      def self.apply_tag_to_components(entities, layer)
        entities.each do |entity|
          if entity.is_a?(Sketchup::ComponentInstance)
            entity.layer = layer
          end
        end
      end
  
      toolbar = UI::Toolbar.new(TOOLBAR_NAME)
      cmd = UI::Command.new(BUTTON_NAME) { self.apply_layer_to_group_components }
      cmd.small_icon = File.join(File.dirname(__FILE__), 'Icons/Tag-Comp-Group.png')
      cmd.large_icon = File.join(File.dirname(__FILE__), 'Icons/Tag-Comp-Group.png')
      cmd.tooltip = TOOLTIP
      cmd.status_bar_text = STATUS_BAR_TEXT
  
      button_state = MF_DISABLED
      cmd.set_validation_proc do
        selection = Sketchup.active_model.selection
        group_with_components_selected = selection.any? do |entity|
          entity.is_a?(Sketchup::Group) && entity.entities.any? { |e| e.is_a?(Sketchup::ComponentInstance) }
        end
        button_state = group_with_components_selected ? MF_ENABLED : MF_GRAYED | MF_DISABLED
      end
  
      toolbar.add_item(cmd)
      toolbar.show
    end
  end

I was going to put everything and the kitchen sink in here. It’s just that I happened to be working on naming and tagging since I’ve seen the topic in the forum lately and the naming groups bug needs some kind of work-around.

IDK comes from the namespace, IDK_Programming. My brother happens to be a programmer and he laughed when he saw it, so I kept it ;^)

For things to be useful in a forum they should be easily searchable and neatly arranged.
You can certainly dump everything together but people will tend to ignore it pretty quickly.
Making relevant collections of extensions in their own threads would be far more useful.
Having a gallery thread that is full of all your images is quite different to having a thread full of everything.

I’ll take your -and ateliernab’s- advice and keep this topic on extensions.

1 Like

Rename a Group in a Group with a name prompt.

Select a group containing a group.

Press button to enter a name for the group.

In this example the Group in “Rectangles and Circles” will be named, “Rectangles”.

The subgroup is now named, “Rectangles”.

Edit later for code…

A Component Browser:

Many versions in on this wrestling match. Basic functionality but not where I want it to be yet.

1 Like

Component Browser V2, (‘Dark Mode’, CSV export):

CSV for individual folders only…

Trying out multiple html files/pages in Html Dialogs and modifying transform info. Behold the 3 input field position changer:

Continued from here: Draping long components across landscape, including rotation to account for changing terrain elevation? - SketchUp - SketchUp Community

Removed Html Dialog and went back to prompt.

Working on z offset:

Z offset with footings:

May try to drape panels with rotation but hold footings plumb.

1 Like

An Attribute Manager with visibility toggling:

3 Likes

Looks like a good substitute/replacement for “multi-tag” (at least until it’s native). :+1:

1 Like

I saw some discussion about that so I tried making one. There are a few glitches with how the attributes toggle visibility and with toggling visibility of nested and tagged/attributed groups/components. I need to look at scenes more. Since I don’t use them much I don’t understand how they might be better used together.

1 Like