Detect whether all elements of the model intersect
-
I want to detect whether all elements of the model intersect
Like this, but I have no solution, please give me advice, Thank you very much!p = mod.entities.find_all {| ent | ent.is_a (Sketchup :: ComponentInstance)?}
bb = p.bounds.intersect (p.bounds)
if bb.valid?
if p.description == "one"
p.get_attribute ("dynamic_attributes", "name")
else
puts "B"
end
else
puts "no"
end -
@ceit81729 said:
I want to detect whether all elements of the model intersect
Like this, but I have no solution, please give me advice, Thank you very much!p = mod.entities.find_all {| ent | ent.is_a (Sketchup :: ComponentInstance)?}
bb = p.bounds.intersect (p.bounds)
if bb.valid?
if p.description == "one"
p.get_attribute ("dynamic_attributes", "name")
else
puts "B"
end
else
puts "no"
endbounds.intersect results are unreliable and can return a valid boundingbox even when bounds do not overlap as demonstrated with this code. In these cases when bb is valid, the x,y or z coordinate of a bb corner will be 1.0e30 in magnitude.
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection grp = sel.grep(Sketchup;;Group) for i in 1...grp.length bb=grp[0].bounds.intersect(grp[i].bounds) if bb.valid? puts "#{grp[0].name} and #{grp[i].name} intersect" else puts "#{grp[0].name} and #{grp[1].name} do not intersect" end end
-
Hello sdmitch:
First of all, thank you for teaching, I changed your code to meet my needs.
Please look at this picture, ruby console return
"one and two intersect
one and three do not intersect"
so I also want to know how to return
"two and three intersect"
Need to write a loop(for...end)?Because I want to deduct the intersection surface of the overlapping area,
so I need to detect whether all elements of the model intersect.Thank you for teaching again.
-
without needing a pre-selection, something like this should return all combinations...
But it will return two for each pair i.e. a=b and b=a...mod = Sketchup.active_model ent = mod.entities grp = ent.grep(Sketchup;;ComponentInstance) for i in 0...grp.length - 1 grp.each{ |g| next if g == grp[i] # skip comparing to self bb = Geom;;BoundingBox.new.add(g.bounds.intersect(grp[i].bounds)) # @Sam, does this avoid that error? if bb.valid? puts "#{g.name} and #{grp[i].name} intersect" else puts "#{g.name} and #{grp[i].name} do not intersect" end bb.clear } end
john
-
@ceit81729 said:
Hello sdmitch:
so I also want to know how to return
"two and three intersect"
Need to write a loop(for...end)?Because I want to deduct the intersection surface of the overlapping area,
so I need to detect whether all elements of the model intersect.Thank you for teaching again.
Yes, a second For loop is needed.
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection grp = sel.grep(Sketchup;;Group) for i in 0...grp.length-1 for j in i+1...grp.length bb=grp[i].bounds.intersect(grp[j]. if bb.valid? puts "#{grp[i].name} and #{grp[j].name} intersect" else puts "#{grp[i].name} and #{grp[j].name} do not intersect" end end end
In your example with the groups aligned with the X axis, the code works perfectly but returns a valid bb even if the groups are only touching and not overlapping. Perhaps this is desired. If you rotate them so that they are on the Y or Z axis, a valid bb is returned in all cases. So a different or additional test may be needed.
-
@Sam...
it was working for me so I checked the docs...
Your still on v14?
Note: Prior to SU2015 this method would return incorrect result in some cases. For correct result in these versions you must first check if the boundingboxes actually overlap - then call this to get the resulting boundingbox.
john
-
@driven said:
@Sam...
it was working for me so I checked the docs...
Your still on v14?
Note: Prior to SU2015 this method would return incorrect result in some cases. For correct result in these versions you must first check if the boundingboxes actually overlap - then call this to get the resulting boundingbox.
john
Yes I am unfortunately.
Some how I missed that note!
-
this seems to offer solution...
http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=29156#p254014 -
@driven said:
this seems to offer solution...
http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=29156#p254014Yes, that seems to work.
-
Hello everyone
I reference everyone's suggestion
The successful implementation of the following code:mod = Sketchup.active_model
ent = mod.entities
grp = ent.grep(Sketchup::ComponentInstance)
for i in 0...grp.length - 1
grp.each{ |g| next if g == grp[i]
bb = Geom::BoundingBox.new.add(g.bounds.intersect(grp[i].bounds))
if bb.valid?
puts "#{g.name.to_s} and #{grp[i].name.to_s} intersect"
else
puts "#{g.name.to_s} and #{grp[i].name.to_s} do not intersect"
end
bb.clear
}
endNext, I want to know how to calculate the model of dynamic properties of all objects (such as "Lenx", "Leny" ,"Lenz"...etc) after the object intersected the other object.
The case description like this:
First, detect all objects intersect situations like the above code
Second, if name = "column" objects intersect name = "beam" objects(just a simple example)
then, "column" objects dynamic properties("Lenx") deduction "beam" objects dynamic properties("Leny")Thank you for your advice and help
Advertisement