如何将 属性 分配给函数的引用赋值(不使用执行)

How do I assign a property to a reference assignment for a function (without using execute)

我希望为 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)

您一次提到了几件事,映射函数(我在示例代码中看不到它的踪迹,因此将忽略)和使用您自己的函数获取给定变量 属性 名称的属性 -您肯定尝试过使用 getProperty:

getProperty $ type