The following should work with your model. Are you copying via a DC copy function? If so, it is making each copy into its own distinct definition, which isn’t doing what you wanted in terms of sharing. Again, I’m not much into DC’s, so I don’t know if this could be avoided.
def count_DC_instances
sel=Sketchup.active_model.selection[0]
if sel.nil?
puts “please select something first”
return
end
defn=sel.definition
if defn.nil?
puts “the selection isn’t a component”
return
end
name = defn.name
if name =~ /(\w*)#\d+/
basename = $1
puts “looking for definitions like #{basename}”
end
defs = Sketchup.active_model.definitions
count = 0
defs.each do |cdef|
defname=cdef.name
if defname.start_with? basename
cdef.instances.each do |inst|
count=count+1 if inst.visible? && inst.layer.visible?
end
end
end
puts “found #{count} instances like #{basename}”
end
(ugh! I need to learn how to format code in this board!)