Can I get Model Info Statistics via the API?

I wish to iterate through many components in my library & get the model statistics, the same as you get when you go via the UI of Model Info > Statistics.

I’m doing this so that I can find any poorly made components (I know there are a few hidden away!) that have far too many edges or such.

All the file loading & iterating is all sorted, but I can’t find the statistics to have an equivalent within the API!

There is no “direct” method for Model Info > Statistics… however e.g.:


1 Like

You might try my statistics probe extension available from sketchucation


This method can give you a quick total of used faces throughout the model at all levels.

Getting the number of edges (and other entity counts) is more involved. Example:

model = Sketchup.active_model
cdef_list = model.definitions
num_group_cdefs = cdef_list.count(&:group?)
num_image_cdefs = cdef_list.count(&:image?)
num_comps_cdefs = cdef_list.size - (num_group_cdefs + num_image_cdefs)

num_comp_insts = 0
num_group_insts = 0
num_image_insts = 0
num_section_planes = 0
num_guide_lines = 0
num_guide_points = 0

num_edges = 0
num_edges += model.entities.grep(Sketchup::Edge).size
num_section_planes += model.entities.grep(Sketchup::SectionPlane).size
guide_lines = model.entities.grep(Sketchup::ConstructionLine).size
num_guide_lines += guide_lines * used_instances
guide_points = model.entities.grep(Sketchup::ConstructionPoint).size
num_guide_points += guide_points * used_instances

cdef_list.each do |cdef|
  used_instances = cdef.count_used_instances
  edges_per = cdef.entities.grep(Sketchup::Edge).size
  num_edges += edges_per * used_instances
    num_group_insts += used_instances
  elsif cdef.image?
    num_image_insts += used_instances
    num_comp_insts += used_instances
  section_planes = cdef.entities.grep(Sketchup::SectionPlane).size
  num_section_planes += section_planes * used_instances
  guide_lines = cdef.entities.grep(Sketchup::ConstructionLine).size
  num_guide_lines += guide_lines * used_instances
  guide_points = cdef.entities.grep(Sketchup::ConstructionPoint).size
  num_guide_points += guide_points * used_instances

num_tags = model.layers.size
num_materials = model.materials.size
num_scenes = model.pages.size
num_styles = model.styles.size

I did not show all entity types, but you should get the general idea.

ADD: I also did not deal with unused definitions (ie, ones whose used_instances == 0.) In those cases, the number of entity objects in their entities collection would not be multiplied by the number of instances, so the count would be just those that occur in the entities collection. These definitions do take up space in the model file, but not as much as those having many instances actually in the model geometry.


This extension looks perfect. Thank you.

This is great info. Thank you.