How do I change the code?
-
mod = Sketchup.active_model
ent = mod.entitiesq = Sketchup.active_model.selection.add(
Sketchup.active_model.definitions["aaa"].instances )a = Sketchup.active_model.selection.add(
Sketchup.active_model.definitions["bbb"].instances )bb = Geom::BoundingBox.new.add(q.bounds.intersect(a.bounds))
if bb.valid?
puts "a"
else
puts "b"
endIt can't run...
How do I change the code? -
Seems like you want to find the intersections of instances.
First remember that the instances might be in different entities contexts...
Using the selection is not always going to work as you expect...
Better to get a list of the definitions' instancesas = mod.definitions["aaa"].instances bs = mod.definitions["bbb"].instances
now iterate one list and check intersections in the other.
hits = {} ### empty hash as.each{|a| es = a.parent.entities hits[a]=[] bs.each{|b| next unless es = b.parent.entities ### same context bb = a.bounds.intersect(b.bounds) hits[a] << b if bb && bb.valid? } } hits.each{|hit| puts "AAA #{hit[0]} intersects BBB #{hit[1]}" }
-
TO TIG:
Thank you for your reply!
If I want to get the component's dynamic attributes(lenx, leny...) by multiple components collision detection?
and I will deduction of the overlapping area(multiple components) after...
(1)multiple components collision detection
(2)get the component's dynamic attributes(lenx, leny...)Thank you for your help!
Advertisement