Hi I am still relatively new to MAxscript. I have a script that splices tube bits then
puts them on splines. Whilst the splines and the tube elements work separately, when I run the full script it falls at the path modifier section.
I am sure there is a more efficient manner to create the various bits and pieces but I have struggled over the past few days to make it shorter.
The text file script is basically this information
TUN_MCD0-CRT_SITEA_SEC_1-#001|TUN_A_LIN_1-#001|6.2|6.5|471.2|246.366|514.576|43.029|472.4|247.419|514|43.021|1.2|40|-5.332|2.70|0|0|0
TUN_MCD0-CRT_SITEA_SEC_1-#002|TUN_A_LIN_1-#002|6.2|6.5|472.4|247.419|514|43.021|473.6|248.471|513.423|43.013|1.2|40|-5.332|2.70|0|0|0
TUN_MCD0-CRT_SITEA_SEC_1-#003|TUN_A_LIN_1-#003|6.2|6.5|473.6|248.471|513.423|43.013|474.8|249.524|512.846|43.006|1.2|40|-5.332|2.70|0|0|0
Could someone please help me with a few pointers on the path modifier element?
Thanks. The code below
Fn tunelem rad1 rad2 hgt tunname Tun_CTR =
(
arrTMP =#()
if $tunname* != undefined then delete $tunname*
mygroup = tunname
n=60 as integer AB=51.429 as float BC=51.429 as float CD=51.429 as float HA= 51.429 as float
DE=51.429 as float EF=44.554 as float FG=13.749 as float GH = 44.554 as float
Tu_AB = tunname + "Sec_AB" as string
Tu_BC = tunname + "Sec_BC" as string
Tu_CD = tunname + "Sec_CD" as string Tu_DE = tunname + "Sec_DE" as string Tu_EF = tunname + "Sec_EF" as string Tu_FG = tunname + "Sec_FG" as string Tu_GH = tunname + "Sec_GH" as string
sidHA = (HA/360)*n as integer Tu_HA = tunname + "Sec_HA" as string sidGH = (GH/360)*(n+3) as integer
sidAB = (AB/360)*n as integer sidBC = (BC/360)*n as integer sidCD = (CD/360)*n as integer sidDE = (DE/360)*n as integer sidEF = (EF/360)*n as integer sidFG = 8
oCyl1=Tube smooth:on sides:sidAB capsegs:1 heightsegs:1 radius1:rad1 radius2:rad2 height:hgt mapcoords:on realWorldMapSize:on pos:[0,0,0] slice:on sliceFrom:-90 sliceTo:(-90-AB) name: Tu_AB
append arrTMP (Tu_AB)
oCyl2=Tube smooth:on sides:sidBC capsegs:1 heightsegs:1 radius1:rad1 radius2:rad2 height:hgt mapcoords:on realWorldMapSize:on pos:[0,0,0] slice:on sliceFrom:(-90-AB) sliceTo:(-90-AB-BC) name: Tu_BC
append arrTMP (Tu_BC)
oCyl3=Tube smooth:on sides:sidCD capsegs:1 heightsegs:1 radius1:rad1 radius2:rad2 height:hgt mapcoords:on realWorldMapSize:on pos:[0,0,0] slice:on sliceFrom:(-90-AB-BC) sliceTo:(-90-AB-BC-CD) name: Tu_CD
append arrTMP (Tu_CD)
oCyl4=Tube smooth:on sides:sidDE capsegs:1 heightsegs:1 radius1:rad1 radius2:rad2 height:hgt mapcoords:on realWorldMapSize:on pos:[0,0,0] slice:on sliceFrom:(-90-AB-BC-CD) sliceTo:(-90-AB-BC-CD-DE) name: Tu_DE
append arrTMP (Tu_DE)
oCyl5=Tube smooth:on sides:sidEF capsegs:1 heightsegs:1 radius1:rad1 radius2:rad2 height:hgt mapcoords:on realWorldMapSize:on pos:[0,0,0] slice:on sliceFrom:(-90-AB-BC-CD-DE) sliceTo:(-90-AB-BC-CD-DE-EF-6) name: Tu_EF
append arrTMP (Tu_EF)
-- Big bit to be tapered next key part
dg = 90 - (HA+GH+FG)
s = sliceModifier Slice_Type:2
x5= (rad1+ (rad2-rad1)/2)*sin(dg)
y5 = (rad1+ (rad2-rad1)/2)*cos(dg)
z5 = hgt/2
Wpos = [x5,y5,z5]
tm=(matrix3 [1,0,0] [0,1,0] [0,0,1] [x5,y5,z5])
yrots = (10 - (GH+HA) )+ FG
print yrots
Wrot = (eulerangles 96 -71 90) as quat
oCylob = oCyl5
addModifier oCyl5 s
objTM = oCyl5.objectTransform
modTM = getModContextTM oCylob s
s.Slice_Plane.rotation = Wrot * modTM - (inverse (objTM as quat))
s.Slice_Plane.pos = [x5,y5,z5]* (inverse objTM)
convertTo OCylob Editable_Poly
oCyl6=Tube smooth:on sides:sidFG capsegs:1 heightsegs:1 radius1:rad1 radius2:rad2 height:hgt mapcoords:on realWorldMapSize:on pos:[0,0,0] slice:on sliceFrom:(12-90-AB-BC-CD-DE-EF) sliceTo:(-90-AB-BC-CD-DE-EF-FG-6) name: Tu_FG
append arrTMP (Tu_FG)
dg = 90 - (HA+GH)
s = sliceModifier Slice_Type:2
x5= (rad1+ (rad2-rad1)/2)*sin(dg)
y5 = (rad1+ (rad2-rad1)/2)*cos(dg)
z5 = hgt/2
Wpos = [x5,y5,z5]
tm=(matrix3 [1,0,0] [0,1,0] [0,0,1] [x5,y5,z5])
yrots = (10 - (GH+HA) )+ FG
print yrots
Wrot = (eulerangles 84 -84 90) as quat
oCylobz = oCyl6
addModifier oCyl6 s
objTM = oCyl6.objectTransform
modTM = getModContextTM oCylobz s
s.Slice_Plane.rotation = Wrot * modTM - (inverse (objTM as quat))
s.Slice_Plane.pos = [x5,y5,z5]* (inverse objTM)
--convertTo OCylobz Editable_Poly
dg = 90 - (HA+GH+FG)
s = sliceModifier Slice_Type:3
x5= (rad1+ (rad2-rad1)/2)*sin(dg)
y5 = (rad1+ (rad2-rad1)/2)*cos(dg)
z5 = hgt/2
Wpos = [x5,y5,z5]
tm=(matrix3 [1,0,0] [0,1,0] [0,0,1] [x5,y5,z5])
Wrot = (eulerangles 96 -71 90) as quat
oCylobz6 = oCylobz
addModifier oCylobz s
objTM = oCylobz.objectTransform
modTM = getModContextTM oCylobz6 s
s.Slice_Plane.rotation = Wrot * modTM - (inverse (objTM as quat))
s.Slice_Plane.pos = [x5,y5,z5]* (inverse objTM)
--convertTo OCylobz6 Editable_Poly
oCyl7=Tube smooth:on sides:10 capsegs:1 heightsegs:1 radius1:rad1 radius2:rad2 height:hgt mapcoords:on realWorldMapSize:on pos:[0,0,0] slice:on sliceFrom:(-90-AB-BC-CD-DE-EF-FG +12) sliceTo:(-90-AB-BC-CD-DE-EF-FG-GH) name: Tu_GH
append arrTMP (Tu_GH)
-- Big bit to be tapered next key part
dg = 90 - (HA+GH)
s = sliceModifier Slice_Type:3
x5= (rad1+ (rad2-rad1)/2)*sin(dg)
y5 = (rad1+ (rad2-rad1)/2)*cos(dg)
z5 = hgt/2
Wpos = [x5,y5,z5]
tm=(matrix3 [1,0,0] [0,1,0] [0,0,1] [x5,y5,z5])
Wrot = (eulerangles 84 -84 90) as quat
oCylob7 = oCyl7
addModifier oCyl7 s
objTM = oCyl7.objectTransform
modTM = getModContextTM oCylob7 s
s.Slice_Plane.rotation = Wrot * modTM - (inverse (objTM as quat))
s.Slice_Plane.pos = [x5,y5,z5]* (inverse objTM)
--convertTo OCylob7 Editable_Poly
oCyl8=Tube smooth:on sides:sidHA capsegs:1 heightsegs:1 radius1:rad1 radius2:rad2 height:hgt mapcoords:on realWorldMapSize:on pos:[0,0,0] slice:on sliceFrom:(-90-AB-BC-CD-DE-EF-FG-GH) sliceTo:(-90-AB-BC-CD-DE-EF-FG-GH-HA) name: Tu_HA
append arrTMP (Tu_HA)
--select arrTMP
-- #### Falls here ####
for i = 1 to arrTMP.count do
(
pdef = SpacePathDeform()
p = getNodeByName Tun_CTR
oCylg = arrTMP[i].name
addModifier oCylg pdef
oCylg.path = p
oCylg.modifiers[#Path_Deform_Binding].Percent_along_path = 0.0 --default: 0.0
oCylg.modifiers[#Path_Deform_Binding].rotation = 0.0 --default: rotc
oCylg.modifiers[#Path_Deform_Binding].axis = 2 -- default: 2
oCylg.modifiers[#Path_Deform_Binding].Flip_deformation_axis = 1
oCylg.transform = p.transform --MOVE TO PATH!
--Ocylparent= arrTMP[1]
--if par != 0 then (Ocylparent.parent = par)
)
)
-- open data file of tunnel section
desproj = sysInfo.currentdir -- Fix this
n = getOpenFileName caption:"Open Tunnel Elements File:" filename: desproj
f = openfile n mode:"r"
count = 0
if $'*_LIN_*' != undefined then delete $'*_LIN_*'
while not eof f do
(
l = readline f
data = filterstring l "|"
--/////////////////////////////////////////////////
--TUN_SEC_A-#0000|TUN_LIN_A-#0000|1451.699|470.29|-8.361|1454.385|470.26|-8.523|10|11|3|0|11301
-- variables
global tunname = data[1] as string
global Tun_CTR = data[2] as string
fie = data[6] as float
fin = data[7] as float
fiz = data[8] as float
ene = data[10] as float
enn = data[11] as float
enz = data[12] as float
global rad1 = data[3] as float
global rad2 = data[4] as float
global hgt = data[13] as float
--par = getNodeByName data[14]
--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
-- Create Tunnel CTR String
myCTRTun= splineShape name: ( uniqueName Tun_CTR)
addnewspline myCTRTun
(
addknot myCTRTun 1 #corner #line (point3 fie fin fiz)
addknot myCTRTun 1 #corner #line (point3 ene enn enz)
)
updateshape myCTRTun
z = tunelem rad1 rad2 hgt tunname Tun_CTR
clearselection ()
)
close f