sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Another grouping a group issue?

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 3 Posters 193 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.
    • T Offline
      tomot
      last edited by

      I'm not quite happy with my 2D Wall Section Tool yet, and improvements are on the way.
      http://forums.sketchucation.com/viewtopic.php?f=323&t=39372
      Currently the routine that draws each of the 3 arcs, is a group, this group is then transformed and copied repeatedly along the entire wall length.
      If I later decide to remove the insulation arcs, I have to delete each 3 arc group individually. Is there a way to group the entire group of insulating arcs for more easy deletion?

      [my plugins](http://thingsvirtual.blogspot.ca/)
      tomot

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

        Let's say your '2d-section' is referred to as group_section and you can then add some geometry to its entities
        group_section.entities.add_line(p0,p1)
        etc etc...
        BUT for your hatching you just need to make a group inside the group_section group's entities thus
        group_hatch=group_section.entities.add_group()
        And now add you hatching geometry to the entities of that nested group
        group_hatch.entities.add_line(p2,p3)
        etc etc
        Now you can delete the hatching group in one go as all of its geometry is 'contained'...
        I used '.add_line' but any '.add_' method will work...
        You can make any number of side by side or nested groups, even groups inside nested groups ! πŸ€“

        TIG

        1 Reply Last reply Reply Quote 0
        • T Offline
          tomot
          last edited by

          I have been struggling with this grouping of groups stuff. The attached code which draws joists @ centers, between 2 points is similar to the insulation example I talked about. This CODE between the IF statement groups each joist.

          if( @joist != "OFF" )  
          
              #...get the number of joists required for the related @vec/@joc
              @num_joist = ((@vec/@joc)+1).to_i 
                   
              definitions=model.definitions
              count=definitions.add
              entities=count.entities
              
              #...draw 1st joist
              base=entities.add_face(@pt33, @pt33a, @pt3a, @pt3) 
              base=entities.add_line(@pt33, @pt3a)
              base=entities.add_line(@pt33a, @pt3)
              
                 
              #...transform joist location 
              t=Geom;;Transformation.translation(Geom;;Vector3d.new(0, 0, 0))
              entities=model.active_entities
              
              entities.add_instance(count, t)
              
              #...copy joists to their new locations
              i = 1
              while i < @num_joist
                 # Transformation
                 i = i + 1
                 vec = @pt44b - @pt3a # width betweeen which joists are to be drawn
                 vec.length = @joc*(i-1)
                 t=Geom;;Transformation.translation(Geom;;Vector3d.new(0,@joc*(i-1), 0))
                 t=Geom;;Transformation.translation(vec)
                 entities.add_instance(count, t)
              end
          end  # if 
          

          I don't know enough about Ruby coding if the
          %(#FF0000)[definitions=model.definitions
          count=definitions.add
          entities=count.entities]
          code is interfering with the new grouping of groups proposal. I don't seem to be able to add the proposed code, causing all the grouped joists to be added to a new group..... help!

          [my plugins](http://thingsvirtual.blogspot.ca/)
          tomot

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            This statement just creates a new identity transform:
            t = Geom::Transformation.translation(Geom::Vector3d.new(0, 0, 0))
            you might as well just use:
            t = Geom::Transformation.new()

            In your while loop, you have two successive reference assignments to t, and the first is frivolous as it's being overwritten by the 2nd.
            Either set up the reference vec and use it, or use the literal, as in the first assignment to t, but not both.

            #...copy joists to their new locations
                i = 1
                while i < @num_joist
                   # Transformation
                   i = i + 1
                   vec = @pt44b - @pt3a # width betweeen which joists are to be drawn
                   vec.length = @joc*(i-1)
                   t=Geom;;Transformation.translation(Geom;;Vector3d.new(0,@joc*(i-1), 0))
                   t=Geom;;Transformation.translation(vec)
                   entities.add_instance(count, t)
                end
            end  # if 
            

            General issues:

            Identifiers: choose descriptive identifiers for your instance vars, so that when you post code, we know what they represent. Otherwise we have to guess, (if we even wish to try, and many readers will just go on to the next post.)

            So help yourself, by helping us to help you.

            Write more understandable code.
            For example, reusing the reference count might save a few bytes of memory, but big deal. This code would be wrapped within a method anyway, and all locals would be garbage-collected when the method call returns.
            So I would use joist = definitions.add("Joist") and joist_ents = joist.entities, then further down use a different reference to refer to the context entities (like: mod_ents and/or act_ents.)

            Next issue... while loop. Normally used when you don't know when the exit condition will be met. But you do, .. the user will tell the method how many joists they want.
            So use:
            for i in 1..@num_joists do ... repetitive code end
            and you don't need to init i, nor increment i during the loop, as the for will do it automatically.

            @tomot said:

            I don't seem to be able to add the proposed code, causing all the grouped joists to be added to a new group..... help!

            You are adding instances of ComponentInstance, not Group.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              By the way... the word count is one of the standard method names in the API. You should avoid using it (it might confuse Ruby into thinking your making a method call. Sometimes Ruby can tell the difference, sometimes not.)

              You should check the method index before choosing var names:
              http://code.google.com/apis/sketchup/docs/methods.html#index_c

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • T Offline
                tomot
                last edited by

                I forgot to mention: I have used this particular statement with and without if, it replicates whatever you throw into it. I did not write it. I simply copied it blindly, and it works flawlessly, in this particular situation it replicates the three statements starting with base=entities.... into a group. However what it does not do presently is collect all grouped base=entities...., into one master group containing all base=entities....
                Seems almost too easy too describe in words, were it not for Ruby getting in my way. πŸ˜„

                [my plugins](http://thingsvirtual.blogspot.ca/)
                tomot

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tomot
                  last edited by

                  @dan rathbun said:

                  By the way... the word count is one of the standard method names in the API. You should avoid using it (it might confuse Ruby into thinking your making a method call. Sometimes Ruby can tell the difference, sometimes not.)

                  You should check the method index before choosing var names:
                  http://code.google.com/apis/sketchup/docs/methods.html#index_c

                  while i < @num_insul
                         # Transformation
                         i = i + 1
                         vec = @pt44b - @pt3a
                         vec.length = @vec4*(i-1)
                         t=Geom;;Transformation.translation(Geom;;Vector3d.new(0,@vec4*(i-1), 0))
                         t=Geom;;Transformation.translation(vec)
                         entities.add_instance(count, t)
                      end  
                  

                  Interesting! I have 2 scripts, on replicates joists the other studs both use count. One script constantly gives me an '<' error in the console the other does not. ....very aggravating!

                  [my plugins](http://thingsvirtual.blogspot.ca/)
                  tomot

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    I don't know who / where you copied it from.. but it's a mess!
                    (Sometimes you have to do the cleanup yourself.)

                    Since it adds the instances to the active_entities, then IF the user (you,) are not within a Group or Component editing context, then the new joists will be added to the model.entities, because in this case model.entities == model.active_entities, understand?

                    You would need to have double-clicked on a Group or Component before running the "joist" command, in order to have them added INSIDE.

                    Or... you create an argument for the method, that you use to pass a reference to the Group or Component that you wish the joists add to.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      tomot
                      last edited by

                      I will chew your suggestions over Dan .... tomorrow is another day! πŸ˜’

                      [my plugins](http://thingsvirtual.blogspot.ca/)
                      tomot

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @tomot said:

                        Interesting! I have 2 scripts, on replicates joists the other studs both use count. One script constantly gives me an '<' error in the console the other does not. ....very aggravating!

                        Yep.. and same with:
                        entities.add_instance(count, t)
                        The word 'entities' is a method name. It often works OK, but is poor form.
                        Using something like:
                        grp_ents.add_instance(joist, tx_vec)
                        is much better, and more understandable.

                        I'm not here much anymore.

                        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