PDA

View Full Version : Unwrap Selection Change and update UI...


PiXeL_MoNKeY
09-03-2009, 08:37 PM
I am trying to write a tool to update a UI component when ever your selection changes on the object. The plan is to use this to type in desired location of the current selection. However, none of the callbacks I have tried seem to be working, but if I just call the function it works as expected. Anyone have any ideas?macroScript UnwrapTransTools
category:"Craft Tools"
tooltip:"Unwrap Transform Tools" (
on isEnabled do (
(classof (modPanel.getCurrentObject()) == Unwrap_UVW)
)
on execute do (
global getSelCen,selCenTxt,selTxt
try (destroyDialog unwrapTransDialog)catch()
fn getSelCen = (
uvMod = selection[1].unwrap_uvw
uvMod2 = uvMod.unwrap2
selCen = uvMod.getSelCenter()
selCenUV = case uvMod.getUVSpace() of (
1: [selCen[1],selCen[2],0.0]
2: [selCen[2],selCen[3],0.0]
3: [selCen[1],selCen[3],0.0]
)
return selCenUV
)
fn selTxt = (
unwrapTransDialog.selCenTxt.text = "Current Selection:"+"["+((getSelCen())[1] as string)+","+((getSelCen())[2] as string)+"]"
)
rollout unwrapTransDialog "Unwrap Xform Tools" width:220 (
label selCenTxt ""
on unwrapTransDialog open do (
selCenTxt.text = selTxt()
)
)
createDialog unwrapTransDialog
callbacks.addScript #selectionSetChanged "selTxt()" id:#unwrapSelectChange
)
)-Eric

JHN
09-03-2009, 09:06 PM
What if you make the function a global function? Now it's in the macroscript scope, maybe the callback can't reach it.

-Johan

PiXeL_MoNKeY
09-03-2009, 09:23 PM
But if that was true, just calling selTxt() from the listener while its open wouldn't work either, right? And it is declared as a global at the top of the script. It currently does work calling the function manually, just not with the callbacks.

-Eric

JHN
09-03-2009, 09:29 PM
Totally missed you already declared it as global, sorry. If nothing works maybe take a look at the in 2009 new introduced Node Event System.

Now I need some sleep,
hope it's somewhat helpful,

-Johan

PiXeL_MoNKeY
09-03-2009, 09:31 PM
Tried it and same problem. It gets declared, but for some reason its not calling my function on selection change. :/

-Eric

denisT
09-03-2009, 10:39 PM
Tried it and same problem. It gets declared, but for some reason its not calling my function on selection change. :/

-Eric

callback #selectionSetChanged calls after node selection changed (not subobject level selection!). You have to use when construct

I modifiered your code to make it work

global unwrapTransDialog
macroScript UnwrapTransTools
category:"Craft Tools"
tooltip:"Unwrap Transform Tools"
(
on isEnabled do (classof (modPanel.getCurrentObject()) == Unwrap_UVW)
on execute do
(
try (destroyDialog unwrapTransDialog)catch()
fn getSelCen = if (iskindof (modi = modPanel.getCurrentObject()) Unwrap_UVW) do
(
selCen = try(modi.getSelCenter()) catch([-1e9,-1e9]) -- uvw edit dialog has to be opened
selCenUV = case modi.getUVSpace() of
(
1: [selCen[1],selCen[2],0.0]
2: [selCen[2],selCen[3],0.0]
3: [selCen[1],selCen[3],0.0]
)
)
fn selTxt = if unwrapTransDialog != undefined and unwrapTransDialog.open and (d = getSelCen()) != undefined do
(
unwrapTransDialog.selCenTxt.text = "Current Selection:"+"["+(d[1] as string)+","+(d[2] as string)+"]"
)
rollout unwrapTransDialog "Unwrap Xform Tools" width:220
(
label selCenTxt ""
on unwrapTransDialog open do selCenTxt.text = selTxt() as string
on unwrapTransDialog close do
(
deleteAllChangeHandlers id:#unwrapSelectChange
callbacks.removeScripts id:#unwrapSelectChange
)
)

deleteAllChangeHandlers id:#unwrapSelectChange
callbacks.removeScripts id:#unwrapSelectChange
fn modiChanged =
(
deleteAllChangeHandlers id:#unwrapSelectChange
if (iskindof (modi = modPanel.getCurrentObject()) Unwrap_UVW) do
(
when select modi changes id:#unwrapSelectChange do selTxt()
)
)
global modiChanged = modiChanged
callbacks.addScript #modPanelSelChanged "modiChanged()" id:#unwrapSelectChange
modiChanged()
createDialog unwrapTransDialog
)
)

PiXeL_MoNKeY
09-03-2009, 10:46 PM
Thanks for the help denisT, now the question is why didn't it work with the Node Event System, or is it not registering as a subobject change for some reason.

-Eric

denisT
09-03-2009, 11:07 PM
Thanks for the help denisT, now the question is why didn't it work with the Node Event System, or is it not registering as a subobject change for some reason.

-Eric

#selectionSetChanged calls on node selection change... it doesn't call on sub selection changes.

PiXeL_MoNKeY
09-04-2009, 03:10 AM
I understand that #selectionsetchanged is node selection only, but with 2009 they added the new Node Event System (which JHN refered to), where #subobjectSelectionChanged is an option. But for some reason it didn't work with my test in 2010. But after rereading the info on the Node Event Callback system, my function may have been missing some required parameters (for some reason it wasn't throwing the error even though the parameters were missing). So I will give that approach another try, to see if I can get it to work. If not atleast I do have your modifications.

-Eric

CGTalk Moderation
09-04-2009, 03:10 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.