ScriptSpot

Forum topic · General Scripting

Error in Call function

By nounei24 · 2016-05-20

Description

Hi all,

I am still a newbie with Maxscript. I have followed methods to create the following script however it fails when looking for negative numbers. I thought float would be able to work for negative numbers as well as positive. This script takes in a text file that has this type of information.
PILECAP_P1|MXshape-O100-001|4.2|4.2|1.5|2|2|1.5|0.9|10|6|PILECAP_P1_PILE_|0|-1.5|1.5|0|0|0|0
the error is with the -1.5.

can someone help please?

(
arr = $'PILE*' as array
for i = 1 to arr.count do
(
if arr[i] != undefined do
(
delete arr[i]
)
)
n = getOpenFileName caption:"Open PileCap File:" filename:"C:/MX Projects/Caulfield to Dandenong Nine/07_Max/02_Macros/Des a501/"
f = openfile n mode:"r"
count = 0
while not eof f do
(
l = readline f
datain = filterstring l "|"
--arr = datain[1] as array
--pierno=4
LL= datain[3] as float
WW = datain[4] as float
TT1 = datain[5] as float
TT=-1*TT1
nor = datain[7] as integer
nop = datain[6] as integer
rot = datain[13] as float
nos = datain[10] as integer
xo1 = datain[11] as float
xo=-1*xo1
rad1 = datain[9] as float
rad=rad1*0.5
p1dist = datain[8] as float

-- pilecap name|mxstring|length|width|thickness|noofpiers|noofrows|xoffset|diameter|nosides|depth|Pile Names|rotate|p1|p2|p3|p4|p5......
myBox= Box lengthsegs:1 widthsegs:1 heightsegs:1 length:LL width:WW height:TT mapcoords:on pos:[0,0,0] name: ( uniqueName datain[1])

if nor==1 then
(
for i = 1 to nop do
(
j=13+i
pjdist=datain[j] as float
piers = Cylinder smooth:on heightsegs:1 capsegs:1 sides:nos height:-1*xo radius:rad mapcoords:on pos:[p1dist,pjdist,TT] name: (uniquename datain[12])
piers.parent = myBox
)
)

if nor==2 then
(
for i = 1 to nop do
(
j=13+i
pjdist=datain[j] as float
piers = Cylinder smooth:on heightsegs:1 capsegs:1 sides:nos height:xo radius:rad mapcoords:on pos:[p1dist*-1,pjdist,TT] name: (uniquename datain[12])
piers.parent = myBox
piers = Cylinder smooth:on heightsegs:1 capsegs:1 sides:nos height:xo radius:rad mapcoords:on pos:[p1dist*1,pjdist,TT] name: (uniquename datain[12])
piers.parent = myBox
)
)

spl = getNodeByName datain[2]
clearlistener ()
disableSceneRedraw() --disable viewport redraws for speed
old_pos = myBox.pos.controller --get the original position controller
myBox.pos.controller = path follow:true path:spl constantVel:true --assign a Path controller to follow

rotate myBox (angleaxis rot [0,0,1])

--myBox.pos.controller.percent = 50 --set the percentage on frame 0 to 0
--animate the values below:
enableSceneRedraw() --enable viewports
redrawViews() --redraw them

myBox.pos.controller.percent = 50
stream = fopen "C:\\MX Projects\\Caulfield to Dandenong Nine\\07_Max\\02_Macros\\test.txt" "wb"
writestring stream ((myBox.name as String) + "Created" )
fclose stream
)

(
-- RELAYERING OBECTS
layer = LayerManager.getLayerFromName"PILECAPS"
arrt = $'Pile*'
for n in (selection as array) do layer.addnode n
(layerManager.getLayer 1).on = on
)
clearselection()

close f

messagebox ((myBox.name as String) +"Created" )
)

Comments (1)

nounei24 · 2016-05-24

Hi all, Worked it out. the piers filtering of the spreadsheet was wrong it was trying to look for a number that was non existent.