ScriptSpot

Forum topic · General Scripting

read pos/rot from a file and apply to listed scene objects

By radioactive · 2018-03-13

Description

Hi, I have this script which reads a txt file with xyz positions and a mesh name
How can I add xyz rotations aswell or change this to rotation only.

Sample.txt format
478,733,-46,mesh01

(
file = memStreamMgr.openFile @"C:\sample.txt"

while NOT file.eos() do
(
local line = filterString (file.readLine()) ", "
if line.count == 4 AND isValidNode (local obj = getNodeByName line[4]) do
obj.pos = [line[1] as float, line[2] as float, line[3] as float]
)
memStreamMgr.close file
)

Comments (1)

read pos/rot from a file and apply to listed scene objects

radioactive · 2018-03-18

I found a solution elsewhere

(rotate script)

(
    file = memStreamMgr.openFile @"C:\position.txt"

    while NOT file.eos() do
    (
        local line = filterString (file.readLine()) ", "
        if line.count == 4 AND isValidNode (local obj = getNodeByName line[4]) do
            obj.pos = [line[1] as float, line[2] as float, line[3] as float]
    )
    memStreamMgr.close file
)

(position script)

(
    file = memStreamMgr.openFile @"C:\rotation.txt"

    while NOT file.eos() do
    (
        local line = filterString (file.readLine()) ", "
        if line.count == 4 AND isValidNode (local obj = getNodeByName line[4]) do
            obj.rotation = eulerAngles (line[1] as float) (line[2] as float) (line[3] as float)
    )
    memStreamMgr.close file
)