如何将属性分配给函数的引用分配(不使用execute)

时间:2019-08-06 16:29:24

标签: maxscript

我希望将属性分配给MAXScript的函数。

这是我尝试过的:

fn getProp type: = (
  $.'type'
  )
getProp type:'pos'

我想将pos属性作为变量传递给函数getProp,并以与以下代码相同的方式对其进行检索:

$.pos


对于另一个获得所选对象比例的示例,代码如下所示:

fn getProp type: = (
  $.'type'
  )
getProp type:'rotation'

以下是我不想做的执行版本:

fn getProp type: = (
  execute("$."+type)
  )
getProp type:#pos
-- will return: [25.051,-115.88,0]

编辑

关于在什么情况下我想实现的完整代码,哪些有效,哪些无效。参见第55行。

try(destroydialog ::lvRolTest)catch()
rollout lvRolTest "Check Mate.."
(

  local  _lvSetItemsInvertProp, _lvSetItemsInvertPropNotWorking

  label         countLabelPrefix       "How many you say ?" across:3
  label         countLabelVal          ""
  checkButton   chkLvToggleAllButton   "Toggle All..."
  dotNetControl lv                     "ListView" width:270 height:535 pos:[10,30]

  on lvRolTest open do (
    lv.View                  = (dotNetClass "View").Details
    lv.FullRowSelect         = true
    lv.MultiSelect           = true
    lv.Checkboxes            = true
    lv.Columns.add           ("Items")

    lv.columns.item[0].width = lvRolTest.width-55

    for x=1 to 100 do (
      lv.BeginUpdate()
      local newLvItem = dotNetObject "ListViewItem" ("Item " + x as string)
      newLvItem.checked = true
      lv.EndUpdate()
      lv.items.add newLvItem
      )
    lv.Focus()
    countLabelVal.text = (lv.CheckedItems.count) as string
    )

  on chkLvToggleAllButton changed state do (
    if state do chkLvToggleAllButton.text         = "Toggle All Again..."

    -- This is working
    --     _lvSetItemsInvertProp ("lvRolTest" as string) ("lv" as string) prop:#Checked

    -- This is not
    _lvSetItemsInvertPropNotWorking lv prop:#Checked

    if not state do chkLvToggleAllButton.text     = "Toggle All..."
    countLabelVal.text = (lv.CheckedItems.count) as string
    lv.Focus()
    )

  -- This is working
  fn _lvSetItemsInvertProp rolArg lvArg prop:#Checked = (
    execute("for i = 0 to "+rolArg+"."+lvArg+".items.count-1 do (
      local item = "+rolArg+"."+lvArg+".items.item[i]
      if item."+prop+" == true then item."+prop+" = false else item."+prop+" = true
      )")
    )

  --   This is not
  fn _lvSetItemsInvertPropNotWorking ListView prop:#Checked = (
    for i = 0 to lvRolTest.lv.items.count-1 do (
      local item = getProperty (lvRolTest.lv.items.item[i]) prop
      if item == true then item = false else item = true
      )
    )

  )

createDialog lvRolTest 300 575 pos:[1850,700] style:#(#style_SysMenu, #style_ToolWindow, #style_resizing)

编辑2.按照下面的Swordslayers注释使用解决方案更新了代码。

try(destroydialog ::lvRolTest)catch()
rollout lvRolTest "Check Mate.."
(

  local  _lvSetItemsInvertProp

  label         countLabelPrefix       "How many you say ?" across:3
  label         countLabelVal          ""
  checkButton   chkLvToggleAllButton   "Toggle All..."
  dotNetControl lv                     "ListView" width:270 height:535 pos:[10,30]

  on lvRolTest open do (
    lv.View                  = (dotNetClass "View").Details
    lv.FullRowSelect         = true
    lv.MultiSelect           = true
    lv.Checkboxes            = true
    lv.Columns.add           ("Items")

    lv.columns.item[0].width = lvRolTest.width-55

    for x=1 to 100 do (
      lv.BeginUpdate()
      local newLvItem = dotNetObject "ListViewItem" ("Item " + x as string)
      newLvItem.checked = true
      lv.EndUpdate()
      lv.items.add newLvItem
      )
    lv.Focus()
    countLabelVal.text = (lv.CheckedItems.count) as string
    )

  on chkLvToggleAllButton changed state do (
    if state do chkLvToggleAllButton.text         = "Toggle All Again..."
    if not state do chkLvToggleAllButton.text     = "Toggle All..."
    _lvSetItemsInvertProp lv prop:#Checked
    _lvSetItemsInvertProp lv prop:#Selected
    countLabelVal.text = (lv.CheckedItems.count) as string
    lv.Focus()
    )

  fn _lvSetItemsInvertProp lvArg prop:#Checked = (
    for i = 0 to lv.items.count-1 do (
      local bool = getProperty (lvArg.items.item[i]) prop
      setProperty (lvArg.items.item[i]) prop (not bool)
      )
    )

  )

createDialog lvRolTest 300 575 pos:[1850,700] style:#(#style_SysMenu, #style_ToolWindow, #style_resizing)

1 个答案:

答案 0 :(得分:1)

您同时提到了几件事,映射函数(在示例代码中看不到痕迹,因此将被忽略),并使用您自己的函数获取具有可变属性名称的属性-当然您尝试使用{{ 3}}:

then