【问题标题】:Sum up Area for material in Components, Google Sketchup组件中材料的汇总区域,Google Sketchup
【发布时间】:2010-05-26 06:15:09
【问题描述】:

我正在制作一个插件来总结 Sketch 中所有材料的面积。 我已经成功获得了所有的面孔等,但现在组件出现了。

我使用术语单级或多级组件,因为我不知道有什么更好的方法来解释组件内部存在组件等等。

我注意到有些组件对 i 的影响还不止 1 个级别。因此,如果您进入一个组件内部,则该组件中可能嵌入的组件也具有材料。所以我想要的是总结特定组件的所有材料,并获得组件内部的所有“递归”材料(如果有的话)。

那么,如何计算组件内所有材料的面积(单层或多层)?

【问题讨论】:

    标签: ruby components area sketchup


    【解决方案1】:

    这就是我要做的,假设您遍历所有实体并检查实体的类型。

    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
    

    你可以对一个组做同样的事情:

    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
    

    希望对你有帮助 拉迪斯拉夫

    【讨论】:

      【解决方案2】:

      Ladislav 的示例并未深入研究所有级别。

      为此,您需要一个递归方法:

      def sum_area( material, entities, tr = Geom::Transformation.new )
        area = 0.0
        for entity in entities
          if entity.is_a?( Sketchup::Group )
            area += sum_area( material, entity.entities, tr * entity.transformation )
          elsif entity.is_a?( Sketchup::ComponentInstance )
            area += sum_area( material, entity.definition.entities, tr * entity.transformation )
          elsif entity.is_a?( Sketchup::Face ) && entity.material == material
            # (!) The area returned is the unscaled area of the definition.
            #     Use the combined transformation to calculate the correct area.
            #     (Sorry, I don't remember from the top of my head how one does that.)
            #
            # (!) Also not that this only takes into account materials on the front
            #     of faces. You must decide if you want to take into account the back
            #     size as well.
            area += entity.area
          end
        end
        area
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-02
        • 1970-01-01
        • 1970-01-01
        • 2020-08-24
        • 1970-01-01
        相关资源
        最近更新 更多