Last active
August 29, 2015 14:01
-
-
Save dmvt/0402939b6635c98686dd to your computer and use it in GitHub Desktop.
Get a printed list of components in Sketchup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ComponentListExtractor | |
attr_reader :components | |
def initialize | |
@components = find_components.freeze | |
end | |
def to_s | |
String.new.tap do |out| | |
components.each do |name, component| | |
out << "#{component[:count]}x #{name} (#{component[:dimensions].join('" x ')}\")\n" | |
end | |
end | |
end | |
private | |
def find_components | |
{}.tap do |components| | |
component_entities.each do |entity| | |
components[entity.definition.name] ||= { | |
count: 0, | |
dimensions: entity.scaled_size, | |
instances: [] | |
} | |
components[entity.definition.name][:count] += 1 | |
components[entity.definition.name][:instances] << entity | |
end | |
end | |
end | |
def component_entities | |
entities.map do |entity| | |
entity if entity.typename == "ComponentInstance" | |
end.compact | |
end | |
def entities | |
model.entities | |
end | |
def model | |
Sketchup.active_model | |
end | |
end | |
list = ComponentListExtractor.new | |
list.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment