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

Adding groups to an existing group

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 147 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.
  • S Offline
    sdmitch
    last edited by 17 Mar 2013, 21:25

    What am I missing. When the following code is executed it creates groups from each face but grpA, which I thought I was adding groups to, is empty?

    mod = Sketchup.active_model
    ent = mod.active_entities
    sel = mod.selection
    grpA = ent.add_group; grpA.name="container"
    for f in ent.grep(Sketchup;;Face)
     grpB=grpA.entities.add_group f
     grpB.name="#{f.bounds.width} X #{f.bounds.height}"
    end
    puts "grpA contains #{grpA.entities.length} entities"
     
    

    before.png


    after.png

    Nothing is worthless, it can always be used as a bad example.

    http://sdmitch.blogspot.com/

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 17 Mar 2013, 22:28

      The ' entities.add_group(xxx)' ONLY works if the ' xxx' is in the ' active_entities' AND ' entities' IS the ' active_entities'...
      So you need to add those faces [that are also in the ' active_entities'] directly into a group as you add it into the ' active_entities', then add that new group directly into a second group that you then add into the ' active_entities' etc...
      Otherwise get a references to the group and use something like:
      tr=Geom::Transformation.new()another_things_entities.add_instance(group.entities.parent, tr)
      then erase the original group
      group.erase!
      leaving a 'clone' of it inside this other group...
      ???

      You are lucky not to get a Bugsplat when 'crossing entities' 😮

      TIG

      1 Reply Last reply Reply Quote 0
      • S Offline
        sdmitch
        last edited by 17 Mar 2013, 23:03

        Thanks TIG. I sure there is a logical explination as to why you have to add an instance to the container group and delete the original but seems strange to me. Anyway, using your suggestions, this is the modified code and it works just like I wanted.

        mod = Sketchup.active_model
        ent = mod.active_entities
        sel = mod.selection
        grpA = ent.add_group; grpA.name="container"
        tr=Geom;;Transformation.new()
        for f in ent.grep(Sketchup;;Face)
         grpB=ent.add_group f; tr=grpB.transformation
         grpB.name="#{f.bounds.width} X #{f.bounds.height}"
         grpC=grpA.entities.add_instance(grpB.entities.parent,tr)
         grpC.name=grpB.name
         grpB.erase!
        end
        puts "grpA contains #{grpA.entities.length} entities"
         
        

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

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

        Advertisement