[Closed] Need help for simple code
Hi,
I am currently learning MAXScript for a university project and am having an issue with the rollout that I have created using information from MAXScript 101 tutorials. I have created the rollout and am having trouble with the code. I am aiming to have a Tree planter like the one in his video but without the curve. I can’t seem to get it to work and was wondering if someone could take a look at my code.
numTrees = 500
utility TreeGenerator “Tree Generator” width:207 height:343
(
local surf, master
GroupBox 'grp1' "GroupBox" pos:[9,8] width:184 height:104 align:#left
pickbutton 'pickSurf' "-- none --" pos:[88,24] width:80 height:24 align:#left
pickbutton 'pickMaster' "-- none --" pos:[88,72] width:80 height:24 align:#left
label 'lb17' "Pick Surface:" pos:[16,24] width:72 height:24 align:#left
label 'lb13' "Pick Master:" pos:[16,72] width:64 height:24 align:#left
GroupBox 'grp2' "Tree Parameters" pos:[8,136] width:184 height:98 align:#left
spinner 'treeCount' "Tree Count:" pos:[16,160] width:96 height:16 range:[1,1000,100] type:#integer align:#left
spinner 'fromScale' "Scale:" pos:[16,184] width:58 height:16 type:#float align:#left
button 'create' "Create Trees" pos:[8,240] width:184 height:24 align:#left
spinner 'toScale' "" pos:[112,184] width:54 height:16 type:#float align:#left
spinner 'fromOffset' "Offset: " pos:[16,208] width:54 height:16 align:#left
spinner 'toOffset' "" pos:[112,208] width:56 height:16 align:#left
on pickSurf picked obj do
(
pickSurf.text = obj.name
surf = obj
)
on pickMaster picked obj do
(
pickMaster.text = obj.name
master = obj
)
on create pressed do
(
for i in 1 to numTrees do
(
local treePos = (intersectRay surf treeRay).pos,
treeScale = [1,1,1] * random fromScale.value toScale.value
instance master pos:treePos scale:treeScale name:"tree"
if mod i 10 == 0 then redrawViews ()
)
)
)
So this is the updated script that I have got but I am still receiving an error ‘pos is undefined’.
numTrees = 500
utility TreeGenerator “Tree Generator” width:207 height:343
(
local surf, master
GroupBox 'grp1' "GroupBox" pos:[9,8] width:184 height:104 align:#left
pickbutton 'pickSurf' "-- none --" pos:[88,24] width:80 height:24 align:#left
pickbutton 'pickMaster' "-- none --" pos:[88,72] width:80 height:24 align:#left
label 'lb17' "Pick Surface:" pos:[16,24] width:72 height:24 align:#left
label 'lb13' "Pick Master:" pos:[16,72] width:64 height:24 align:#left
GroupBox 'grp2' "Tree Parameters" pos:[8,136] width:184 height:98 align:#left
spinner 'treeCount' "Tree Count:" pos:[16,160] width:96 height:16 range:[1,1000,100] type:#integer align:#left
spinner 'fromScale' "Scale:" pos:[16,184] width:58 height:16 type:#float align:#left
button 'create' "Create Trees" pos:[8,240] width:184 height:24 align:#left
spinner 'toScale' "" pos:[112,184] width:54 height:16 type:#float align:#left
spinner 'fromOffset' "Offset: " pos:[16,208] width:54 height:16 align:#left
spinner 'toOffset' "" pos:[112,208] width:56 height:16 align:#left
on pickSurf picked obj do
(
pickSurf.text = obj.name
surf = obj
)
on pickMaster picked obj do
(
pickMaster.text = obj.name
master = obj
)
on create pressed do
(
for i in 1 to treeCount.value do
(
theNewTree.pos = [(random -200 200), (random -200 200), 1000]
local treeRay = ray theNewTree.pos [0,0,-1]
local treePos = (intersectRay surf treeRay) .pos,
treeScale = [1,1,1] * random fromScale.value toScale.value
instance master pos:treePos scale:treeScale name:"tree"
if mod i 10 == 0 then redrawViews ()
)
)
)
pos in 1st different from 2cd
1st
treePos = (intersectRay surf treeRay).pos
this ray may be undefined
2cd
theNewTree.pos = [(random -200 200), (random -200 200), 1000]
this ‘theNewTree’ is a variable ,there is no ‘pos’ property with it , delete ‘.pos’ , will done
So the issue I am having now is the error: Unable to convert: (ray [-69,-30,0] [0,0,1] to type: Point3
This is the script I have currently:
numTrees = 500
utility TreeGenerator “Tree Generator” width:207 height:343
(
local surf, master
GroupBox 'grp1' "GroupBox" pos:[9,8] width:195 height:104 align:#left
pickbutton 'pickSurf' "-- none --" pos:[80,24] width:80 height:24 align:#left
pickbutton 'pickMaster' "-- none --" pos:[80,72] width:80 height:24 align:#left
label 'lb17' "Pick Surface:" pos:[16,24] width:64 height:16 align:#left
label 'lb13' "Pick Master:" pos:[16,72] width:64 height:16 align:#left
GroupBox 'grp2' "Tree Parameters" pos:[8,136] width:194 height:59 align:#left
spinner 'treeCount' "Tree Count:" pos:[16,160] width:96 height:16 range:[1,1000,100] type:#integer align:#left
button 'create' "Create Trees" pos:[8,240] width:175 height:24 align:#left
on pickSurf picked obj do
(
pickSurf.text = obj.name
surf = obj
)
on pickMaster picked obj do
(
pickMaster.text = obj.name
master = obj
)
on create pressed do
(
for i in 1 to treeCount.value do
local theNewTree = #()
maxops.cloneNodes #(master) newNodes:&theNewTree
theNewTree[1].pos = [(random -200 200), (random -200 200), 1000]
local treeRay = ray theNewTree[1].pos [0,0,-1]
local treePos = (intersectRay surf treeRay)
instance master pos:treePos scale:treeScale name:"tree"
if mod i 10 == 0 then redrawViews ()
)
)
local treePos = (intersectRay surf treeRay)
this is ray , not a point3 , like before , use ray.pos