Program "Set attributes" create two attribute dictionaries and sets attributes to selected objects. Attributes can then be read with "Get attributes" program. Attributes can also be deleted.
Program "SetAttributes.rb" and SetSecondAttributes.rb create two attribute dictionaries and sets attributes to selected objects. Attributes can then be read with "GetAttributes.rb" program. Program also counts model faces and calculates total material costs. Material Information is then showed on html page. Attributes can also be deleted.
SetAttributes.rb
require 'sketchup.rb'
wd=UI::WebDialog.new("Attributes", false, "Info",300, 650, 500, 500, true )
wd.add_action_callback("first_ac") do |js_wd, message|
model = Sketchup.active_model
entities = model.active_entities
selection = model.selection
cost = message.to_i
value = model.set_attribute "cost_dictionary", "euro", cost
attrdicts = model.attribute_dictionaries
attrdict = attrdicts["cost_dictionary"]
value = attrdict["euro"]
puts value
end
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/SetAttributes.html" )
wd.show()
load 'SetAttributesSecond.rb'
SetAttributesSecond.rb
require 'sketchup.rb'
wd=UI::WebDialog.new("Attributes", false, "Info",300, 650, 500, 500, true )
wd.add_action_callback("first_ac") do |js_wd, message|
model = Sketchup.active_model
entities = model.active_entities
selection = model.selection
material = message.to_s
value = model.set_attribute "material_dictionary", "metal", material
attrdicts = model.attribute_dictionaries
attrdict = attrdicts["material_dictionary"]
value = attrdict["metal"]
puts value
end
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/SetAttributesSecond.html" )
wd.show()
GetAttributes.rb
require 'sketchup.rb'
wd=UI::WebDialog.new("Attributes", false, "Info",500, 550, 100, 100, true )
wd.add_action_callback("first_ac") do |js_wd, message|
model = Sketchup.active_model
entities = model.active_entities
selection = Sketchup.active_model.selection
attrdict = model.attribute_dictionaries['cost_dictionary']
attrdict.each { | key, value |
puts "#{key} = #{value}"
model = Sketchup.active_model
entities = model.active_entities
selection = Sketchup.active_model.selection
face_count = 0
area_a = 0
selection.each { |entity|
if entity.is_a? Sketchup::Face
face_count = face_count + 1
area_a = area_a + entity.area*0.00064513629
totalcost = area_a*value
puts area_a
puts totalcost
puts face_count
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/INFO.html" )
html ="Material price is " + value.to_s + " euros / square meter.\n""Material area is " + area_a.to_s + " square meter.\n""Total value is " + totalcost.to_s + " euros.\n""The selection has " + face_count.to_s + " faces.\n"
wd.set_html(html)
end
}
}
UI.messagebox " Back to Get Attributes Plugin "
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/COSTATTRIB.html" )
wd.show()
end
wd.add_action_callback("new_ac") do |js_wd, message|
model = Sketchup.active_model
selection = model.selection
attrdict = model.attribute_dictionaries['cost_dictionary']
value = attrdict.delete_key("euro")
attrdict = model.attribute_dictionaries['material_dictionary']
value = attrdict.delete_key("metal")
attrdict = model.attribute_dictionaries['manufacturer_dictionary']
value = attrdict.delete_key("manufacturer")
end
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/Get Attributes.html" )
wd.show()
load 'GetAttributesSecond.rb'
GetAttributesSecond
require 'sketchup.rb'
wd=UI::WebDialog.new("Material Attributes", false, "Info",500, 550, 100, 100, true )
wd.add_action_callback("first_ac") do |js_wd, message|
model = Sketchup.active_model
entities = model.active_entities
selection = Sketchup.active_model.selection
attrdict = model.attribute_dictionaries['material_dictionary']
attrdict.each { | key, value |
puts "#{key} = #{value}"
model = Sketchup.active_model
entities = model.active_entities
selection = Sketchup.active_model.selection
face_count = 0
area_a = 0
selection.each { |entity|
if entity.is_a? Sketchup::Face
face_count = face_count + 1
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/INFO.html" )
html ="Material name is " + value + ""
wd.set_html(html)
end
}
}
UI.messagebox " Back to Get Attributes Plugin "
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/COSTATTRIB.html" )
wd.show()
end
wd.add_action_callback("new_ac") do |js_wd, message|
model = Sketchup.active_model
selection = model.selection
attrdict = model.attribute_dictionaries['cost_dictionary']
value = attrdict.delete_key("euro")
attrdict = model.attribute_dictionaries['material_dictionary']
value = attrdict.delete_key("metal")
attrdict = model.attribute_dictionaries['manufacturer_dictionary']
value = attrdict.delete_key("manufacturer")
end
wd.set_file( "C:/Program Files/SketchUp/SketchUp 2017/Tools/Get Attributes.html" )
wd.show()
SetAttributes and GetAttributes Plugins
Attributes HTML file
<!DOCTYPE html>
<html>
<head>
<title>Attributes
</title>
</head>s
<center><h1>Add Attributes</h1>
<script>
function sendDataToSketchUp() {
var user_input1 = document.getElementById('id1');
var user_input3 = formid.ddlselect[formid.ddlselect.selectedIndex]
query = 'skp:getUserInput1@' + user_input1.value
window.location.href = query;
query = 'skp:getUserInput3@' + user_input3.value
window.location.href = query;
}
</script>
<script>
function LoadFromRubyFunction() {
var user_input3 = formid.ddlselect[formid.ddlselect.selectedIndex]
query = 'skp:execRubyFunction@' + user_input3.value
window.location.href = query;
}
</script>
<body>
<script>
</script>
<body>
</body>
<center><p>Model Attributes</p>
<form>
<center>Give Value: <input id='id1' type='number' name='length' value=100 required><br>
<br>
</form>
<br>
<br>
<form name="formid">
<select name="ddlselect" onchange="myFunction()">
<option value="Part Price">Part Price</option>
<option value="Part Weight">Part Weight</option>
<option value="Part Height">Part Height</option></select>
</form>
<label id="input"></label>
<br> <center> <button onclick='sendDataToSketchUp()'>Add Attributes To Model</button>
<br>
<center> <button onclick='LoadFromRubyFunction()'>Load Attributes</button>
<br>
</body>
</html>
Attributes Ruby file
<!DOCTYPE html>
<html>
<head>
<title>Attributes
</title>
</head>
<center><h1>Add Attributes</h1>
<script>
function sendDataToSketchUp() {
var user_input1 = document.getElementById('id1');
var user_input3 = formid.ddlselect[formid.ddlselect.selectedIndex]
query = 'skp:getUserInput1@' + user_input1.value
window.location.href = query;
query = 'skp:getUserInput3@' + user_input3.value
window.location.href = query;
}
</script>
<script>
function LoadFromRubyFunction() {
var user_input3 = formid.ddlselect[formid.ddlselect.selectedIndex]
query = 'skp:execRubyFunction@' + user_input3.value
window.location.href = query;
}
</script>
<body>
<script>
</script>
<body>
</body>
<center><p>Model Attributes</p>
<form>
<center>Give Value: <input id='id1' type='number' name='length' value=100 required><br>
<br>
</form>
<br>
<br>
<form name="formid">
<select name="ddlselect" onchange="myFunction()">
<option value="Part Price">Part Price</option>
<option value="Part Weight">Part Weight</option>
<option value="Part Height">Part Height</option></select>
</form>
<label id="input"></label>
<br>
<center> <button onclick='sendDataToSketchUp()'>Add Attributes To Model</button>
<br>
<center> <button onclick='LoadFromRubyFunction()'>Load Attributes</button>
<br>
</body>
</html>