Created
January 23, 2015 03:08
-
-
Save jimfoltz/79844bb2e01bdce3b92d to your computer and use it in GitHub Desktop.
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 Node | |
attr_reader :ins, :name, :path | |
def initialize(ins, path, name) | |
@ins = ins | |
@path = path | |
@name = name | |
end | |
# Model Transformation | |
def wtransformation | |
tr = Geom::Transformation.new | |
path().each {|e| tr *= e.transformation} | |
tr *= @ins.transformation | |
tr | |
end | |
# Model Position | |
def worigin | |
wtransformation().origin | |
end | |
end | |
def dig(entities, data = [], path = []) | |
entities.grep(Sketchup::Group).each do |g| | |
n = Node.new(g, path.clone, g.name) | |
data << n | |
path << g | |
dig(g.entities, data, path) | |
path.pop | |
end | |
entities.grep(Sketchup::ComponentInstance).each do |i| | |
n = Node.new(i, path.clone, i.definition.name) | |
data << n | |
path << i | |
dig(i.definition.entities, data, path) | |
path.pop | |
end | |
data | |
end | |
def node_map | |
model = Sketchup.active_model | |
entities = model.entities | |
$data = dig(entities) | |
p $data.count | |
end | |
def label_map | |
$data.each_with_index do |node, i| | |
p node | |
o = node.worigin | |
entities.add_text(i.to_s, o) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment