ScriptSpot

Forum topic · General Scripting

Sweep modifer from textfile

By TomNChris · 2015-12-21

Description

Hi, I am a novice at MXS but I have picked up some bits and bobs to try and mash what I would like to do.
I have a series of objects that are in a spreadsheet, it produces a text file with a delimiter of "|" with the line name in the first and the name of the custom object in the fourth column I would like to read in all modifications required to the lines.
So far I have this however Max is unable to converts the custom object name to a MaxObject.

n = "C:\\test\\07_Max\\macros\\test.txt"
f = openfile n mode:"r"
count = 0
while not eof f do
(
l = readline f
data = filterstring l "|"
beamz = line name:(data[1])
beamtype = line name:(data[4])
select beamz
for index = beamz.modifiers.count to 1 by -1 do
if ((classOf beamz.modifiers[index]) == Sweep) do
deleteModifier beamz index
sw=sweep() -- create an Edit Mesh modifier
addModifier beamz sw -- add edit mesh mod
select beamz -- select object box01
beamz.modifiers[#Sweep].CustomShape = 1
beamz.modifiers[#Sweep].XOffset = 0
beamz.modifiers[#Sweep].yOffset = 0
beamz.modifiers[#Sweep].MirrorXZPlane = off
beamz.modifiers[#Sweep].shapes[1] = (data[4])
beamz.modifiers[#Sweep].PivotAlignment = 5
beamz.modifiers[#Sweep].Banking = off
)
\
I then would like to change the line name to the data[2] & data[3] & text.
If someone could give a few pointers I would grateful, thank you.

Comments (2)

.

miauu · 2015-12-21

I can't understand where is the problem(I don't have your text file), but you can select an object by its name using this:


obj = getNodeByName data[1]

RE advice

TomNChris · 2015-12-21

Thank you Miauu, that advice got it to work!
the textfile wasn't the issue
it is broken up into string | Span | Type of Structure | object for use as sweep | delimitated by "|"
the code below is the resultant.


n =  "C:\\test\\07_Max\\macros\\test.txt"
f = openfile n mode:"r"
count = 0
while not eof f do
(
	l = readline f
	data = filterstring l "|"
	beamtype =  getNodeByName data[4]
	obj = getNodeByName data[1]

	 for index = obj.modifiers.count to 1 by -1 do
if ((classOf obj.modifiers[index]) == Sweep) do
      deleteModifier obj index
sw=sweep() 
addModifier obj sw 
select obj 
	obj.modifiers[#Sweep].CustomShape = 1
obj.modifiers[#Sweep].XOffset = 0
obj.modifiers[#Sweep].yOffset = 0
	obj.modifiers[#Sweep].MirrorXZPlane = off
obj.modifiers[#Sweep].shapes[1] = beamtype.baseObject
obj.modifiers[#Sweep].PivotAlignment = 5
obj.modifiers[#Sweep].Banking = off
)