Skip to content

[Request] Sketchup Dialog Box UI Methods #1033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3dmod opened this issue Feb 20, 2025 · 3 comments
Open

[Request] Sketchup Dialog Box UI Methods #1033

3dmod opened this issue Feb 20, 2025 · 3 comments

Comments

@3dmod
Copy link

3dmod commented Feb 20, 2025

Many of my ruby scripts have work arounds because there is no Api methods for interacting with the Dialog boxes.

Could not find an existing Request so here it is.

The highest priority Dialog Boxes are listed below

  • Tags
  • Scenes

Specific Methods

  • .selection
  • .selection.add
  • .selection.remove
  • .selection.clear

I can break these out to separate requests if requested.

@thomthom
Copy link
Member

Can you explain your scenario and use cases in more detail? Why do you need to drive the UI like this?

@3dmod
Copy link
Author

3dmod commented Mar 4, 2025

First would be the ability to make a method to bulk rename selected layers not all layers.

The following is a simplified versions of Bulk Rename All Layers.

def self.bulk_rename_layers(find_txt:, add_txt: )
	sel = Sketchup.active_model.layers.to_a
	return if sel.empty?
	layers_h = sel.map { |v| { e: v, txt: v.name } }
	layers_h.select! { |v| v[:txt].include?(find_txt) }
	return if layers_h.empty?
	layer_h.each { |v|
		v[:n] = v[:txt].gsub( /#{Regexp.quote(h_glb[:find_txt])}/, h_glb[:add_txt]
		v[:target] = Sketchup.active_model.layers[v[:n]]
	)
	Sketchup.active_model.start_operation("Bulk Rename Layers")
		layers_h.each { |e| 
			if v[:target].nil?
				Sketchup.active_model.layers[v[:txt]].name = v[:n]
				v[:target] = Sketchup.active_model.layers[v[:n]]
			else
				ents  = Sketchup.active_model.entities
				top   = ents.select { |ent| ent.layer == v[:txt] }
				dlist = Sketchup.active_model.definitions
				reassign = top + dlist.flat_map do |cdef|
					cdef.entities.select { |ent| ent.layer == v[:txt] }
				end
				next if reassign.empty?
				reassign.each { |ent| ent.layer = v[:target] }
			end
		}
	Sketchup.active_model.commit_operation
end

I would change the first line of the method to something like.

	sel = Sketchup.active_model.tagdialog.selection.to_a

Then at the end of the method after the commit I would add the following

	sel = Sketchup.active_model.tagdialog.selection.clear
	sel_tags = layers_h.map { |v| v[:target] } 
	sel = Sketchup.active_model.tagdialog.selection.add( sel_tags )

@3dmod
Copy link
Author

3dmod commented Mar 5, 2025

The need to drive the UI is very little compared the need to read the UI.

adding selection method is 90% of the need and easier to add to the api.

Sketchup.active_model.tagdialog.selection

10% of the need is the other listed methods

  • .selection.add
  • .selection.remove
  • .selection.clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants