Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
π« Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download
[Code] intersect_with?() Group test method
-
*Author*::*SomeLib*.intersect_with?( grp1, grp2 [, precision] )Test whether two groups have a boolean intersection. Returns
true||false.( Method is non-destructive, and does not change either reference. )
module Author;;SomeLib class << self # PROXY CLASS #{ intersect_with?( grp1, grp2 [, precision] ) #{ # Test whether two groups have a boolean intersection. # # (Method is non-destructive, and does not change either reference.) # # grp1 ; a Sketchup;;Group or Sketchup;;ComponentInstance reference. # grp2 ; a Sketchup;;Group or Sketchup;;ComponentInstance reference. # precision ; number of decimal places for precision (default = 3.) # # Returns; true, if "grp1" intersects with "grp2" argument. # false, if they do not intersect. # nil, if either are not manifold, Sketchup is not Pro, # or if the groups are in different contexts. #} def intersect_with?( grp1, grp2, prec=3 ) #{ unless grp1.is_a?(Sketchup;;Group) || grp1.is_a?(Sketchup;;ComponentInstance) raise(TypeError,"(arg 0) Sketchup;;Group or Sketchup;;ComponentInstance expected.",caller) end unless grp2.is_a?(Sketchup;;Group) || grp2.is_a?(Sketchup;;ComponentInstance) raise(TypeError,"(arg 1) Sketchup;;Group or Sketchup;;ComponentInstance expected.",caller) end return nil unless Sketchup.is_pro? && Sketchup.version.to_i>7 return nil unless (grp1.manifold? && grp2.manifold?) return nil unless (grp1.model == grp2.model) return nil unless (grp1.parent == grp2.parent) #} tgrp = nil retval = false mdl = grp1.model vola = volb = grp1.volume.to_l # begin # mdl.start_operation('Intersect Test') ### # if grp1.is_a?(Sketchup;;Group) tgrp = grp1.copy else grp1.is_a?(Sketchup;;ComponentInstance) tgrp = grp1.parent.entities.add_instance(grp1.definition,grp1.transformation) end # vola = grp2.trim(tgrp).volume.to_l # ### mdl.commit_operation # rescue Exception => e mdl.abort_operation puts(e.message) puts(e.backtrace) return nil else # Sketchup.undo # if prec==3 return puts( vola == volb ? false ; true ) else aft = ((vola*(10**prec)).to_i)/((10**prec).to_f) bef = ((volb*(10**prec)).to_i)/((10**prec).to_f) return puts( aft == bef ? false ; true ) end end # end #} end # PROXY CLASS end # moduleTested OK with 2 cuboids that intersected at their corners by 0.001" x 0.001" x 0.001"

-
Hi,
May I know after determining if the 2 groups/ components/ faces are intersected. How do I get the area of the intersection?
Advertisement