sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Move groups with different measures?

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    55 貼文 4 Posters 29.4k 瀏覽 4 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • thomthomT 離線
      thomthom
      最後由 編輯

      Build a hash with the entities as the key and their Z posiiton as value and then sort the hash by the values.

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

      1 條回覆 最後回覆 回覆 引用 0
      • pilouP 離線
        pilou
        最後由 編輯

        Each groups has not a "time creation" trace board? So no need to remake a sorting ?
        Seems I have re-open a new nightmare door 💚

        Frenchy Pilou
        Is beautiful that please without concept!
        My Little site :)

        1 條回覆 最後回覆 回覆 引用 0
        • Chris FullmerC 離線
          Chris Fullmer
          最後由 編輯

          Awesome Pilou! Keep it up, its looking great. You've got lots of good help around here.

          Chris

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

          1 條回覆 最後回覆 回覆 引用 0
          • TIGT 離線
            TIG Moderator
            最後由 編輯

            Try something like...

            
            zeds=[]
            index=0
            groups.each{|group|
               zeds.push(group.bounds.min.z, index)
               index+=1
            }
            zeds.sort!
            sorted_groups=[]
            zeds.each{|z|sorted_groups.push(groups[z[1]]) }
            ### sorted_groups is now groups sorted by Z
            
            

            TIG

            1 條回覆 最後回覆 回覆 引用 0
            • pilouP 離線
              pilou
              最後由 編輯

              Does the group.bounds.min.z only valuable in SU 7?
              Edit seems not 😄

              little try but seems I miss something 😄 (any doubt selection but the sorted_groups gives nothing on the screen)

              model = Sketchup.active_model
              entities = model.entities
              selection = model.selection
              groups = []
              z=0
              zeds=[]
              index=0
              groups.each{|group|
                 zeds.push(group.bounds.min.z, index)
                 index+=1
              }
              zeds.sort!
              sorted_groups=[]
              zeds.each{|z|sorted_groups.push(groups[z[1]]) }
              ### sorted_groups is now groups sorted by Z
              
              sorted_groups.each do |e| 
                point = Geom;;Point3d.new 0,0,z
                t = Geom;;Transformation.new point
                e.transform!(t)  
                z =  z + 1000.mm
              end
              

              Frenchy Pilou
              Is beautiful that please without concept!
              My Little site :)

              1 條回覆 最後回覆 回覆 引用 0
              • pilouP 離線
                pilou
                最後由 編輯

                it's like a snowball on the top of the mountain 😄

                http://www.id2sorties.com/id2photos/5907205456neig.jpg

                Frenchy Pilou
                Is beautiful that please without concept!
                My Little site :)

                1 條回覆 最後回覆 回覆 引用 0
                • TIGT 離線
                  TIG Moderator
                  最後由 編輯

                  groups = [] then nothing set !!!
                  You emptied the groups array...
                  You need to fill it from the selection... 🤓

                  groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup;;Group)}
                  

                  TIG

                  1 條回覆 最後回覆 回覆 引用 0
                  • pilouP 離線
                    pilou
                    最後由 編輯

                    another try found: undefined method ‘[]’ 😕

                    model = Sketchup.active_model
                    entities = model.entities
                    selection = model.selection
                    
                    z=0
                    zeds=[]
                    index=0
                    sorted_groups=[]
                    
                    groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup;;Group)}
                    
                    groups.each{|group|zeds.push(group.bounds.min.z, index)
                       index+=1
                    }
                    zeds.sort!
                    zeds.each{|z|sorted_groups.push(groups[z[1]]) }
                    ### sorted_groups is now groups sorted by 
                    
                    sorted_groups.each do |e| # update!
                      # Now we process the groups
                      point = Geom;;Point3d.new 0,0,z
                      t = Geom;;Transformation.new point
                      # Apply the transformation
                      e.transform!(t)
                      z = z + 100.cm
                    end
                    
                    

                    Frenchy Pilou
                    Is beautiful that please without concept!
                    My Little site :)

                    1 條回覆 最後回覆 回覆 引用 0
                    • thomthomT 離線
                      thomthom
                      最後由 編輯

                      Is that the only error message you get?

                      @unknownuser said:

                      it's like a snowball on the top of the mountain 😄

                      You're hooked now! No way back! 😉 😄

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

                      1 條回覆 最後回覆 回覆 引用 0
                      • TIGT 離線
                        TIG Moderator
                        最後由 編輯

                        Here's some tweaked code

                        def test()
                            model = Sketchup.active_model
                          model.start_operation("Move in Z")
                            entities = model.entities
                            selection = model.selection
                        
                            zeds=[]
                            index=0
                            sorted_groups=[]
                        
                            groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup;;Group)}
                        
                            groups.each{|group|zeds.push([group.bounds.min.z, index])
                               index+=1
                            }
                            zeds.sort!
                            zeds.each{|z|sorted_groups.push(groups[z[1]]) }
                            ### sorted_groups is now groups sorted by
                        
                            z = 0.0
                            sorted_groups.each do |e| # update!
                              # Now we process the groups
                              t = Geom;;Transformation.new(Geom;;Point3d.new(0,0,z))
                              # Apply the transformation
                              e.transform!(t)
                              z = z + 100.cm
                            end
                            
                          model.commit_operation
                          return nil
                          
                        end#def
                        
                        

                        Runs as ' test'.
                        I made a typo - it needed an array [] of two items adding to zeds: zeds.push([group.bounds.min.z, index]) not two 'loose' items as in zeds.push(group.bounds.min.z, index).
                        I made your z = 0 into z = 0.0 as it needs the number as a float, not an integer...
                        Removed 'point' variable and set the point definition directly inside the transformation - not necessary but fewer variables...
                        I added a model.start_operation("")...model.commit_operation so it becomes a one step undo.
                        I added return nil at end so the Ruby-Console doesn't get clogged with info...

                        Tested it - it works...

                        TIG

                        1 條回覆 最後回覆 回覆 引用 0
                        • pilouP 離線
                          pilou
                          最後由 編輯

                          Seems indeed that some corrections were necessary 😄
                          This time works like a charm! Excellent! TIG + Thomthom! Bravo! 😎
                          I will see all that more in detail for learn this little cryptic language ! ☀
                          Very funny plug! 😉
                          For the next Pilou's foolish... 💚
                          ...I need to know the "centroïd" (xyz) of a "bounding box's group"
                          Here of course without different measure, just for little test! 😄 (click image)


                          TIGTHOMPilou.jpg

                          Frenchy Pilou
                          Is beautiful that please without concept!
                          My Little site :)

                          1 條回覆 最後回覆 回覆 引用 0
                          • TIGT 離線
                            TIG Moderator
                            最後由 編輯

                            @unknownuser said:

                            ...I need to know the "centroïd" (xyz) of a "bounding box's group"

                            centre_point=group.bounds.center
                            

                            See http://code.google.com/apis/sketchup/docs/ for all these details 😉

                            TIG

                            1 條回覆 最後回覆 回覆 引用 0
                            • pilouP 離線
                              pilou
                              最後由 編輯

                              Thx I had missed this one 😉

                              Frenchy Pilou
                              Is beautiful that please without concept!
                              My Little site :)

                              1 條回覆 最後回覆 回覆 引用 0
                              • thomthomT 離線
                                thomthom
                                最後由 編輯

                                It'd help if you posted the error messages.

                                However, I can still see the problem here. Sketchup::Component isn't an SU object. Check the manual, you have Sketchup::ComponentDefinition and Sketchup::ComponentInstance. In your case you're looking for a Sketchup::ComponentInstance.

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

                                1 條回覆 最後回覆 回覆 引用 0
                                • pilouP 離線
                                  pilou
                                  最後由 編輯

                                  I have replaced "Group" by "Component" but seems that is not so simple 💚

                                  groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup;;Component)}
                                  
                                      groups.each{|component|zeds.push([component.bounds.min.z, index])
                                  

                                  Else I can yet nest a component inside a group color transparent 💚
                                  That works fine (just disable Edges visible) but I suppose there is another thing 😄


                                  compogroup.jpg

                                  Frenchy Pilou
                                  Is beautiful that please without concept!
                                  My Little site :)

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • pilouP 離線
                                    pilou
                                    最後由 編輯

                                    @ Tig Some cryptic but I will see that 😉
                                    Joint an image for no ambiguities
                                    So here the increment is 300 cm
                                    Edit sorry I have not seen all these speedy results! 😳

                                    @Thomthom! Yes that is that ! e.transform!(t) 😉


                                    zzz.jpg

                                    Frenchy Pilou
                                    Is beautiful that please without concept!
                                    My Little site :)

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • pilouP 離線
                                      pilou
                                      最後由 編輯

                                      Come back in these very dangerous territories 💚

                                      As I understand that retrieve the center XYZ of the bounding box group by

                                       center = boundbox.center 
                                      

                                      but how give these 3 values(?) to these 3 variables ? 😒
                                      xc= ?
                                      yc= ?
                                      zc= ?
                                      must be trivial but yet some foggy for me 😄
                                      PS I read the API from the end to the start, and inverse but this stay mysterious found anything except that 💚

                                      Frenchy Pilou
                                      Is beautiful that please without concept!
                                      My Little site :)

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • thomthomT 離線
                                        thomthom
                                        最後由 編輯

                                        boundbox.center returns an object of type Point3d. You can check what an object is by checking the .class value of an object. That gives you an indication to where to look.

                                        
                                        xc= boundbox.center.x
                                        yc= boundbox.center.y
                                        zc= boundbox.center.z
                                        
                                        

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

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • pilouP 離線
                                          pilou
                                          最後由 編輯

                                          Many thx! ☀
                                          It's always the more easy ans usefull who is not written as example 😒

                                          Frenchy Pilou
                                          Is beautiful that please without concept!
                                          My Little site :)

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • pilouP 離線
                                            pilou
                                            最後由 編輯

                                            ??? = error : in ‘initialize’: undefined local variable or method ‘boundbox’ 😮

                                            model = Sketchup.active_model
                                            entities = model.entities
                                            selection = model.selection
                                            #groups = []
                                            xp=100  # Pivot Point 
                                            yp=100
                                            zp=100
                                            
                                            xc=0  #Center Point of the grouped object
                                            yc=0
                                            zc=0
                                            
                                            xe=0  #End Point of the grouped object
                                            ye=0
                                            ye=0
                                            
                                            selection.each do |e| # update!
                                              # Skip all entities that aren't groups
                                              next unless e.is_a? Sketchup;;Group
                                              # Now we process the groups
                                            
                                             center = boundbox.center 
                                                    xc= boundbox.center.x # ??? error
                                            	yc= boundbox.center.y
                                            	zc= boundbox.center.z
                                            	
                                            xe=xc
                                            ye=yc
                                            ze=zc
                                            if xc<xp 
                                            xe =xc - 100
                                            end
                                              if xc>xp 
                                            xe =xc +100
                                            end
                                            
                                            if yc<yp 
                                            ye =yc - 100
                                            end
                                              if yc>yp 
                                            ye =yc +100
                                            end
                                            
                                            if zc<zp
                                            ze =zc - 100
                                            end
                                              if zc>zp
                                            ze =zc +100
                                            end
                                            
                                              point = Geom;;Point3d.new xe,ye,ze
                                              t = Geom;;Transformation.new point
                                              # Apply the transformation
                                              e.transform!(t)
                                            end
                                            

                                            Frenchy Pilou
                                            Is beautiful that please without concept!
                                            My Little site :)

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

                                            Advertisement