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

    Nested groups

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

      Hi all, I need some help in understanding nested groups.I have to build something like as follows:

      LEVEL_0 (a group)
      |_____ OBJECTS_TYPE_1 (a group)
      |_________ OBJ_1a (a group)
      |_________ OBJ_2a (a group)
      |_________ ...
      |_________ OBJ_na (a group)
      |_____ OBJECTS_TYPE_2 (a group)
      |_________ OBJ_1b (a group)
      |_________ OBJ_2b (a group)
      |_________ ...
      |_________ OBJ_mb (a group)

      So I used:

      
      @level[0] = SkecthUp.active_model.active_entities.add_group()
      @level[0].name="LEVEL_0"
      
      @sublevel1 = @level[0].entities.add_group
      @sublevel1.name = "OBJECTS_TYPE_1"
      
      @sublevel2 = @level[0].entities.add_group
      @sublevel2.name = "OBJECTS_TYPE_2"
      
      
      
      # loop code for geometry generation
      i=0
      n=5
      
      @type1=[] # I waant to store OBJECTS_TYPE_1 into an array for further processing
      @type2=[] # same ...
      n1=0 # incremental number of OBJECTS_TYPE_1
      n2=0 # incremental number of OBJECTS_TYPE_2
      
      while i < n
          pts << [xj,yj,zj]  # xj, yj, zy getted from other part of my script
          if (layer=="TYPE_1")
              @OBJ_1a = @sublevel1.entities.add_group
              ent1=@OBJ_1a.entities
              @type1[n1] = ent1.add_face(pts)
              @type1[n1].pushpull(hpil,false)
              if n1<9
      		@OBJ_1a.name= "OBJ_0" + (n1+1).to_s + "a"
      	else
      		@OBJ_1a.name= "OBJ_" + (n1+1).to_s + "a"
      	end
      	n1 += 1
          elsif (layer=="TYPE_2")
              @OBJ_2a = @sublevel2.entities.add_group
              ent2=@OBJ_2a.entities
              @type2[n2] = ent2.add_face(pts)
              @type2[n2].pushpull(hpil,false)
              if n2<9
      		@OBJ_2a.name= "OBJ_0" + (n1+1).to_s + "b"
      	else
      		@OBJ_2a.name= "OBJ_" + (n1+1).to_s + "b"
      	end
      	n2 += 1
          end
      end
      
      
      

      Running my code I get an error

      Error: #<TypeError: reference to deleted Group>

      The error is on line

       @OBJ_1a = @sublevel1.entities.add_group 
      

      of the code above. What is wrong?

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

        As soon as you make an empty group.. you must ADD something to it in the next statement or two.
        A cpoint is often used.

        If you don't,.. SketchUp will delete the empty group automatically.

        I'm not here much anymore.

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

          As Dan says... an empty group won't last for long.
          Add something like this:
          @sublevel1.entities.add_cpoint(ORIGIN)
          immediately after making the group [you need to do it for every 'empty' nested group]...
          You won't need to do it where you add a group into a group etc, as then that means the container-group is no longer empty as it contains a nested group!
          Then to tidy up later, after there is some geometry inside the group, use something like:
          group.entities.erase_entities(group.entities.grep(Sketchup::ConstructionPoint))
          to delete the cpoint [substitute the 'reference' needed, where I have used 'group']

          TIG

          1 Reply Last reply Reply Quote 0
          • bomastudioB Offline
            bomastudio
            last edited by

            @dan rathbun said:

            As soon as you make an empty group.. you must ADD something to it in the next statement or two.
            A cpoint is often used.

            If you don't,.. SketchUp will delete the empty group automatically.

            Thank you Dan!!! πŸ˜„

            1 Reply Last reply Reply Quote 0
            • bomastudioB Offline
              bomastudio
              last edited by

              @tig said:

              As Dan says... an empty group won't last for long.
              Add something like this:
              @sublevel1.entities.add_cpoint(ORIGIN)
              immediately after making the group [you need to do it for every 'empty' nested group]...
              You won't need to do it where you add a group into a group etc, as then that means the container-group is no longer empty as it contains a nested group!
              Then to tidy up later, after there is some geometry inside the group, use something like:
              group.entities.erase_entities(group.entities.grep(Sketchup::ConstructionPoint))
              to delete the cpoint [substitute the 'reference' needed, where I have used 'group']

              Thanks TIG!! Now all the world is clear as a sunny day!!! β˜€
              I'm going to correct my code..... πŸ‘

              1 Reply Last reply Reply Quote 0
              • bomastudioB Offline
                bomastudio
                last edited by

                😍 😍 THANXXXXXXXXX!!!! it works!!!!!!

                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