Can I access things from the model info by ruby?

Can I access things from the model info by ruby?
Can I change the model unit by ruby?
Can I access the purge all by ruby?

There is no single or specific API for the contents of the model info window. But almost all of its information can be queried, assembled and in many cases set using methods in the SketchUp Ruby API. There is to my knowledge no single place that states exactly what methods to use. Some investigation and understanding of the API is required.

To your specific questions, yes the units can be manipulated via Ruby. They are contained in an options provider (read up on that in the documentation and come back with specific questions).

There is no single method equivalent to purge. It requires analysis of the model to decide what to purge, a non-trivial task.

I wanted to make a bar with a purge unused button and a button to change to cm, just this.
Today, you need to access the model info to do this, I wanted it in bars.

yes: https://ruby.sketchup.com/UI.html#show_model_info-class_method

yes: https://ruby.sketchup.com/Sketchup/OptionsManager.html https://ruby.sketchup.com/Sketchup/OptionsProvider.html

yes: https://ruby.sketchup.com/Sketchup/Styles.html#purge_unused-instance_method
https://ruby.sketchup.com/Sketchup/Layers.html#purge_unused-instance_method
https://ruby.sketchup.com/Sketchup/Materials.html#purge_unused-instance_method
https://ruby.sketchup.com/Sketchup/DefinitionList.html#purge_unused-instance_method

e.g.
https://sketchucation.com/pluginstore?pln=PurgeAll
https://sketchucation.com/pluginstore?pln=Matt_Toggle_Units

1 Like

Actually no, this only displays the Model Info panel, but does not facilitate changing any of the properties.


An example of printing the Model Info properties to the Console …

model = Sketchup.active_model
if !model.selection.empty?
  obj = model.selection.first
  puts "Selected: #{obj.class.name}"
  puts "Name: #{obj.name}" if obj.respond_to?(:name)
  puts "Definition: #{obj.definition.name}" if obj.respond_to?(:definition)
  puts "Layer: #{obj.layer.name}"
  if obj.is_a?(Sketchup::Edge)
    puts "Length: #{Sketchup.format_length(obj.length)}"
    puts "Soft: #{obj.soft?}"
    puts "Smooth: #{obj.smooth?}"
  end
  if obj.is_a?(Sketchup::Face)
    puts "Area: #{Sketchup.format_area(obj.area)}"
    puts "Front Material: #{obj.material ? obj.material.display_name : '(none)'}" 
    puts "Back Material: #{obj.back_material ? obj.back_material.display_name : '(none)'}"
  else
    puts "Material: #{obj.material ? obj.material.display_name : '(none)'}" 
  end
  if obj.is_a?(Sketchup::Drawingelement)
    puts "Hidden: #{obj.hidden?}"
    puts "Locked: #{obj.locked?}" if obj.respond_to?(:locked?)
    puts "Casts Shadows: #{obj.casts_shadows?}"
    puts "Receives Shadows: #{obj.receives_shadows?}"
  end
  if obj.respond_to?(:definition)
    if dict = obj.attribute_dictionary('SU_InstanceSet')
      puts '----Advanced Instance Attributes-------'
      dict.each_pair do |key,value|
        puts "#{key}: #{value}"
      end
    end
    if dict = obj.definition.attribute_dictionary('SU_DefinitionSet')
      puts '----Advanced Definition Attributes-------'
      dict.each_pair do |key,value|
        puts "#{key}: #{value}"
      end
    end
  end
else
  puts "No selection"
end
2 Likes

You are right…

...BUT

When I show my wallet, you can access, but I do not think you could take out money from it … :stuck_out_tongue_winking_eye:
And your example “does not facilitate changing any of the properties.” “This only displays the Model Info” in other way. :peace_symbol:

Don’t take it upon yourself, all my respect is yours! :slight_smile:

thank you very much, now I can do it here.