Python change for scripts?


#1

I have a few scripts I use to move all selected points to an axis.
For instance, the “snap all selected to Y” 0 looks like:

import c4d
from c4d import utils

def main():
doc.StartUndo()
doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
settings = c4d.BaseContainer() # Settings
settings[c4d.MDATA_SETVALUE_SETX] = c4d.MDATA_SETVALUE_SET_LEAVE # Dropdown for X
settings[c4d.MDATA_SETVALUE_SETY] = c4d.MDATA_SETVALUE_SET_SET # Dropdown for Y
settings[c4d.MDATA_SETVALUE_SETZ] = c4d.MDATA_SETVALUE_SET_LEAVE # Dropdown for Z
settings[c4d.MDATA_SETVALUE_VAL] = c4d.Vector(0.0, 0.0, 0.0) # X Y Z values
settings[c4d.MDATA_SETVALUE_SYSTEM] = c4d.MDATA_SETVALUE_SYSTEM_WORLD # Global system

res = utils.SendModelingCommand(command = c4d.ID_MODELING_SETVALUE_TOOL,
list = [op],
mode = c4d.MODELINGCOMMANDMODE_POINTSELECTION,
bc = settings,
doc = doc)
doc.EndUndo()
c4d.EventAdd()

if res is False:
print “Something went wrong.”
elif res is True:
print “Command successful.”
elif isinstance(res, list):
print “Here you get the newly created object(s).”

if name==‘main’:
main()

But it’s not working in R23.
I’m guessing it’s because of a change from Python 2.x to 3.x ?

Anybody familiar with python spot what’s wrong?

Thanks


#2

I think Python 3 print needs parentheses. Try looking in console for other clues.


#3

That was it thanks.
Just needed parentheses around the print statements.


#4

If you have other scripts: The xrange now is called range, and the string type is now in unicode so the original unicode class is gone.