selection = Sketchup.active_model.selection
model = Sketchup.active_model
entities = model.active_entities
selection = Sketchup.active_model.selection
face_count = 0
area_a = 0
# Look at all of the entities in the selection.
selection.each { |entity|
if entity.is_a? Sketchup::Face
face_count = face_count + 1
area_a = area_a + entity.area*0.00064513629
firstface = Array[area_a]
puts "#{firstface}"
end
}
UI.messagebox "Number of faces: #{face_count}"
UI.messagebox "Face area : #{area_a} square meter"
my_thi_dialog = UI::WebDialog.new("Multi Actions", false, "Selection Info", 400, 300, 400, 200, true)
my_thi_dialog.set_file("C:/Program Files/SketchUp/SketchUp 2017/Tools/FaceCount.html")
my_thi_dialog.show()
my_thi_dialog.add_action_callback("get_data") {|my_thi_dialog,action|count_face}
def count_face
selection = Sketchup.active_model.selection
model = Sketchup.active_model
entities = model.active_entities
selection = Sketchup.active_model.selection
face_count = 0
area_a = 0
# Look at all of the entities in the selection.
selection.each { |entity|
if entity.is_a? Sketchup::Face
face_count = face_count + 1
area_a = area_a + entity.area*0.00064513629
firstface = Array[area_a]
puts "#{firstface}"
end
}
UI.messagebox "Number of faces: #{face_count}"
UI.messagebox "Face area : #{area_a} square meter"
end
<!DOCTYPE html>
<html>
<head>
<title>Face Counting
</title>
</head>
<center><h1>Count Object Faces</h1>
<a href="skp:get_data@true">Count Faces </a>
<body>
<body>
</body>
<center><p>Select Object To Count Faces</p>
<br>
</body>
</html>
HTML DIALOG
RUBY CODE
require 'sketchup.rb'
dialog = UI::WebDialog.new("Face And Area Counter", true, "", 410, 600, 200, 100, true)
dialog.set_file("C:/Program Files/SketchUp/SketchUp 2017/Tools/BaseRec.html")
dialog.show
dialog.add_action_callback("typeName") {|dialog, action|
selection = Sketchup.active_model.selection
model = Sketchup.active_model
entities = model.active_entities
selection = Sketchup.active_model.selection
face_count = 0
area_a = 0
# Look at all of the entities in the selection.
selection.each { |entity|
if entity.is_a? Sketchup::Face
face_count = face_count + 1
dialog.execute_script("document.write('Number of faces : #{face_count} <br>')");
area_a = area_a + entity.area*0.00064513629
dialog.execute_script("document.write('Face And Area : #{area_a} <br>')");
firstface = Array[area_a]
puts "#{firstface}"
end
}
UI.messagebox "Number of faces: #{face_count}"
UI.messagebox "Face area : #{area_a} square meter"
dialog.execute_script("document.write('Number of faces : #{face_count} <br>')");
dialog.execute_script("document.write('Full area of faces is : #{area_a}<br>')")
}
HTML FILE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<html>
<head>
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Get your name from Sketchup</title>
<script language="javascript" src="js/prototype.js"></script>
<script language="javascript">
<script>
function dataFromSketchup(){
}
</script>
</head>
<body>
<p id="nameId"></p>
</div>
<a href="skp:typeName@true">Count Object Facess And Area</a><br />
<a href="skp:showConsole@true">Show Console</a>
</body>
</html>