try(destroydialog TextBeltRol) catch()
rollout TextBeltRol "Text Belt" width:191
(
fn isTextObject obj = iskindof obj.baseobject Text
local text_template = text_template
local recent_file = unsupplied
local recent_texts
pickbutton pick_template_bt "< Pick Text Template Node >" width:172 autodisplay:on align:#left offset:[-4,2] filter:isTextObject \
tooltip:"Pick a node to be used as a template"
spinner spacing_sp "Spacing: " type:#worldunits range:[0,1e6,10] fieldwidth:58 align:#right offset:[4,6]
spinner roll_sp "Roll: " type:#float range:[-360,360,90] fieldwidth:58 align:#right offset:[4,0]
radiobuttons target_name_rb "Make Name From:" labels:#("Template", "File") default:2 columns:1 align:#left offset:[9,4] offsets:#([92,-16],[92,-16])
checkbutton create_bt "Create From File..." highlightcolor:orange width:104 align:#left offset:[-4,6] across:2 \
tooltip:"Pick a File..."
button repeat_bt "Repeat" width:66 align:#right offset:[4,6] \
tooltip:"Repeat Last File\n +ALT\t- Delete previuos nodes"
progressbar progress_pb color:orange width:172 height:8 align:#center offset:[0,-2]
label info_lb "info..." width:172 align:#left offset:[-4,4]
fn loadTextBeltData file: =
(
local texts
if file == unsupplied do file = getOpenFileName filename:recent_file caption:"Load Text List File" types:"CSV File(*.csv)|*.csv"
if iskindof file String and doesfileexist file and (ss = openfile file) != undefined do
(
recent_file = file
texts = #()
while not eof ss do
(
str = filterstring (readline ss) ","
if (str.count >= 2) do
(
append texts str[2]
)
)
--if texts.count == 0 do texts = undefined
flush ss
close ss
)
texts
)
local recent_nodes
fn make_valid_text text =
(
text = trimleft text " \t"
text = trimright text " "
)
fn make_valid_name text =
(
text = substitutestring text " " "_"
)
on pick_template_bt picked obj do
(
if isvalidnode obj do text_template = obj
)
on pick_template_bt rightclick do
(
if isTextObject (node = selection[1]) do
(
pick_template_bt.object = text_template = node
)
)
fn createTextBelt filename: = if isvalidnode (node = text_template) do
(
texts = loadTextBeltData file:filename
if texts.count do
(
sp = spacing_sp.value
rt = roll_sp.value
tm = node.transform
base = node.name + "_"
col = node.wirecolor * 0.75
info_lb.text = "info..."
progress_pb.value = 0
factor = 100.0/texts.count
-- we skip first...
recent_nodes = for k = 2 to texts.count while not keyboard.escpressed collect
(
text = make_valid_text texts[k]
name = if target_name_rb.state == 1 then uniquename base else (make_valid_name text)
t = copy node name:name parent:node wirecolor:col
t.baseobject.text = text
t.transform = translate (rotateX (copy tm) ((k-2) * rt)) [(k-2) * sp, 0, 0]
progress_pb.value = (k + 1) * factor
t
)
info_lb.text = "create nodes: " + recent_nodes.count as string
recent_texts = texts
recent_nodes
)
completeredraw()
)
on create_bt changed state do undo "Create Text Belt" on
(
createTextBelt()
create_bt.state = off
)
on repeat_bt pressed do undo "Create Text Belt" on
(
if keyboard.altpressed do try (delete recent_nodes) catch()
createTextBelt filename:recent_file
create_bt.state = off
)
on TextBeltRol open do
(
if isvalidnode text_template do pick_template_bt.object = pick_template_bt
)
)
createdialog TextBeltRol escapeEnable:true
-- TextBeltRol.recent_texts
/* CSV file: *******************************************
Rank, Company, Country, Annual Steel Production (million tons)
1, ArcelorMittal, Luxembourg, 96.5
2, China Baowu Group, China, 67.5
3, Nippon Steel Corporation, Japan, 49.3
4, HBIS Group, China, 46.9
5, POSCO, South Korea, 42.9
6, Shagang Group, China, 40.7
7, Ansteel Group, China, 37.4
8, JFE Steel Corporation, Japan, 29.2
9, Jianlong Group, China, 27.9
10, Shougang Group, China, 27.4
*/
1. make a CSV file where the first row is the column headings as usual (we skip it).
2. create a template text spline node that will be used for all created text objects from the file as instance
3. set the spinners to the required values
4. pick the template node
5. create text nodes using the "Create From File..." button
6. use the Undo and "Repeat" buttons if we need to redo the creation with different settings using the last used CSV file.