api-issue-tracker icon indicating copy to clipboard operation
api-issue-tracker copied to clipboard

[Request] Sketchup Dialog Box UI Methods

Open 3dmod opened this issue 10 months ago • 3 comments

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.

3dmod avatar Feb 20 '25 16:02 3dmod

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

thomthom avatar Feb 24 '25 09:02 thomthom

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 avatar Mar 04 '25 02:03 3dmod

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

3dmod avatar Mar 05 '25 20:03 3dmod