【问题标题】:3ds maxscript group objects according to name and name + suffix3ds maxscript根据名称和名称+后缀对对象进行分组
【发布时间】:2016-01-30 06:06:13
【问题描述】:
macroScript Grouper category: "MaxScript==Shit"
(
on isEnabled return
 selection.count > 0 

on execute do
    (
        createDialog (
                            rollout mf_main "LOD Grouper"
                            (


                                button savebtn "Group Proper LODs"
                                on savebtn pressed do
                                (


                                    max_count = 2   
                                    lodlist = #()




                                        for index in 1 to $.count do
                                        (


                                            if($[1].name == $[index].name + "_lod1")
                                            then(append lodlist $[1])
                                            else()

                                            if($[1].name == $[index].name + "_lod1")
                                            then(append lodlist $[index])
                                            else(reset)


                                            print lodlist

                                        )




                                        lodgroup = group lodlist 
                                        select lodgroup


                                )


                            )
                         )
    )




)

这是我的脚本,它通过检查选择中的名称并比较它们以查看基于前缀和后缀的匹配项,但它只是 对我的选择中的一个对象执行此操作,而不是遍历我的选择数组

我试图让脚本做什么的例子

objects name box01, box01_lod1 / box02, box02_lod1 / box03 , box03_lod1

               group-1              group-2           group-3

非常感谢任何帮助

提前致谢

【问题讨论】:

    标签: 3dsmax maxscript


    【解决方案1】:

    在您的示例中,相同的确切测试连续执行两次:

    if($[1].name == $[index].name + "_lod1")
    then(append lodlist $[1])
    else()
    
    if($[1].name == $[index].name + "_lod1")
    then(append lodlist $[index])
    else(reset)
    

    我怀疑这是一个错字,你想先测试一个前缀然后一个后缀...

    上面的代码与选择数组的第一项进行比较。不知道你在选择什么,很难知道这是否确实是正确的方法。

    我的方法是使用一个名称数组进行测试,以便对您选择的节点进行分组。每次选定节点在名称数组中不“匹配”时,您将其作为唯一数组添加到 lod_groups。如果匹配,那么它只会被附加到现有的 lod_groups 数组之一。

    请注意,这假设您在场景中始终有一个名为“Box001”的节点。例如,如果场景中没有“Box001”节点,则“Lod1_Box001”和“Box001_Lo​​d2”将不会被分组。

    local lod_groups = #() -- 2d array
    local _names = #() -- list of names to test against
    local selected_nodes = getCurrentSelection() -- get selected nodes
    for i = 1 to selected_nodes.count do
    (
        local found = False
        local index = 0
        local node_name = selected_nodes[i].name
        -- test node_name against _names
        for j = 1 to _names.count do
        (
            local n = node_name
            local pattern = "*" + _names[j] + "*"
            -- if the name in the list is greater swap the pattern test, this will cover suffix and prefix
            if _names[j].count > node_name.count then
            (
                n = _names[j]
                pattern = "*" + node_name + "*"
            )
            -- if it matches the current name, then record the j-index
            if (matchpattern n pattern:(pattern)) then
            (
                found = True
                index = j
            )
        )
        -- append to lod_groups based on results
        if found then
        (
            append lod_groups[index] selected_nodes[i]
        )
        else
        (
            -- add this name to the _names list, it most likely is unique
            append _names selected_nodes[i].name
            append lod_groups #(selected_nodes[i])
        )
    )
    -- do your grouping here
    for lod_group in lod_groups do
    (
        group lod_group
    )
    

    【讨论】:

      猜你喜欢
      • 2017-10-31
      • 2020-12-15
      • 1970-01-01
      • 2020-12-28
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-23
      相关资源
      最近更新 更多