When I create the box, the code creates a folder and saves the date as a csv.
My intent is to select the csv file and fill in the input boxes.
How can I do this?
require "sketchup.rb"
#def dave_HtmlSample()
#load "dave_HtmlSample.rb"
dialog = UI::HtmlDialog.new(
{
:dialog_title => "Draw a box",
:scrollable => true,
:resizable => true,
:width => 500,
:height => 500,
:left => 200,
:top => 200,
:min_width => 150,
:min_height => 150,
:max_width =>100,
:max_height => 50,
:style => UI::HtmlDialog::STYLE_DIALOG
})
html = "
<!DOCTYPE html>
<html>
<head>
<title>Dave Loves You</title>
<style>
body{
display:grid;
}
label {
display: block;
font:
1rem 'Fira Sans',
sans-serif;
}
input,
label {
margin: 0.4rem 0;
}
input[type=number], select {
width: 20%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 20%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
</style>
</head>
<h1>Insert Box Info</h1>
<script>
function sendDataToSketchUp() {
var nm = document.getElementById('nam');
var user_input1 = document.getElementById('id1');
var user_input2 = document.getElementById('id2');
var user_input3 = document.getElementById('id3');
sketchup.getUserInput(nm.value, user_input1.value, user_input2.value, user_input3.value)
}
</script>
<body>
<p>Draw Box or select an existing CSV file</p>
<form>
<label for='file_nm'>Choose an existing file :</label>
<input type='file' id='file_nm' name='file_nm' accept='csv, csv' />
<hr>
Name: <input id='nam' type='text' name='name' value required><br>
width: <input id='id1' type='number' name='width' value=24 required>
length: <input id='id2' type='number' name='length' value=24 required>
depth: <input id='id3' type='number' name='depth' value=4 required>
</form>
<button onclick='sendDataToSketchUp()'>Draw Box</button>
</body>
</html>
"
dialog.set_html(html)
dialog.show
dialog.add_action_callback("getUserInput"){|action_context,nm, user_input1, user_input2, user_input3|
Sketchup.active_model.entities.clear!
width = user_input1.to_f
length = user_input2.to_f
depth = user_input3.to_f
model = Sketchup.active_model
entities = model.active_entities
UI.messagebox(nm)
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, length, 0]
pts[3] = [0, length, 0]
# Add the face to the entities in the model
face = entities.add_face(pts)
face.reverse! unless face.normal.samedirection?(Z_AXIS)
face.pushpull depth
require 'fileutils'
FileUtils.mkdir_p("C:/Users/davem/OneDrive/Documents/testRubyFolders/#{nm}")
box_Info = [
{ Name: nm , Width: width, Length: length , Depth: depth }
]
require 'csv'
CSV.open("C:/Users/davem/OneDrive/Documents/testRubyFolders/#{nm}/testMyCsv.csv", "w") do |csv|
csv << ["Name", "Width", "Length", "depth"]
box_Info.each do |bx|
csv << [bx[:Name], bx[:Width], bx[:Length], bx[:Depth]]
end
end
}
#end