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

    Working with selection - ungrouped or within a group

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 8.2k Views 2 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.
    • PixeroP Offline
      Pixero
      last edited by

      (Posted this at the SketchUp forum but since its dissapearing I'd thought I'd post it here also)

      If I want a script to work with a selection of either ungrouped objects or within a group.
      Could something like this work?

      if selection.typename == "Group" { entities=group.entities }
      else { entities=model.active_entities }

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        No.
        You cannot have a selection of entities in and out a group/component at the same time.

        Shetchup.active_model.active_entities returns the whole model if you aren't editing a group/component, and returns the collection of entities of the group/component if you are editing a group/component.

        Shetchup.active_model.selection is completely different from that.
        Hope this helps,

        DB

        1 Reply Last reply Reply Quote 0
        • PixeroP Offline
          Pixero
          last edited by

          I'll try to explain what I'm after.
          Is it possible to make a script work with either the edges/faces in a selected group or the ungrouped edges/faces if there is no group?
          I don't mean at the same time, but to recoginize if the selection is a group or not and be able to work either way.

          If not, I guess I'll have to make two scripts, one for groups and one without.

          1 Reply Last reply Reply Quote 0
          • Didier BurD Offline
            Didier Bur
            last edited by

            Yes it is doable.

            For instance:

            def editing_group?
            if Sketchup.active_model.active_entities.parent.class == Sketchup::ComponentDefinition and Sketchup.active_model.active_entities.parent.group?
            return true
            else return false
            end

            Will return a boolean to tell the script if the user is currently editing a group. BUT using methods of the selection class is independant of that.
            Even if the user is editing a group, Sketchup.active_model.entities can be accessed the usual way, and Sketchup.active_model.active_entities will return a collection of entities of the active group/component.

            If you have to check wether selection is a group or not, use this test:
            Sketchup.active_model.active_entities.parent.class == Sketchup::ComponentDefinition
            (because group are stored as if they are components !)
            and if you have to check wether a particular selected object is part of a group or not, use this test:

            if editing_group? and Sketchup.active_model.active_entities.include?( object_id ) ...
            Hope this helps,

            DB

            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