I have noticed an apperently random behaviour in intersect_with
. I am probably making a mistake somewhere, but I honestly can’t see where.
In my plugin I need to intersect a few groups (tools
) with one group containing only one face (aoi[0]
). I want the intersection to appear on the face inside the group aoi[0]
.
Open this model (I still cannot upload on the forum for some reason) and then execute this script from the console.
mod = Sketchup.active_model
ent = mod.active_entities
10.times do
aois = []
ent.grep(Sketchup::Group).each do |e|
if e.attribute_dictionary("RadCalc_Entities") != nil
aois << e if e.attribute_dictionary("RadCalc_Entities")["EntityType"] == "area_of_interest"
end
end
intersect_entities = ["fixed_surroundings", "far_buildings", "new_buildings", "obstructions", "baffles", "shading"]
tools = []
ent.grep(Sketchup::Group).each do |e|
if e.attribute_dictionary("RadCalc_Entities") != nil
tools << e if intersect_entities.include?(e.attribute_dictionary("RadCalc_Entities")["EntityType"])
end
end
mod.start_operation("Intersect")
tools.each do |tool|
# tool.material = "red"
# puts "Before using tool #{tool} -- no faces in aoi: #{aois[0].entities.grep(Sketchup::Face).size}"
tool.entities.intersect_with false, tool.transformation, aois[0].entities, aois[0].transformation, false, aois[0]
# tool.material = nil
end
puts "Faces in aoi: #{aois[0].entities.grep(Sketchup::Face).size}"
mod.abort_operation
end
nil
The script intersects all the tools with the aois[0]
group, counts the number of faces in the group after the interesection and then aborts the operation (equivalent to undo in the UI).
To my surprise, the number of faces keeps changing. For example I get
Faces in aoi: 29
Faces in aoi: 26
Faces in aoi: 27
Faces in aoi: 26
Faces in aoi: 27
Faces in aoi: 26
Faces in aoi: 26
Faces in aoi: 27
Faces in aoi: 31
Faces in aoi: 31
I have also tested it by undoing manually at each step and the bahviour is the same.
Also, and this is what made me start the investigation, the large face within the group disappears!
Finally, if you run the script (inside the times
loop) only once you the face disappears, but if you start to delete the groups outside the central circle at random, and then you put them back again with undo, everything works as expected.
Any idea? Have I made some silly mistake that I can’t see?