Making a hole in a group with multiple subgroups
-
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
-
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 notreturn
??@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...
-
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.
-
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. -
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.
Advertisement