Good morning to all of you.
Can someone explain to me why example 1 below does not work when example 2, below, works?
To run these examples; install them in the Sketchup.temp_dir directory under file names:
For example 1 “right gears.rb” and “engrenagesdroits.html”,
require 'sketchup.rb'
html_dialog = UI::HtmlDialog.new
path = Sketchup.temp_dir + "/engrenagesdroits.html"
puts "path = #{path.inspect}"
html_dialog.set_file path
@label = "un autre label"
js_command = "loadlabel("+@label+")"
html_dialog.execute_script(js_command)
html_dialog.show
<!DOCTYPE html>
<html>
<head>
<title>Engrenages droits</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta http-equiv="MSThemeCompatible" content="Yes"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link href="style/style.css" rel="stylesheet">
</head>
<body >
<p></p>
<form >
<script type="text/javascript">
function init_dialog(){alert ("Amorce du dialogue")};
function loadlabel(label){
alert ("label transmis " + label + " ");
document.getElementById('label1').innerHTML = label;
document.getElementById('label2').innerHTML = 'Module';
document.getElementById('label3').innerHTML = 'Nombre de dents';
}
</script>
<label id="label1" >label1</label>
<br>
<input type="text" id="theinput" name="theinput" value ="20°"/>
<select name="thelist" onChange="combo(this, 'theinput')" onMouseOut="comboInit(this, 'theinput')" >
<option>20°</option>
<option>25°</option>
<option>14°30</option>
</select>
<br>
<p></p>
<label id="label2" for="part">Label2</label>
<br>
<input type="text" id="part" name="part" required pattern="[0-9]{1,5}"
title="Part numbers consist of 3 uppercase letters followed by 4 digits."/>
<br>
<p></p>
<label id="label3" for="part">Label3</label>
<br>
<input type="text" id="part" name="part" required pattern="[0-9]{5}"
title="Part numbers consist of 3 uppercase letters followed by 4 digits."/>
<br>
<p></p>
<input type="submit" formnovalidate value="Save">
<input type="submit" value="Submit">
</form>
<script src="scripts/main.js">
</script>
<button onclick="javascript:loadlabel('Angle de pressions');">Cliquer pour changer les labels ci-dessous</button>
</body>
</html>
For example 2 “point_checker.rb” and “point_checker2.html”.
# Create a class that extends EntityObserver
class EntObserver < Sketchup::EntityObserver
# Invoquerd when the Entity changes
def onChangeEntity(entity)
f_count = 1
# Execute the script with the vertex locations
for v in entity.vertices
args = "'" + v.position.x.to_s + "', '" +
v.position.y.to_s + "', '" + v.position.z.to_s + "'"
$wd.execute_script("setPoint" + f_count.to_s + "(" +
args + ")")
f_count = f_count + 1
end
end
# Invoquerd when the Entity is deleted
def onEraseEntity(entity)
$wd.execute_script("faceDeleted()")
end
end
# Add an Edge and a Face to the model
ents = Sketchup.active_model.entities
face = ents.add_face [0,0,0], [10,0,0], [10,10,0], [0,10,0]
# Associate a new observer with the face and edge
obs = EntObserver.new
face.add_observer obs
# Create a WebDialog and set its HTML
$wd = UI::WebDialog.new "Point Checker"
path = Sketchup.temp_dir + "/point_checker2.html"
$wd.set_file path
$wd.show
<html>
<head>
<script type="text/javascript">
function setPoint1(c1, c2, c3)
{
document.getElementById("pt1").innerHTML = c1 + ", " + c2 +
", " + c3
}
function setPoint2(c1, c2, c3)
{
document.getElementById("pt2").innerHTML = c1 + ", " + c2 +
", " + c3
}
function setPoint3(c1, c2, c3)
{
document.getElementById("pt3").innerHTML = c1 + ", " + c2 +
", " + c3
}
function setPoint4(c1, c2, c3)
{
document.getElementById("pt4").innerHTML = c1 + ", " + c2 +
", " + c3
}
function faceDeleted()
{
document.getElementById("pt1").innerHTML = "Face deleted"
document.getElementById("pt2").innerHTML = "Face deleted"
document.getElementById("pt3").innerHTML = "Face deleted"
document.getElementById("pt4").innerHTML = "Face deleted"
}
</script>
</head>
<body>
<!-- Location of the first vertex -->
Point 1:
<b id="pt1">Initial position</b>
<br />
<!-- Location of the second vertex -->
Point 2:
<b id="pt2">Initial position</b>
<br />
<!-- Location of the third vertex -->
Point 3:
<b id="pt3">Initial position</b>
<br />
<!-- Location of the fourth vertex -->
Point 4:
<b id="pt4">Initial position</b>
<br />
</body>
</html>
If it is possible to operate example 1, how do you do it?
Thank you
On SkectchUp Make Version 17.2.2555 64 Bits
Windows 10 Family Version 8:2 PM