[Closed] Problem with different objects on same script
hello !
i began learning maxscript not so long time ago … and for practice what i’ve learned so far i decided to write a script that would help me in my work (architecture visuals).
my script shoud do basicaly a hedge from a module that i allready have, the script is based on for loops copying, scaleing and rotating the module along a spline. My problem is that with basic objects like a box or a cylinder it works fine (as i intended) but with my module it doesn’t, at high setings … because of an error … that i don’t know . i will post here the print screens …
Can anyone explaine me how to solve this problem please !
this is the script:
linie = $line01 – necessary change name
obiect = $hedge – necessary change name and convert to mesh
len = curvelength linie
x = 20
uStep = x / len
for u = 0.0 to 1.0 by uStep do
(
pozitie = lengthInterp linie u
tan = lengthTangent linie u
n = random 0 360
rot = eulerangles 0 0 n
copy obiect pos:pozitie name:(uniquename “modul”) wirecolor:red isSelected:on
rotate obiect rot
)
myArray = $modul* as array
deleteItem myArray 1
for o in myArray do
(
z = random 0.8 1.2
scale o [z,z,z]
)
for myObjects in myArray do
(
attach $modul01 myObjects
)
i forgot to mention that if i attach manualy the modules one by one it works fine .
ps: sorry, i forgot to dissable the smilies in the text
i modified the script to a more cleaner one, hoping to solve the error but unfortunatly the error is still on.
Can anyone help me with this please ?
linie = $line01 – change name
obiect = $myMesh – change name and use only mesh
len = curvelength linie
x = 20
uStep = x / len
myArray = for u = 0.0 to 1.0 by uStep do
(
pozitie = lengthInterp linie u
tan = lengthTangent linie u
n = random 0 360
z = random 0.5 1.5
rot = eulerangles 0 0 n
copy obiect pos:pozitie name:(uniquename “modul”) wirecolor:red isSelected:on
rotate obiect rot
scale $ [z,z,z]
if u != 0.0 do ( attach $modul01 $)
)
I just threw this together, might help.
(
local segDiv = 20
local lineObj = $line01 -- your line
local boxRef = $box01 -- your box
local boxArray =#()for i = 0.0 to 9.0 by (1.0/segDiv) do
(
local boxObj = box()
local p0 = lengthInterp lineObj i
local p1 = lengthInterp lineObj (i + 0.1)
local randomRot = [-0.1,-0.1,-0.1] [0.1,0.1,0.1]
local x = normalize (p0 - (p1 + randomRot))
local z = [0,0,1]
local y = cross z x
local x = cross y z
boxObj.transform = orthogonalize (matrix3 x y z p0)
local randomSize = 0.0 5.0
boxObj.width = randomSize + boxRef.width
boxObj.height = randomSize + boxRef.height
boxObj.length = randomSize + boxObj.length
append boxArray boxObj
gc()
)
for i = 2 to boxArray.count do
(
attach boxArray[1] boxArray[i]
gc()
)
)
I dont know how heavy attach is so i added a gc().
The trouble with attach is the Undo buffer it creates.
A better idea is to say
with undo off attach objA objB
to avoid the creation of a huge undo buffer. Even the collapse utility used to crash with large amounts of geometry in the past for the very same reason. Plus, with undo off makes it much faster, too.
thank you for your prompt responce,
… and tnx EEK for that, but it has an error in the “i” loop and i didn’t figure it out, my final result will not be with simple boxes but with those modules of hedge ( every mesh module has almost 1000 poly each) so in the end it will be a heavy geometry (that it will be easyer for me to export as VrayProxy afterwards), if i try to just create them and not attach them together it works fine, the problem appear when i join them, so for what i understood from the script you wrote is that it works only with boxes.
i tryed aslo “with undo off ” but the error apear evan in cases of simple boxes and the program turns itself of with an error .
Does the fact that i use Max version 8 matter in someway ? I’ve seen that the latest version of max handles heavy geometry much easyer than previous ones.