[Closed] a maxscript question
ok,this is Roger Hyde’s scipt,my question is,itcan’t autoload,you must run it once after max run,
why?
:bounce: :bounce:
macroScript SaveRestoreViews
category:“RHTools”
toolTip:“Save/Restore Views”
buttonText:“Save/Restore Views”
(
createDialog rlt_saveRestoreViews 240 225
)
persistent global srv_viewNames = #()
persistent global srv_viewMatrices = #()
persistent global srv_viewTypes = #()
persistent global srv_scene
global srv_version = 1.0
newFileScript = stringStream “”
openFileScript = stringStream “”
format “srv_viewNames = #()
srv_viewMatrices = #()
srv_viewTypes = #()
” to:newFileScript
format “fname = maxFilePath + maxFileName
” to:openFileScript
callBacks.addScript #systemPostNew newFileScript id:#srv
callbacks.addScript #systemPostReset newFileScript id:#srv
struct srv
(
fn copyArray arr =
(
newarr = #()
for item in arr do
(
append newarr item
)
return newarr
),
fn restoreView viewName =
(
viewNum = findItem srv_viewNames viewName
if viewNum != 0 do
(
viewport.setType srv_viewTypes[viewNum]
viewport.setTM srv_viewMatrices[viewNum]
return true
)
return false
),
fn saveView name viewTM viewType =
(
append srv_viewNames name
append srv_viewMatrices viewTM
append srv_viewTypes viewType
),
fn updateView viewName viewTM viewType =
(
viewNum = findItem srv_viewNames viewName
if viewNum != 0 do
(
viewMatrices[viewNum] = viewTM
viewTypes[viewNum] = viewType
)
),
fn deleteView viewName =
(
viewNum = findItem srv_viewNames viewName
if viewNum != 0 do
(
deleteItem srv_viewNames viewNum
deleteItem srv_viewMatrices viewNum
deleteItem srv_viewTypes viewNum
return true
)
return false
)
) –end struct srv
rollout rlt_saveRestoreViews “Save/Restore Views” width:240 height:225
(
button btn_add “Add” pos:[180,5] width:25 height:17
button btn_delete “Del” pos:[210,5] width:25 height:17
combobox cbx_savedViews “” pos:[5,25] width:230 height:14 items:(srv.copyArray srv_viewNames)
label lbl1 “Saved Views:” pos:[10,5] width:70 height:15
on btn_add pressed do
(
if (viewport.getType() == #view_persp_user) or (viewPort.getType() == #view_iso_user) then
(
cbx_text = cbx_savedViews.text
if cbx_text != "" do
(
if (findItem cbx_savedViews.items cbx_text != 0) then
(
vm = viewport.getTM()
vt = viewport.getType()
srv.updateView cbx_text vm vt
)
else
(
cbx_items = cbx_savedViews.items
append cbx_items cbx_text
cbx_savedViews.items = cbx_items
vm = viewport.getTM()
vt = viewport.getType()
srv.saveView cbx_text vm vt
cbx_savedViews.text = ""
)
)
)
else
(
messageBox "Unable to save non-user view!" title:"rhTools"
)
)
on btn_delete pressed do
(
cbx_items = cbx_savedViews.items
if cbx_items.count > 0 do
(
idx = cbx_savedViews.selection
srv.deleteView cbx_items[idx]
deleteItem cbx_items idx
cbx_savedViews.items = cbx_items
)
)
on cbx_savedViews doubleClicked sel do
(
selView = cbx_savedViews.selected
srv.restoreView selview
)
)
Been a while since I wrote this, but I think it had something to do with a scope issue I was too lazy to sort out. I’ve just gotten back from vacation, but after I’ve settled back in perhaps I’ll take another look at it:)
RH