On 26/04/2013 at 09:28, xxxxxxxx wrote:
First the solution to your request.
Here is some code that will change the Min attribute on a Real type UD entry:
import c4d
def main() :
obj = doc.GetFirstObject() #The object hosting the UD
ud = obj.GetUserDataContainer() #The master UD container
for i, bc in ud:
level = i[1].id #Get the ID# for each UD entry
if level == 1: #If we find the first UD entry
bc[5]= 0.2 #Set the Min value to 20% in memory only!!!
obj.SetUserDataContainer(i, bc) #Set the container changes from memory
c4d.EventAdd()
if __name__=='__main__':
main()
How did I come up with this code?
I had to learn about how the UD system works. It's a rather convoluted system of a master base container. With sub containers. Which hold values consisting of Reals, Longs, Vectors, and Tuples.
Then I mapped it out and made a note for myself to use as a reference guide on how to get at a specific UD attribute.
This is one of several notes I've written to myself about How the UD system works.
And how to get at the specific built-in attributes inside of them:
#This is how to get at the options in a specific UD entry
#The options are different depending on what kind of UD item it is
#These options are descriptions found under "cid DESC_Items" in the sdk (lib_description.h)
import c4d
def main() :
obj = doc.GetFirstObject() #The object hosting the UD
ud = obj.GetUserDataContainer() #The master UD container
first = ud[0] #The first UD entry (by it's stack position...not it's ID#)
#first is now a variable that holds a tuple of two base containers
#first[0] holds the level ID#, and two DescLevel objects
#first[1] holds the various options for the UD entry. Changed by accessing their descriptions
#Here is an example of accessing those options:
container = first[1] #The second tuple container of the UD entry. Which holds most of the attributes
for i in container:
print i #Prints the container ID#s, values
#Examples of what some of these options are for the default UD type entry:
level = first[0][1].id #The level ID#
Lname = first[1][1] #The long name
Sname = first[1][2] #The short name
three = first[1][3] # 3 for certain UD types
minValue = first[1][5] #Min value
maxValue = first[1][6] #Max value
step = first[1][9] #Step Value
anim = first[1][10] #Animatable option
meters = first[1][12] #units type
tupleData =first[1][13] # (700, 5, 0)
interface =first[1][21] #interface type (float=19,
#float slider=1000489,
#float slider noedit = 200000006,
#lat/lon = 1011148)
minslider =first[1][27] #The min slider value (if enabled)
if __name__=='__main__':
main()
I hope that help demystify UD a little bit.
IMHO. The UD system is rather convoluted. Which I why I wrote myself lots of helper notes & guides like this one about it.
-ScottA