Notifications
Clear all

[Closed] Dropdown selected state resets in scripted plugin

Hi all,

I’m creating a scripted plugin helper. I have a drop down list and a checkbox. The issue is that the selected option on the drop down list resets after deselecting the plugin node. Below is the script to create it. To recreate the issue, either run the execution in the comments, or create the node, change the drop down option, deselect and select the node again. I’ve run out of ideas, but am getting back to Maxscript after a while, so maybe I’m missing something obvious. This does not occur with the checkbox, as in I can set it’s state, and deselect the node and select it again and the previous sate is retained. Thanks for the help

“`
plugin helper MyRootNode
name:“RootNode”
category:“Nodes”
classID:#(0x6d0413c0, 0x65fc2a57)
extends:Point
version:1.0
(
parameters main rollout:assetRollout
(
assetType type:#string ui:dropdwn_assetType
exportable type:#boolean ui:chk_exportable default:true
)

function getAssetType =
(
return this.assetRollout.dropdwn_assetType.selected
)

function isExportable =
(
if (this.assetRollout.chk_exportable.checked == 1) then return true
else return false
)

function setExportable stateBool =
(
this.assetRollout.chk_exportable.state = stateBool
)

function setAssetType assetType =
(
for i in this.assetRollout.dropdwn_assetType.items do
(
if assetType == i then
(
this.assetRollout.dropdwn_assetType.selected = i
exit
)
)
)

rollout assetRollout “Root Node” width:168 height:309
(
dropdownList ‘dropdwn_assetType’ “Asset type” pos:[0,0] width:160 height:40 items:#(“Mesh”, “Rig”,“Animation”)
checkbox ‘chk_exportable’ “Exportable” checked:true pos:[0,45] width:65 height:19
)
)
– Example execution below
/*
newNode = MyRootNode()
select newNode
newNode.setAssetType “Rig”
deselect newNode
select newNode
*/

“`

2 Replies

2018+:

plugin helper MyRootNode
name:"RootNode"
category:"Nodes"
classID:#(0x6d0413c0, 0x65fc2a57)
extends:Point
version:1.0
(
    parameters main rollout:assetRollout
    (
        assetName type:#string
        assetType type:#integer ui:dropdwn_assetType default:1
        exportable type:#boolean ui:chk_exportable default:true

        on assetName preSet newVal do
            if findItem this.assetRollout.dropdwn_assetType.items newVal then newVal else assetName

        on assetName set val do
            assetType = findItem this.assetRollout.dropdwn_assetType.items val

        on assetType set val do
            assetName = this.assetRollout.dropdwn_assetType.items[amax (amin this.assetRollout.dropdwn_assetType.items.count val) 1]
    )

    rollout assetRollout "Root Node" width:168 height:309
    (
      dropdownList 'dropdwn_assetType' "Asset type" pos:[0,0] width:160 height:40 items:#("Mesh", "Rig","Animation")
      checkbox 'chk_exportable' "Exportable" checked:true pos:[0,45] width:65 height:19
    )
)

/*
MyRootNode isSelected:on
$.assetName = "Animation"
$.exportable = off
*/

Brilliant, that worked. Thanks Vojtech