Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

More PYMXS requirement

More PYMXS requirement

Anonymous
Not applicable
4,092 Views
19 Replies
Message 1 of 20

More PYMXS requirement

Anonymous
Not applicable

So, as there are several threads already, I am making another one relative to the continually inadequate pymxs implementation. Every time I use it, or try and use it, I find that there are more things that have not, or appear not to, have made it to the docs or the actual implementation. Perhaps I am trying the wrong things when attempting to uncover the syntax required (though not documented), so perhaps others can provide some insight. The auto complete for pymxs often does not list attributes that are actually available but omitted from all functionality in the editor.

 

I am attempting to use (with pymxs, not MaxPlus or MaxScript): setAppData, getAppData etc so I can attach data to assets and retrieve it through whichever means we decide.

 

below is code I have tried, but there is probably some other undocumented method of getting info back.

 

import pymxs
rt = pymxs.runtime

rt.SetAppData rt.selection[0] 1 "Nonsense" # (selected object is a sphere, for testing)

rt.SetAppData( rt.selection[0] 1 "Nonsense")

pymxs.SetAppData rt.selection[0] 1 "Nonsense"

pymxs.SetAppData( rt.selection[0], 1, "Nonsense")

derp = rt.selection[0].getmxsprop("getAppData")

All of the above fail for syntax reasons or asset not having the attribute and as mentioned in other threads, I do not have time to go through this convoluted guess and hope scenario when coding. The paradigm should have been made and released complete, not two versions ago and STILL not working properly.

Its all well and good being told by Autodesk staff that theres a raodmap we are not allowed to see, but this is wearing thin as another release is out with below par python and documentation and no sight of any improvement.

0 Likes
Accepted solutions (3)
4,093 Views
19 Replies
Replies (19)
Message 2 of 20

Anonymous
Not applicable
Accepted solution

Multiple missing parenthesis and commas.
This is not MaxScript.

 

The following will not work

rt.SetAppData( rt.selection[0] 1 "Nonsense")

This will

rt.SetAppData (rt.selection[0], 1, "Nonsense")

 

 

Message 3 of 20

Anonymous
Not applicable

Thanks Alexcgt, the one permutation I didnt try, but this is the issue with pymxs. You have to keep trying different syntax in the hope that its right. There needs to be a complete API documentation for pymxs so that time is not wasted.  It just becomes frustrating. Did you just try what I hadn`t or were you able to find some doc info or autocomplete for it?

It just feels like Autodesk are waiting for a list of commands to be gained this way instead of actually providing documentation when the yearly release is done. 

 

Thanks again

0 Likes
Message 4 of 20

Anonymous
Not applicable

No issues here.
You do realize that this is the Python language syntax?
MaxScript is Autodesk 3dsMax specific but Python has nothing to do with Autodesk.

0 Likes
Message 5 of 20

Anonymous
Not applicable

Yes, I have been using Maxscript and python in max, maya and externally for many years, as well as Python for no 3d use, but pymxs is a unfinished hybrid, created for use in Max, that sits somewhere between an embedded version and something else. There`s no real docs for it and you pretty much have to guess what the syntax is as you saw from the different permutations of the code. Its a relentless ballache to keep having to message the devs so a correct syntax can be found, and often, its the case that something has not been done yet (animation controllers for instance, which I have discussed in other threads). Generally though, I am able to get the syntax as I used BLUR Python prior to this pymxs being released, which required some trial and error also. In this instance, couldnt see the wood for the trees. MaxPlus is bloated and cumbersome, it takes 12 lines of code to achieve what I can do in maxscript with three lines. The implementations since 2014 have been pretty much awful and that, backed uo with the non existent help makes using python in max a real chore. It needs vast improvement

0 Likes
Message 6 of 20

Anonymous
Not applicable

MaxPlus indeed does suck but if you are familiar with MaxScript and Python then the use of pymxs is quite straightforward.
Only very few MaxScript elements are not translated.

 

The use of pymxs is sufficiently documented here (3dsMax 2018).
Can't see a lot of space for guesswork.

0 Likes
Message 7 of 20

Anonymous
Not applicable

Well, some of those doc entries have come about through me and others reporting its poor amount to the devs and putting up threads similar to the one I did. Theres no real in depth coverage of many topics and if you are new to max and max python, it should not be that you have to get a grounding in maxscript and python and then guess most of what should be properly documented. The devs tried using that reasoning, but its a false economy and detracts from the fact that the docs are not great. Two implementations, neither having a full set of libraries and functionality. Even says on that doc page that you have to use MaxPlus in conjunction with pymxs. so what then, go and learn whats available with Maxplus and make a hybrid code set? Thats not how an api/coding paradigm should be used or made available for use. Python in Maya has been solid since 2011, I just do not see why Autodesk could not have gone down a similar route instead of different implementations that have always been flakey. The QtWidgets library is not the same as PySide2 externally, so we have to update the dict so we can use both. Its not in line with whats used as standard by other apps.

0 Likes
Message 8 of 20

Anonymous
Not applicable

I see how this can be a problem for beginners who don't want to learn a language which cannot be used outside 3dsMax -- they are basically forced to learn MaxScript to use Python pymxs.
They are also forced to learn C++ SDK to use MaxPlus.


But for a person with an intermediate knowledge level of MaxScript and Python, using pymxs should not cause any difficulties.

0 Likes
Message 9 of 20

Anonymous
Not applicable

Ok, so rather than start ANOTHER pymxs thread, cataloging the shortcomings and abject omissions from the 2nd poor implementation of Python, now theres not even a command for what I want to do. This is becoming more farcical by the month. It really shows a lack of due dilligence and attention when issues like this KEEP coming up and Autodesk do little to nothing except to say "get involved with the Beta" which is a cop out and has almost no impact until the next release that needs a service pack on release. How are artists supposed to use the bright shiny new unfinished features if they are.. well, unnfinished?

 

Im just trying to acccess selection sets and find that there is not even a command to use that will allow me to do what I want. I am sure there may be some conveluted and spurious workround, but I dont have time to play Cluedo with the code, I just want to be able to work, which is virtually impossible with pymxs at times. I do not want to use MaxPlus as I should not be forced to use it when the people at Autodesk who are responsible for pthon should get it done right and not a half finished, undocumented wrapper. So while it seems, that after playing the "Guess the bloody syntax" game AGAIN, it turns out that the syntax I did eventually get right (I think?) Has no command to back it up. Ridiculous. It just never seems to improve. We have had Pymxs for a couple versions now and NOTHING improves at a pace or rate that is justifiable and just leaves artists frustrated. Even Blender has better python intergration than MAX, which shows that just because a company has money, does not mean its products are better.

 

for idx in range(1, the_sets+1):
set_nm = rt.getNamedSelSetName(idx)
print set_nm
num_set_items = rt.getNamedSelSetItemCount(idx)
print num_set_items
if num_set_items == 0:
#~ rt.deleteItem(rt.selectionSets set_nm) #SyntaxError: invalid syntax 
#~ rt.deleteItem(rt.selectionSets(rt.name = set_nm)) #SyntaxError: invalid syntax
#~ rt.deleteItem rt.selectionSets set_nm #SyntaxError: invalid syntax
#~ rt.deleteItem(rt.selectionSets(set_nm) #SyntaxError: invalid syntax
rt.deleteItem(rt.selectionSets[set_nm]) # Runtime error: deleteItem not yet implemented for NamedSelectionSet

0 Likes
Message 10 of 20

Anonymous
Not applicable

Dude, seriously, your complete disregard to the Python syntax puzzles me 🙂
There's zero guesswork here.
Your sample contains syntax error in every commented line and I can point out these errors without running the code in the interpreter.
The last line doesn't work because using deleteItem apparently cannot be used on a selection set item.

 

I'll be the last guy to defend Autodesk but in this case, it's not Autodesk's or Python's fault.
It's your fault.
I suggest you get some Python training.

0 Likes
Message 11 of 20

Anonymous
Not applicable

You are right, every line DOES contain an error as those are the trials I have attempted in trying to get the right pymxs command syntax based on the Maxscript version, which is also why the #syntax error appears at the end of each line that has not worked, so that it can be seen what I have tried. I though that might be obvious.

 

The last line in the last post is the one that I believe is applicable, but the python module does not seem to support the use of remove item as the maxscript one does

From the docs (Line 4 is the one that I am looking to emulate with pymxs):

selectionSets["new set"] = selection --snap the current selection
selectionSets["old spheres"] = $sphere* --all the current objects named "sphere*"
selectionSets[#foo] = #(obj1, obj2, obj3)
deleteItem selectionSets"old set" --delete the set named "old set"
nss = selectionSets["another set"] --get the selection set by name
deleteItem selectionSets nss --possible syntax since 3ds Max 9

so, by way of what should be a simple wrap for the code, does not produce the same outcome and the code produces the non implementation error code.

Even if I wrap it in a function, accessing it via an index, it still shows the error, which points to it not being part of the pymxs module.

def del_sel_sets(setName = None):
	sets_cnt = rt.selectionsets.count
	for i in range(sets_cnt):
		nm = rt.selectionsets[i].name
		if nm == setName:
			rt.deleteItem(rt.selectionsets[i])
	
del_sel_sets("Wheels")

RuntimeError: MAXScript exception raised.
-- Runtime error: deleteItem not yet implemented for NamedSelectionSet

The fact it did not error like the others (syntax error from incorrect code) AND provides feedback that the action has not been implemented (which I take to mean that it is not written yet) should denote that it cannot be used as it doesn`t exist, meaning I cant use pymxs for what I want to do.

 

Here is a version that looks for the name supplied, so it does produce some relative info

def del_sel_sets(setName = None):
	sets_cnt = rt.selectionsets.count
	for i in range(sets_cnt):
		nm = rt.selectionsets[i].name
		if nm == setName:
			#~ rt.deleteItem(rt.selectionsets[i])
			print "Found"
		else:
			print "I dont care about it: {0}".format(nm)

 

I have not looked at MaxPlus as its a bloated bootstrapped wrapper and cumbersome to use (personal choice) but even MaxPlus has areas and omissions that make its use problematic. 

 

Perhaps try it yourself, see if you can get it to work. I would be interested to see what your approach to it is as it could well be something I just have not considered, woods for the trees and all that.

0 Likes
Message 12 of 20

Anonymous
Not applicable
Accepted solution
import pymxs
rt = pymxs.runtime
rt.deleteItem(rt.selectionsets,1)
0 Likes
Message 13 of 20

Anonymous
Not applicable

Thanks very much for the reply. I thought I had tried that version, but looking back, I overlooked it. 

I was able to finish the code I wanted to write, so in light of the informed response, I have added them below, should anyone want to use them. To avoid having to add to the index, I just gathered what I wanted into lists and then performed the operation on those. I am sure someone will be able to reformat it to be more concise or neater, but they do the job as they stand.

 

import os
import sys
import PySide2
import pymxs
rt = pymxs.runtime

def del_sel_set_by_name(setName = None):
	rt.clearListener()
	sets = []
	for idx in range(0, rt.selectionsets.count):
		nm = rt.selectionsets[idx].name
		sets.append(nm)
	for index in range(len(sets)):
		if sets[index] == setName:
			rt.deleteItem(rt.selectionSets, (index+1))

def del_empty_sel_sets():
	rt.clearListener()
	the_sets= []
	for idx in range(rt.selectionsets.count):
		nm = rt.selectionsets[idx].name
		items_cnt = rt.getNamedSelSetItemCount(idx+1)
		if items_cnt == 0:
			the_sets.append(nm)
	for idxx in range(len(the_sets)):
		rt.deleteItem(rt.selectionSets, (the_sets[idxx]))
		
del_sel_sets('balls')
del_empty_sel_sets()

Please test thoroughly before any use on important files.

 

Constructive feedback welcome 😉

 

Message 14 of 20

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

what is the reason for all this? is this a practice in Python?

OK.. 

import pymxs
rt = pymxs.runtime

 

technically to delete a selset by name:

def delete_selset_by_name(name):
    rt.deleteItem(rt.selectionsets, name)

if you want to check selset existence before and return a result of deletion:

def does_selset_exist(name):
    return (rt.selectionsets[name] is not None)
def delete_selset_by_name(name):
    return (rt.deleteItem(rt.selectionsets, name) if does_selset_exist(name) else False)

if you want delete an empty selset (which does not make sense in recent max versions because the system does it automatically):

def delete_empty_selsets():
	for ss in list(rt.selectionSets): 
		if len(ss) == 0: rt.deleteItem(rt.selectionsets, ss)

 

 

I just want to notice:

if you want to use pymxs you have to know MaxScript first. 

if you want to use Python in MAX you have to know Python.

 

 

Message 15 of 20

Anonymous
Not applicable

Hi DenisT, thanks very much for the reply. The studio I work at are keen that we use one of the python implementations in Max, so as we move more to that structure, we are updating to pymxs. What is frustrating at times is the lack of clarity and documentation that means there is trial and error, but this is lessening with each case use and with tool redevelopment. I understand that the syntax is relatively simple to ascertain if you look at the Maxscript, it was just one of those cases where I had been working long hours and was a bit drained from two weeks of it, so could not grasp the syntax which was so obvious that I was kicking myself when the solution was provided.

 

I still find some access to some Maxscript functionality via pymxs to be problematic, but I am not completely blaming Autodesk, I just feel that a better set of docs would help and from discussions with them, it seems they are going to be more proactive with that documentation for future versions.

 

The code I provided was more a descriptive entry point for those adapting to its use, as there is not a lot of documentation for it as stated, so I did not go down the route of list comprehensions or deeper pythonic use and instead tried to provide something that may help with the understanding of it. 

 

What you have done is great though and will also really help those (and myself) with a want to learn more. Both do what is required, its just yours is more concise and much better as production code.

 

I admit, I was unaware that newer versions deleted empty sets, is that done on file close? Will have to look into it. Asking as I have several files (Max 2019) that have empty sets and I have not seen them deleted when reopening files (if its the case that they are deleted on close). I want empty sets deleted as part of the bigger script I am writing as artists have been known to delete nodes in an open scene, but not the sets, so I am doing that before any data goes out to the database I am using.

 

I do know Maxscript and I do know Python. Perhaps not as well as some replying, but I`ve not had any rejection of tools and what I have written over the years has served people well and done what is required.

 

Many thanks for the updated code and the feedback, it is much appreciated.

0 Likes
Message 16 of 20

Anonymous
Not applicable

I knew that sets are deleted if you delete all the nodes in that set in an open file, but empty sets created and not populated do not. This is what I meant by artists deleting nodes. They preempt the need so create empty sets they think they will need, but often forget they created them.

0 Likes
Message 17 of 20

denisT.MaxDoctor
Advisor
Advisor

you are right. i forgot about this possibility.

 

0 Likes
Message 18 of 20

denisT.MaxDoctor
Advisor
Advisor

I do know Maxscript and I do know Python. Perhaps not as well as some replying, but I`ve not had any rejection of tools and what I have written over the years has served people well and done what is required.

 

In this case, it should be easy to go with pymxs.

 

pymxs is a wrapper for MaxScript. It has the same set of methods, classes, and variables. The advantage of using it is the power of Python. But ... it's slower than the MXS.

 

therefore, if you want to write something serious, you need to go to the 3DS MAX Python API. The performance will be comparable to c ++

Message 19 of 20

Anonymous
Not applicable

Cheers DenisT.

On a side note, are you conversant with C++? Do you develop with it at all? 

 

Ive played around with the SDK before, hacked a couple of plugins to see what was going on, but would like to develop that a bit more as we use it here with UE4 and want to use it for some areas, more out of interest than need.

 

Thanks again.

0 Likes
Message 20 of 20

denisT.MaxDoctor
Advisor
Advisor

On a side note, are you conversant with C++? Do you develop with it at all? 

 

my development is

3DS MAX:

        c++ 50%, MaxScript 40%, C# 10%

Maya:

        Python 85%, c++ 10%, MEL 5%