SI have been looking around and tried hard to solve this problem, but its giving me a hard time.
Imagine having a dynamic component. Inside that, you have 2 groups.
In the component option you can choose between 2 lengths: 1000 mm and 2000 mm.
When 2000 mm is chosen, Its obvious that the red face area of group 1 is twice the size than group 2.
But - and thats the question - when trying to iterate through all the entities and measuring the red faces it reads the same area - before and after. I beliebe its because the dynamic component resize by scaling, so that the inner-groups still think it has its original size.
Is there a way to get the “real” face area?
The dynamic component has this attribute: "test_dict", "my_dc_group"
The 2 groups inside has these attributes: "test_dict", "my_group", "1"
… (or "2")
The red face of each group has the attribute: "test_dict", "face_area"
To test it I have included a sample.
Every time a new LenX is set in the dynamic component, it should measures the areas of the two red faces and write it to the ruby console - when clicked.
I have included the test.rb sample file + test.png
and the test_dynamic_component.rb
test.zip (4.6 KB)
test_dynamic_component.skp (163.4 KB)
test.rb:
``
require ‘sketchup.rb’
require ‘extensions.rb’
PDB_toolbar = UI::Toolbar.new "test_DC_face_area"
cmd = UI::Command.new("test_DC_face_area") {
model = Sketchup.active_model
ent = model.active_entities
SKETCHUP_CONSOLE.show
ent.each_with_index do |o,i|
next unless o.is_a?Sketchup::Group
it_has_my_dc_group_attr = o.get_attribute "test_dict", "my_dc_group"
n_faces = 1
if it_has_my_dc_group_attr
o.entities.each_with_index do |m,n|
next unless m.is_a?Sketchup::Group
it_has_component_group_attr = m.get_attribute "test_dict", "my_group"
if it_has_component_group_attr
m.entities.each_with_index do |q,r|
next unless q.is_a?Sketchup::Face
it_has_face_attr = q.get_attribute "test_dict", "face_area"
if it_has_face_attr
face_area = q.area
puts 'face number: ' + n_faces.to_s + ' face_area: ' + face_area.to_s
n_faces = n_faces + 1
end # it_has_face_attr
end # m.entities.each_with_index do |q,r|
end # if it_has_component_group_attr
end # o.entities.each_with_index do |m,n|
end # if it_has_my_dc_group_attr
end # @ent.each_with_index do |o,i|
}
cmd.small_icon = "test.png"
cmd.large_icon = "test.png"
cmd.tooltip = "test_DC_face_area"
cmd.status_bar_text = "test_DC_face_area"
cmd.menu_text = "test_DC_face_area"
PDB_toolbar = PDB_toolbar.add_item cmd
PDB_toolbar.show
``