Set Persistent global variable using pymxs

Set Persistent global variable using pymxs

stevkalinowski
Contributor Contributor
1,334 Views
4 Replies
Message 1 of 5

Set Persistent global variable using pymxs

stevkalinowski
Contributor
Contributor

Hello,

 

I'm attempting to set persistent global variables in 3ds Max 2018 using pymxs.  Is this currently possible?  I have had a hard time finding any examples of this.

 

Here are some things that I have tried.  Each of these results in an "unsaveable file".  If I hit save after any of these Max crashes.

 

import pymxs

pymxsRt = pymxs.runtime
pymxsMp = getattr(pymxsRt, '%make_persistent')

global gTest

gTest = []
gTest.append('qwer')
gTest.append('asdf')
gTest.append('zxcv')

pymxsRt.persistents.append(gTest)

 

import pymxs

pymxsRt = pymxs.runtime
pymxsMp = getattr(pymxsRt, '%make_persistent')

global gTest

gTest = []
gTest.append('qwer')
gTest.append('asdf')
gTest.append('zxcv')

pymxsMp( gTest, pymxsRt.persistents )

 

import pymxs

pymxsRt = pymxs.runtime
pymxsMp = getattr(pymxsRt, '%make_persistent')

global gTest

gTest = []
gTest.append('qwer')
gTest.append('asdf')
gTest.append('zxcv')

pymxsMp( gTest )

 

 

 

I'm trying to avoid going between python and MaxScript since I have a PySide2 GUI and I have to pass data back and forth.

 

Also, are persistent global variables not advised for any reason?

0 Likes
Accepted solutions (1)
1,335 Views
4 Replies
Replies (4)
Message 2 of 5

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

first of all you have to make MXS global... not a Python global.

the only way to do it with pymxs i see:

rt = pymxs.runtime
rt.execute('global abcd')

after that use MXS struct "persistents":

rt.persistents.make('abcd')
rt.persistents.isPersistent('abcd')
rt.persistents.gather()

to set/get use "globalVars"

 

rt.globalVars.set('abcd', 12)
rt.globalVars.get('abcd')


to remove use "persistents" and "globalVars"

0 Likes
Message 3 of 5

denisT.MaxDoctor
Advisor
Advisor

maybe with MaxPlus you can get direct access to "globals" and "persistents" sdk HashTable(s).. i never tried  

0 Likes
Message 4 of 5

denisT.MaxDoctor
Advisor
Advisor

@denisT.MaxDoctor wrote:

maybe with MaxPlus you can get direct access to "globals" and "persistents" sdk HashTable(s).. i never tried  


at first glance it is impossible... i don't see any classes for that.

0 Likes
Message 5 of 5

stevkalinowski
Contributor
Contributor

Hey hey!  How you doing man!

 

Thanks a bunch, this seems to work just fine.

0 Likes