sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Hole plugin

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 3 Posters 234 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      @njeremy2 said:

      I have an another pb... I can't create hole in components or groups. I have to explode it before make a hole

      Sounds like you are not referring to the correct entities collection.

      If you use model.active_entities then it'll create the entities in the currently open group/component. If you want to edit a group you need to reference it's Entities collection: group.entities - When editing a ComponentInstance you need to modify the definition componentinstance.definition.entities.
      (Here's a short summary about how instances and definitions relate in SketchUp: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/ )

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

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Regarding test_hole.rb
        Your method def in_face is outside the class. Move it to the inside of the class so it doesn't pollute the global namespace.


        @entities = @model.entities
        This is your problem with not being able to edit groups/components.
        model.entities always refer to the root entities collection. Use model.active_entities to the current open set of entities.


        (Still looking)

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

        1 Reply Last reply Reply Quote 0
        • N Offline
          njeremy2
          last edited by

          I'm gonna read your articles

          and test what you tell me to do. ๐Ÿ˜„

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            <span class="syntaxdefault"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxcomment">#We&nbsp;get&nbsp;all&nbsp;faces,&nbsp;norms,&nbsp;reversed&nbsp;norms&nbsp;and&nbsp;plans<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_faces&nbsp;</span><span class="syntaxkeyword">=&nbsp;[]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_norms&nbsp;</span><span class="syntaxkeyword">=&nbsp;[]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_norms_reverse&nbsp;</span><span class="syntaxkeyword">=&nbsp;[]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_plans&nbsp;</span><span class="syntaxkeyword">=&nbsp;[]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">j&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">0<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">@</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each&nbsp;</span><span class="syntaxkeyword">do&nbsp;|</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">|<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_faces</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">j</span><span class="syntaxkeyword">]&nbsp;=&nbsp;</span><span class="syntaxdefault">current_ent<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all_norms</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">j</span><span class="syntaxkeyword">]&nbsp;=&nbsp;</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all_norms_reverse</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">j</span><span class="syntaxkeyword">]&nbsp;=&nbsp;</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">!<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_plans</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">j</span><span class="syntaxkeyword">]&nbsp;=&nbsp;</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">plane<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">j&nbsp;</span><span class="syntaxkeyword">+&nbsp;</span><span class="syntaxdefault">1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;</span><span class="syntaxcomment">#&nbsp;end&nbsp;if&nbsp;current_ent&nbsp;is_a&nbsp;face<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">end&nbsp;</span><span class="syntaxcomment">#end&nbsp;current_ent<br />&nbsp;</span><span class="syntaxdefault"></span>
            

            First of all, @entities is incorrect. In your code you set this to @model.entities - which is the root entities collection. The face you pick might be from any group or component - so you want to use the entities collection that face belongs to. face.parent.entities.

            Second of all, you use a counter to insert items into your arrays.

            <span class="syntaxdefault"><br />j&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">0<br /></span><span class="syntaxkeyword">for&nbsp;</span><span class="syntaxdefault">e&nbsp;in&nbsp;model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />&nbsp;&nbsp;array1</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">]&nbsp;=&nbsp;</span><span class="syntaxdefault">foo<br />&nbsp;&nbsp;array2</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">]&nbsp;=&nbsp;</span><span class="syntaxdefault">bar<br />end<br /></span>
            

            No need for that, just push the data directly to the arrays.

            <span class="syntaxdefault"><br /></span><span class="syntaxkeyword">for&nbsp;</span><span class="syntaxdefault">e&nbsp;in&nbsp;model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />&nbsp;&nbsp;array1&nbsp;</span><span class="syntaxkeyword"><<&nbsp;</span><span class="syntaxdefault">foo<br />&nbsp;&nbsp;array2&nbsp;</span><span class="syntaxkeyword"><<&nbsp;</span><span class="syntaxdefault">bar<br />end<br /></span>
            

            Both foo and bar are still located with the same index in each their arrays.

            A cleaned up version of your code snippet:

            <span class="syntaxdefault"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxcomment">#We&nbsp;get&nbsp;all&nbsp;faces,&nbsp;norms,&nbsp;reversed&nbsp;norms&nbsp;and&nbsp;plans<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_faces&nbsp;</span><span class="syntaxkeyword">=&nbsp;[]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_norms&nbsp;</span><span class="syntaxkeyword">=&nbsp;[]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_norms_reverse&nbsp;</span><span class="syntaxkeyword">=&nbsp;[]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_plans&nbsp;</span><span class="syntaxkeyword">=&nbsp;[]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">parent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each&nbsp;</span><span class="syntaxkeyword">do&nbsp;|</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">|<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_faces&nbsp;</span><span class="syntaxkeyword"><<&nbsp;</span><span class="syntaxdefault">current_ent<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all_norms&nbsp;</span><span class="syntaxkeyword"><<&nbsp;</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all_norms_reverse&nbsp;</span><span class="syntaxkeyword"><<&nbsp;</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">!<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">all_plans&nbsp;</span><span class="syntaxkeyword"><<&nbsp;</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">plane<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;</span><span class="syntaxcomment">#&nbsp;end&nbsp;if&nbsp;current_ent&nbsp;is_a&nbsp;face<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">end&nbsp;</span><span class="syntaxcomment">#end&nbsp;current_ent<br />&nbsp;</span><span class="syntaxdefault"></span>
            

            (Still looking)

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

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              I don't understand the rest of your code.

              mini = 10000
              What is this magic number?

              current_norm_reverse.length = 1000
              What is the purpose of this line?

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

              1 Reply Last reply Reply Quote 0
              • N Offline
                njeremy2
                last edited by

                @thomthom said:

                I don't understand the rest of your code.

                mini = 10000
                What is this magic number?

                current_norm_reverse.length = 1000
                What is the purpose of this line?

                me too, that code is from rectangleHoletool.rb from the link in my first post

                1 Reply Last reply Reply Quote 0
                • N Offline
                  njeremy2
                  last edited by

                  I made some test on that plugin.
                  If the entity is longer than ~25000 cm (more than 25400cm, I just test it), you can make any hole. If it's smaller than that value, it working

                  re-edit2 : I can make a hole in groups ! ๐Ÿ˜„ (many thanks thom !)
                  Now I still have the first problem...

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    The logic for finding the opposite face is somewhat odd. The magic number is no good design and puts on an artificial limit.
                    I'm thinking that it'd be better to trace a ray to pick the opposite face. Shoot a ray from one of the vertices (or a calculated face centre) in the opposite direction of the face normal - see if it hit a face with a reversed normal. Then use that length to push-pull.

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

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      Here is one alternative:


                      No working correctly!!

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

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        Meh! Doesn't work for faces outside the current context... ๐Ÿ˜ž

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

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          This one works. ๐Ÿ˜„

                          UPDATE: I'd forgotten to remove some old code. Please check the new version.


                          Removed some redundant code!

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

                          1 Reply Last reply Reply Quote 0
                          • thomthomT Offline
                            thomthom
                            last edited by

                            I saw a tiger lurking...

                            http://images.bcdb.com/ad_im/wb/ltmm/putty_tat.jpg?u=

                            ๐Ÿ˜ฒ

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

                            1 Reply Last reply Reply Quote 0
                            • TIGT Offline
                              TIG Moderator
                              last edited by

                              I made an inept and incorrect comment, which I then decided to erase ๐Ÿ˜ฎ
                              You have fixed it now anyway...
                              BUT where'd it go ๐Ÿ˜•
                              Now it's back again... The art of illusion..........
                              "Now you see it, now you don't."

                              PS:
                              The latest code method's model = face.model is now redundant, because you iterate through the face.parent.entities to find the matching 'back-face'...

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • thomthomT Offline
                                thomthom
                                last edited by

                                @tig said:

                                PS:
                                The latest code method's model = face.model is now redundant, because you iterate through the face.parent.entities to find the matching 'back-face'...

                                True that. (Won't bother to update for that one line though.)

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

                                1 Reply Last reply Reply Quote 0
                                • N Offline
                                  njeremy2
                                  last edited by

                                  ahahah
                                  AHAHAHAHAHA !!! Thank you thomthom !!

                                  It works great !!!
                                  Many many many .... (ctrl+C, ctrl+V) ... many thanks !! ๐Ÿ˜ ๐Ÿ‘

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  • First post
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement