I am trying to create a gui for this script but every time I hit 'create' button it gives me error
"Unable to convert: undefined to type: Float"at
front_shape.pos=[0,canopy_width,0] on line 20.
The script is working fine without the roll-out so I guess it has something to do with scope of the variable. I don't know much about maxscript, any help will be apreciated.Thankyou.
theGroup= #()
try(closerolloutfloater MainFloater)catch()
fn posts_pads gap pos post_count=
( post_pad=ChamferCyl radius:90 height:1200 Fillet:20 Fillet_Segments:10 sides:18
addModifier post_pad (materialModifier materialID:2 )
append theGroup post_pad
post_pad.pos=[0,pos,0]
for i=1 to post_count-1 do
(
post_pad_instance= instance post_pad
append theGroup post_pad_instance
post_pad_instance.pos=[i*gap,pos,0]
)
)
fn front_posts=
(
front_shape=Rectangle length:80 width:80
append theGroup front_shape
front_shape.pos=[0,canopy_width,0]
if canopy_width<=4000 then(
post_gap=3500.0
)
else(
post_gap=3000.0
)
front_post_count=ceil(canopy_length/post_gap)+1
front_post_gap= ((canopy_length/1000.0)/(front_post_count-1))*1000
for i=1 to front_post_count-1 do
(
post_instance=instance front_shape
append theGroup post_instance
post_instance.pos=[i*front_post_gap,canopy_width,0]
)
post=select front_shape
ex= Extrude()
my_post=$
addmodifier my_post ex
my_post.modifiers[#Extrude].amount = (front_height+40)
addModifier front_shape (materialModifier materialID:1 )
posts_pads front_post_gap canopy_width front_post_count
)
Rollout Menu "Sample Canopy" width:200 height:64
(
Spinner len "Canopy Length" range:[2000, 20000, 2000]
Spinner width "Canopy Width" range:[1500, 6000,1500 ]
Spinner height "Front Height" range:[1800, 4000, 1800]
Spinner b_height "Back Height" range:[2000, 6000, 2000]
button create "Create" pos:[55,120] width:80 height:20
on create pressed do
(
canopy_length=len.value
canopy_width=width.value
front_height=height.value
back_height=b_height.value
max create mode
with redraw off
(
front_posts()
$.name= uniquename "Sample canopy"
obj = getCurrentSelection()
tempLib = loadTempMaterialLibrary "H:\script\sample.mat"
mat= tempLib[1]
obj.material = mat
)
closerolloutfloater MainFloater
actionMan.executeAction 0 "310"
)
)
MainFloater= NewRolloutFloater "" 200 200
addRollout Menu MainFloater
Comments (2)
Comment policy
yes, scope issue it is
hey,
you are declaring global variables and functions at the top of your script.
this could collide with other scripts and you shouldn't do this.
Read this:
https://davewortley.wordpress.com/2012/08/02/lesson-7-scopes-why-has-my-…
(And in general, this dudes blog helps really to understand max script better!)
Move your variables and functions inside the Rollout.
Then you can access them properly from your buttons and functions.
The order of declaration is also important. Go from top to bottom and check which function needs which variable and so on.
Thanks a lot :)
Hey It worked! Was stuck here for days. Thanks a lot,Cheers!