sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Identifying a group

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 267 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.
    • artmusicstudioA Offline
      artmusicstudio
      last edited by

      hi,
      i went thru some topics about it, but i still can't get it:

      why does this ruby does not identify the group selected?

      
      selection = Sketchup.active_model.selection
      	     
      	     if selection.is_a?(Sketchup;;Group)
      	     puts "selection is a group"
      	     selection = group.entities.parent.entities()
      	     end
      
      

      or do i have to go "insode" the group to be able to select the entities?

      i my case i don't get the message "selection is a group" at all, when 1 group is selected.

      zjanx and ragards
      stan

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        Hi Stan.

        The selection is a collection of entities. You can index and iterate the selection set similar to an Array.

        
        sel = Sketchup.active_model.selection
        puts "#{sel.size} entities selected."
        first_ent = sel.first
        third = sel[2]
        for e in sel
          if e.is_a?(Sketchup;;Group)
            puts "Found a Group"
          end
        end
        
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          hi jim,
          thanx very much.
          i understood iterating thru selection-items, which btw. solves also the next step
          for the eruby to work on

          all groups in the selection.

          i put this small helper online, when it is finished (have to solve the selection of components , especially nested components in the selected group, to read the items-properties of the planes inside those components.

          so thanx, this step works !!!!

          stan

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

            @artmusicstudio said:

            all groups in the selection.

            easy one:
            grps = sel.grep(Sketchup::Group)

            The grep filter method is very fast,... and comes from the Enumerable module which is mixed into many collection classes.
            The grep method creates a new Array instance.

            This then leads to:

            for grp in grps
              gt = grp.transformation
              comps = grp.entities.grep(Sketchup;;ComponentInstance)
              next if comps.empty?
              for comp in comps
                ct = comp.tranformation
                ents = comp.defintion.entities
                # process component's entities, etc.
              end
            end
            

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • artmusicstudioA Offline
              artmusicstudio
              last edited by

              hi dan,
              thanx, ok, again something for my limited brain capacity ( -:) ) ,
              what i have to achive is
              -iterate thru selection (can be groups, compnents or pure entities and combined)
              -check for pure entities in it - at model level (done, works)
              -check for pure entities in groups inside ( 1 level deep only, done, works)
              +
              -check for entities in groups within selected groups ( 1 level deep only)
              -check for entities in components within selected groups ( 1 level deep only)
              -check for entities in components within selected groups ( 1 level deep only)
              -check for entities in components within selected components( 1 level deep only)
              so some brainwork is necessary.
              we shall see.

              by the way:

              when i iterate thru pure elements within a group, the ruby reads them chronologically, so
              newer elements are read out later then the older ones.

              now, i think of finding a way to iterate depending of the Z height.

              is there a way to say directly in the iteration routine, start with lowest elements and go up to the highest?

              the result: the found planes would always be numbered from 1 to x like floors !

              i still have no idea, how to realise this.

              stan

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

                @artmusicstudio said:

                now, i think of finding a way to iterate depending of the Z height.

                is there a way to say directly in the iteration routine, start with lowest elements and go up to the highest?

                You make an array COPY of the collection, and the sort the array using the sort() method that is mixed in from the Enumerable module.

                Use the entity bounds() method to get a Geom::BoundingBox, and it's min() method to get a Geom::Point3d, and use it's z() method to get Length objects for the compare expression.

                def z_sort(coll)
                  coll.to_a.sort {|a,b|
                    a.bounds.min.z <=> b.bounds.min.z
                  }
                end
                
                

                The trick is that the Comparable module must be mixed into the final object's class, on both sides of the compare <=> operator. This will always be true for Numeric and String subclasses. At the console:
                Length.ancestors %(darkgreen)[>> [Length, Float, JSON::Ext::Generator::GeneratorMethods::Float, Numeric, Comparable, Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]]
                Notice that Comparable is already mixed in ?

                πŸ’­

                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