views:

88

answers:

1

I am making a plugin to sum up the area of all the material in a Sketch. I have succeeded in getting all the faces and such, but now the Components come into the picture.

Im using the term single or multi leveled component as i dont know any better way to explain the occurence of having a component inside an component and so on.

I have noticed that some components also have more to i than just 1 level. So if you go inside one component there may be components embedded inside this component that also have materials. So what i want is to sum up all of the material of a specific component and get all the "recursive" materials, if any, inside the component.

So, how do I count the area of all the material inside an component(single or multileveled)?

+1  A: 

Here is what I would do, let's suppose that you loop through all entities and check for type of entity.

if entity.is_a? Sketchup::ComponentInstance
  entity.definition.entities.each {|ent|
    if ent.is_a? Sketchup::Face
      #here do what you have to do to add area to your total
    end
  }
end

You can do the same with a Group with:

if entity.is_a? Sketchup::Group
  entity.entities.each {|ent|
    if ent.is_a? Sketchup::Face
      #here do what you have to do to add area to your total
    end
  }
end

Hope it helps Ladislav

Ladislav