openstudiocore/sketchup_plugin/openstudio/sketchup_plugin/user_scripts/Alter or Add Model Elements/Intersect_Space_Geometry.rb
#define what happens when the measure is run
define what happens when the measure is run
define what happens when the measure is run
def run(model, runner, user_arguments)
    super(model, runner, user_arguments)
    if not runner.validateUserArguments(arguments(model), user_arguments)
      return false
    end
    starting_surfaces = model.getSurfaces
    runner.registerInitialCondition("The building started with #{starting_surfaces.size} base surfaces.")
    if starting_surfaces.size == 0
      runner.registerAsNotApplicable("The building does not have any base surfaces to intersect.")
    end
    spaces = model.getSpaces
    n = spaces.size
    boundingBoxes = []
    (0...n).each do |i|
      boundingBoxes[i] = spaces[i].transformation * spaces[i].boundingBox
    end
    (0...n).each do |i|
      (i+1...n).each do |j|
        next if not boundingBoxes[i].intersects(boundingBoxes[j])
        spaces[i].intersectSurfaces(spaces[j])
        spaces[i].matchSurfaces(spaces[j])
      end 
    end 
    finishing_surfaces = model.getSurfaces
    runner.registerFinalCondition("The building finished with #{finishing_surfaces.size} base surfaces.")
    if starting_surfaces.size == finishing_surfaces.size
      runner.registerAsNotApplicable("No surface intersections were found.")
    end
    return true
  end
def run ( model , runner , user_arguments ) super ( model , runner , user_arguments ) if not runner . validateUserArguments ( arguments ( model ) , user_arguments ) return false end starting_surfaces = model . getSurfaces runner . registerInitialCondition ( "The building started with #{starting_surfaces.size} base surfaces." ) if starting_surfaces . size == 0 runner . registerAsNotApplicable ( "The building does not have any base surfaces to intersect." ) end spaces = model . getSpaces n = spaces . size boundingBoxes = [ ] ( 0 ... n ) . each do | i | boundingBoxes [ i ] = spaces [ i ] . transformation * spaces [ i ] . boundingBox end ( 0 ... n ) . each do | i | ( i + 1 ... n ) . each do | j | next if not boundingBoxes [ i ] . intersects ( boundingBoxes [ j ] ) spaces [ i ] . intersectSurfaces ( spaces [ j ] ) spaces [ i ] . matchSurfaces ( spaces [ j ] ) end end finishing_surfaces = model . getSurfaces runner . registerFinalCondition ( "The building finished with #{finishing_surfaces.size} base surfaces." ) if starting_surfaces . size == finishing_surfaces . size runner . registerAsNotApplicable ( "No surface intersections were found." ) end return true end
define what happens when the measure is run
define what happens when the measure is run
#use the built-in error checking #assign the user inputs to variables #reporting initial condition of model #j #i #reporting final condition of model
model
<not_specific>
runner
<not_specific>
user_arguments
<not_specific>