“首次展示中的Maxscript脚本”会显示错误

时间:2017-06-10 14:19:21

标签: 3dsmax maxscript

我正在尝试为这个剧本创建一个gui,但每次我点击“创建”#39;按钮它在第20行的"Unable to convert: undefined to type: Float"处给出了错误front_shape.pos=[0,canopy_width,0]

脚本工作正常,没有推出,所以我猜它与变量的范围有关。我对maxscript了解不多,任何帮助都会被贬低.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

1 个答案:

答案 0 :(得分:0)

那是因为你在front_posts中引用了一些不属于函数范围的变量。

将所需的变量传递给函数front_posts,并相应地调用它。


   (...)

    fn front_posts canopy_length canopy_width front_height = ...
    Rollout Menu "Sample Canopy" width:200 height:64
    (
        Spinner spn_cnpy_len "Canopy Length" range:[2000, 20000, 2000]
        Spinner spn_cnpy_wid "Canopy Width" range:[1500, 6000,1500 ]
        Spinner spn_front_height "Front Height" range:[1800, 4000, 1800]
        Spinner spn_back_height "Back Height" range:[2000, 6000, 2000]

        button create "Create" pos:[55,120] width:80 height:20

        on create pressed do
        (   

            max create mode
            with redraw off
            (   
                front_posts (spn_cnpy_len.value) (spn_cnpy_wid.value) (spn_front_height.value) (spn_back_height.value)
                (...)
            )
            closerolloutfloater MainFloater
            actionMan.executeAction 0 "310" 
        )
    )