• 登入
sketchucation logo sketchucation
  • 登入
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Iterating over the faces of a component - without exploding

已排程 已置頂 已鎖定 已移動 Developers' Forum
30 貼文 6 Posters 962 瀏覽 6 Watching
正在載入更多貼文
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • T 離線
    talig
    最後由 編輯 2009年3月23日 上午8:26

    Yeah, I think I've tried that, though only visually.
    I'm not sure they match, but visual testing counts for nothing...
    I'll give it a go, we'll see what the conclusions are 😄

    Avatar: all rights reserved to Bryan Eppihimer

    1 條回覆 最後回覆 回覆 引用 0
    • C 離線
      Chris Fullmer
      最後由 編輯 2009年3月23日 下午4:09

      @thomthom said:

      I was thinking more like selection.to_a.sort
      Is there a .sort method for a string?

      Yeah, but that's the thing. There is no selection.to_a.sort method available. But you can sort them alphabetically if you turn all the array items into strings selection.to_a.to_s.sort. Then it sorts them alphabetically.

      But of course it was decided this won't help here. But maybe elsewhere in the future.

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 條回覆 最後回覆 回覆 引用 0
      • C 離線
        Chris Fullmer
        最後由 編輯 2009年3月23日 下午4:12

        I'm stilll curious Talig, are looking to find all the face normals? OR looking to find square areas? As Thom and Fredo have mentioned, the different rotation and scale of each group and component need to be taken into account.

        Chris

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 條回覆 最後回覆 回覆 引用 0
        • T 離線
          thomthom
          最後由 編輯 2009年3月23日 下午4:57

          @chris fullmer said:

          Yeah, but that's the thing. There is no selection.to_a.sort method available. But you can sort them alphabetically if you turn all the array items into strings selection.to_a.to_s.sort. Then it sorts them alphabetically.

          hmm? .to_s returns an array. And for array objects there's a .sort method. I'm sure I've used this.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 條回覆 最後回覆 回覆 引用 0
          • C 離線
            Chris Fullmer
            最後由 編輯 2009年3月23日 下午5:28

            But it depends what is in the array. Sketchup does not define a heirarchy for how to sort entities like FaceObjects, Component Objects, etc. So the .sort method breaks when put on an array full of items that ruby can't decide how they should be sorted.

            I thought that Sketchup.active_model.selection.to_a.to_s.sort would turn the selection into an array, and then turn each objectID into a separate string and then alphabetize all the strings. But thats not quite right. It turns the whole returned array into a single string, and therefore .sort doesn't change anything anyhow.

            So to get around it, you have to make an array of all entitiesID's turned into strings. Something like:
            sel = Sketchup.active_model.selection selection_strings = [] sel.each do |e| selection_strings << e.to_s end puts selection_strings.sort
            That will effectively create an array of strings, instead of unsortable ObjectIDs. The strings can then be alphabetized by .sort, which makes it much easier to compare - even though the entire idea was thrown out a few posts ago. But if you wanted to sort them, this does work.

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 條回覆 最後回覆 回覆 引用 0
            • F 離線
              fredo6
              最後由 編輯 2009年3月23日 下午6:10

              @talig said:

              Fredo - I'm a female 😄
              About the coordinates: What you're saying is interesting. I assumed I get the absolute model coordinates in any case. That's obviously true in the exploded case, but possibly the cause of the problem in what I'm trying to do. I'll check it out. Thanks! 👍 (and thanks for the to_a tip!)

              I already have everything else up and running, so thanks for trying to help - but really, no call for that.
              All I need is an array of faces equivalent to that of an exploded component. Nothing more, nothing less. 😄

              Sorry for the confusion. I missed your splendid avatar.
              What I wanted to say is that if you have instances of a component, each containing one face, you will always get the same face object for each one when scanning the model: this is the face which is stored in their Definition. The only way to make a distinction is to use the transformation property of each instance (when you explode you have 2 components, each with its own definition). So, in short, don't expect to get a list of faces alone, but rather a list of couple [faces, transformation].

              Fredo

              1 條回覆 最後回覆 回覆 引用 0
              • T 離線
                talig
                最後由 編輯 2009年3月23日 下午11:16

                Fredo,
                Can't I just apply the transformation and save just the transformed face?
                Because that's what I thought I'd do 😄

                • Tali

                Avatar: all rights reserved to Bryan Eppihimer

                1 條回覆 最後回覆 回覆 引用 0
                • T 離線
                  thomthom
                  最後由 編輯 2009年3月24日 上午7:27

                  But then you'd apply it to all instances, won't you? Since that face belongs to the definition. This could be what's throwing your calculations off.

                  What kind of calculations is it that you do?

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 條回覆 最後回覆 回覆 引用 0
                  • A 離線
                    AdamB
                    最後由 編輯 2009年3月24日 下午8:05

                    @talig said:

                    Jim - Thanks.
                    I'm using raytest. But I need a fine-grain detail.
                    See, if I have a component - raytest will return the component as an answer for the ray hitting any of it's faces. I need to know which face in that component was intersected. More accurately, I need to know that a certain face that should have been intersected, isn't - because it's shaded.

                    Thomthom - any thoughts?

                    Thanks again guys,

                    • Tali

                    So I've been lurking on this thread and the bit I don't understand is that Model#raytest does return the Face you pick (along with the Component/Group parts hierarchy). Isn't that what you want?

                    Developer of LightUp Click for website

                    1 條回覆 最後回覆 回覆 引用 0
                    • T 離線
                      talig
                      最後由 編輯 2009年3月24日 下午8:42

                      AdamB,
                      No, the calculation that I'm doing is in the reversed direction. I do not want to raytrace the whole model and see what I hit,
                      I want to select a face (or a few faces) and say how much of it is lit. (i.e. out of the set of rays that should hit it, how many actually hit it first)

                      This is working great, as already stated, for non-grouped/componented selections...

                      Avatar: all rights reserved to Bryan Eppihimer

                      1 條回覆 最後回覆 回覆 引用 0
                      • 1
                      • 2
                      • 2 / 2
                      2 / 2
                      • 第一個貼文
                        21/30
                        最後的貼文
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement