Redraw all dynamic components?

Try this … (untested) …

ADD (2021-04-10): This file has been posted to this topic:
Force Redraw - #4 by DanRathbun

# Redraw all selected (and siblings)
UI.add_context_menu_handler do |context_menu|
  ss = Sketchup.active_model.selection
  if defined?($dc_observers) && !ss.empty?
    insts = ss.grep(Sketchup::ComponentInstance)
    grps  = ss.grep(Sketchup::Group)
    if !grps.empty?
      grps.each {|grp|
        insts.push(*grp.entities.grep(Sketchup::ComponentInstance)) 
      }
    end
    if !insts.empty?
      dynatts = 'dynamic_attributes'
      insts.select! {|i| i.definition.attribute_dictionary(dynatts) }
      if !insts.empty?
        cdefs = insts.map(&:definition).uniq
        dco = $dc_observers.get_latest_class
        context_menu.add_item("Redraw ALL sibling DCs") {
          cdefs.each {|cdef|
            puts "\nRedrawing Instances of: \"#{cdef.name}\"..."
            cdef.instances.each {|i|
              puts "Redrawing ... #{i.inspect}"
              dco.redraw_with_undo(i)
            }
          }
        }
        context_menu.add_item("Redraw ONLY selected DCs") {
          puts
          insts.each {|i|
            puts "Redrawing Instance of: \"#{i.definition.name}\"... #{i.inspect}"
            dco.redraw_with_undo(i) 
          }
        }
      end # if DC instances were selected
    end # if component instances were selected
  end # if DC loaded and something is selected 
end # context menu handler block

It is the same as above, but after …

    insts = ss.grep(Sketchup::ComponentInstance)

… I added these few lines …

    grps  = ss.grep(Sketchup::Group)
    if !grps.empty?
      grps.each {|grp|
        insts.push(*grp.entities.grep(Sketchup::ComponentInstance)) 
      }
    end

It should separately “grep” groups from the selection set and then iterate them adding any nested component instances to the “redraw” collection.


This would be “a bit” off-topic for this thread. I do have a code snippet that is so old (it was from NOV 2020) … I cannot remember if it works or not. I’ll add the bit to “grep” groups and PM it to you so you can try it.

ADD: FYI, Ryan also had started the topic on resetting DC nominal length attributes …

2 Likes