I’m trying to count all groups and used component depending of the layer they have.
For exemple, I want to know how many “door” taged group and component i have and i want it to count for each definitions.
Eg. :
5 component White door
2 component Front door
1 group Back door
I tried different things. I’m able to get the nb of component used with definition.count_used_instances but i’m not able to count used instance if tagged
I’m able to count tagged instance, entity.is_a?(Sketchup::ComponentInstance) #&& entity.layer.name == "Door"
But it also count doors which are in not used component …
With this code, I’m able to list components of my active entities
model = Sketchup.active_model
entities = model.active_entities
entities.each{ |entity|
if entity.is_a? Sketchup::ComponentInstance
puts "yes it is (#{entity.definition.name}) (#{entity.name}) (#{entity.layer.name}) "
end}
But not to list component in nested entites, and that’s kind of my goal
model = Sketchup.active_model
entities = model.active_entities
def analyze(entity)
puts "yes it is (#{entity.definition.name}) (#{entity.name}) (#{entity.layer.name}) "
entity.definition.entities.each{|subentity|
if subentity.is_a? Sketchup::ComponentInstance
analyze(subentity)
end
}
end
entities.each{ |entity|
if entity.is_a? Sketchup::ComponentInstance
analyze(entity)
end
}
You can create an empty hash with key (layer.name) and value (amount of components) every item check if key exist and update the value…
I’ll try this weekend…
I used to work with “Reports,” but even after exporting, I still had to edit the CSV file to make it compatible with the software that requires the CSV data. By creating my own plugin, I can tailor the program to my specific needs and make it easier to use.
This script is just the first step of a larger project.
I plan to add the ability to see at any time how many components I have in my project realtime.