Pymxs Custom Attributes

Pymxs Custom Attributes

colbey82
Contributor Contributor
2,107 Views
3 Replies
Message 1 of 4

Pymxs Custom Attributes

colbey82
Contributor
Contributor

Trying to use pymxs to add custom attributes and I can't seem to find any reference to how this works.  Is it even possible?

 

The only reference to custom attributes seems to be here in the Documentation:

https://help.autodesk.com/view/3DSMAX/2020/ENU/?guid=__developer_using_pymxs_pymxs_objects_html

For example this is my maxscript code:

ca = attributes test
(
	parameters main rollout:params
	(
		fx_shader type:#string ui:shader default:"Test"
	)

	rollout params "REALTIME"
	(
		edittext shader "FX Shader" readonly:True
	)
)
print ca

CustAttributes.add $ ca

 

Is this possible to do in pymxs?  And if so how?

0 Likes
Accepted solutions (1)
2,108 Views
3 Replies
Replies (3)
Message 2 of 4

attilaszabo
Alumni
Alumni
Accepted solution

Hi @colbey82 ,

 

Unfortunately pymxs does not support defining custom attributes in Python.

But you can use the pymxs.runtime.execute() function to pass in the definition of a custom attribute, as a Maxscript string, and then use pymxs to add instances of it to objects.

Here's an example:

from pymxs import runtime as rt
selObj = rt.selection[0]

testCA='''attributes "TestCustAttrib"
(
parameters main rollout:params
(
param1 type:#float ui:spinParam1 default:10 animateable:True
)
 
rollout params "Test Parameters"
(
spinner spinParam1 "Param1" type:#float
)
)'''
attr = rt.execute(testCA)
rt.custAttributes.add(selObj.baseObject,attr)
selObj.TestCustAttrib.param1 = 21

After you execute this python code, the selected object will have a custom attribute instance named "TestCustAttrib" with one parameter called "param1" which will be visible in the rollout called "Test Parameters" displayed in the Modifier panel.

 

I hope this helps,

 

Attila Szabo
Product Owner, 3ds Max
Autodesk
0 Likes
Message 3 of 4

colbey82
Contributor
Contributor

Yeah this is how I normally do it, I was just looking to see if there was a pymxs way of doing it.  Might be useful to include this in the documentation so it's a bit easier to find the information.  It's very hard to find decent reference what does and doesn't work in pymxs and having practical examples is useful.

 

Thanks

 

Nick

0 Likes
Message 4 of 4

attilaszabo
Alumni
Alumni

Thanks for this feedback. We'll make sure this is explained in the Python (pymxs) help

Attila Szabo
Product Owner, 3ds Max
Autodesk
0 Likes