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

Making a hole in a group with multiple subgroups

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 669 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.
  • B Offline
    biervat
    last edited by 3 Mar 2017, 16:06

    I'm writing a script to make a hole in a group with multiple subgroups.
    I iterate through the group and subtract a box if they intersect.
    The boxes are created correctly but it gives the following error:
    #<Deleted Entity:0x65d174a8>
    Error: #<TypeError: reference to deleted Group>

    def addhole(beginx,beginz,breedte,hoogte)
        #beginpunt x = afstand tot begincoordinaat muur; y = hoogte tov nulpas
        dikte = @wandgroep.local_bounds.depth
        openingbound = Geom;;BoundingBox.new
        openingbound.add([beginx,0,beginz],[beginx + breedte,dikte,beginz + hoogte])
        points = [
            [beginx,0,beginz],
            [beginx,0,beginz + hoogte],
            [beginx + breedte,0,beginz + hoogte],
            [beginx + breedte,0,beginz]
        ]
        @wandgroep.entities.to_a.each do |element|
          if not openingbound.intersect(element.bounds).valid?
            if element.typename == 'Group'
              if element.manifold?
                opening = @wandgroep.entities.add_group
                opening.entities.add_face(points).pushpull(dikte)
                result = opening.subtract(element)
              else
                element.entities.to_a.each do |subelement|
                  opening = subelement.entities.add_group
                  opening.entities.add_face(points).pushpull(dikte)
                  result = opening.subtract(subelement)
                end
              end
            end
          end
        end
      end
    
    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 3 Mar 2017, 18:48

      The error-message usually includes a line number.
      That helps you find where things are going wrong...

      It seems to relate to a missing Group ??

      A few ideas...
      @wandgroep
      what is it ?
      Is @wandgroep.valid? when the code runs ?
      If not return ??

      @wandgroep.entities.to_a.each do |element|...
      perhaps add an extra line at the start of that block...
      next unless element.valid?
      so only valid elements get processed...

      PS: I swapped your [ruby] tags for [code] to make it indent and be easier to read...

      TIG

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 3 Mar 2017, 23:05

        For faster speed, change:
        if element.typename == 'Group'
        with:
        if element.is_a?(Sketchup::Group)

        Reason: Ruby string comparison is slow, but object identity is fast.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • B Offline
          biervat
          last edited by 7 Mar 2017, 14:11

          Yes @wandgroep is a group containing several groups which contain several manifold groups.

          the error occurs in the line "opening = subelement.entities.add_group" after the first subtraction is done. When I delete the subtract line, I don't get the error and every cube is drawn correctly in the correct group.
          It looks like all subelement are deleted after I subtract the first subelement.

          1 Reply Last reply Reply Quote 0
          • B Offline
            biervat
            last edited by 7 Mar 2017, 15:07

            I've found the problem. It was in line "opening = subelement.entities.add_group"
            I created a group inside the group I wanted to subtract.

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

            Advertisement