Acessing User data using Python
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 31/12/2010 at 16:25, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform:
Language(s) : PYTHON ;---------
I have been trying create a script to access 3 link fields I added as user data to a python object. I seem to be able to get a container of all the user data using the op.GetUserDataContainer() command, but i cant seem to figure out how to use the tuples of data it spits out to get the position of the linked objects. i have a feeling im going about this completely wrong, so any help would be greatly appreciated.when i put this code into my python object:
import c4d
from c4d import utilsdef main() :
UserData = op.GetUserDataContainer()
print UserDatathe console prints out :
[((1, 133, 0), <c4d.BaseContainer object at 0x0000000016616308>), ((2, 133, 0), <c4d.BaseContainer object at 0x0000000016616260>), ((3, 133, 0), <c4d.BaseContainer object at 0x00000000166162D0>)]
and when i try to get individual elements using the __getitem__(0) :
def main() :
UserData = op.GetUserDataContainer()
obj1 = UserData.__getitem__(0)
print obj1it prints out:
((1, 133, 0), <c4d.BaseContainer object at 0x0000000016616308>)ok, so far so good.
but when i try to access that object's position:
def main() :
UserData = op.GetUserDataContainer()
obj1 = UserData.__getitem__(0)
obj1_pos = obj1.GetRelPos()
print obj1_posI get this error:
Traceback (most recent call last) :
File "<Python Generator>", line 9, in main
AttributeError: 'tuple' object has no attribute 'GetRelPos'thanks in advance for any help! I'm a noob to all of this.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 01/01/2011 at 14:02, xxxxxxxx wrote:
Hi,
there is a much simpler way to access user datas:
value1=op[c4d.ID_USERDATA, 1] #use 1 for the first user data value2=op[c4d.ID_USERDATA, 2] #use 2 for the second user data
Btw, if your code returns:
((1, 133, 0), <c4d.BaseContainer object at 0x0000000016616308>)
def main() : UserData = op.GetUserDataContainer() obj1 = UserData.__getitem__(0) #better use UserData[0] obj1_pos = obj1.GetRelPos() #obj1 is (1,133,0) so its a tuple and GetRelPos is not a member of a tuple print obj1_pos
Cheers, Sebastian
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 01/01/2011 at 14:14, xxxxxxxx wrote:
Sebastian, you rock. that worked like a charm!
I had one more question if its not too much trouble. If my particular user data is a list of objects(a.k.a. InExcludeData list) how can i iterate through those object's position values safely, without crashing cinema. Thanks again!
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 01/01/2011 at 14:28, xxxxxxxx wrote:
here is the code that keeps crashing my rig.
import c4d
from c4d import documents, utils, internals
#Welcome to the world of Pythondef LinkListObjs(i,L): #this function will eventually harvest the average position
obj = L.ObjectFromIndex(doc, i) #matrix of the objects inside linkList
return obj
print str(obj)def main() :
linkList = op[c4d.ID_USERDATA, 1]
objNum = linkList.GetObjectCount()
objCount = 0
while(objCount != objNum+1) : #check if object counter reached it's limit before proceeding
if (objCount>objNum) :
pass # just in case object count has reached it's limit... again
elif(objCount>=objNum) : # otherwise, run the LinkListObjs() function describe above
obj= LinkListObjs(objCount, linkList)
objCount=objCount+1 # add one to object counter
return c4d.BaseObject(c4d.Ocube) -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 01/01/2011 at 17:34, xxxxxxxx wrote:
Can you please upload a small test file where the crash is reproducable or can you send the bugreport to MAXON? Thanks!
Cheers, Sebastian
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 01/01/2011 at 18:42, xxxxxxxx wrote:
Here is a link to download the scene file. It is pretty basic, built in c4d 12, but be careful if you turn on the python object. It crashes my system every time.
http://www.4shared.com/file/S5IYt6nE/New_Python_Averager.html
here is a link without a wait time. stupid wait times.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/01/2011 at 07:10, xxxxxxxx wrote:
Thanks for uploading. This line is responsible for
while(linkList) :
You run into an endless loop. You need to ensure that the loop
will exit. Btw, you wrote your system crashed. C4D should
freeze due to this line, but you should be able to quit it
via the task manager.Cheers, Sebastian
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 03/01/2011 at 09:48, xxxxxxxx wrote:
for sure. I'll try to figure it out. thanks again for the help!
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 03/01/2011 at 15:45, xxxxxxxx wrote:
got it working in case anyone cares!
import c4d
from c4d import documents, utils, internals
#Welcome to the world of Pythondef main() :
pos_avg = c4d.Vector(0)
obj_pos = c4d.Vector(0)
doc = op.GetDocument()
linkList = op[c4d.ID_USERDATA, 1]
linkList_cnt = linkList.GetObjectCount()
for x in xrange(linkList_cnt) :
obj = linkList.ObjectFromIndex(doc, x)
obj_pos = obj.GetRelPos()
pos_avg = (obj_pos.__add__(pos_avg))
op.SetRelPos(pos_avg/linkList_cnt) -
On 24/03/2015 at 01:22, xxxxxxxx wrote:
hello guys. i'm sorry if my english is bad.
i have some question.i designed a roller coaster. i want to get position data of moving train. can u help me?
how to declare id object? -
On 24/03/2015 at 07:28, xxxxxxxx wrote:
Hello and welcome,
if you have a new question that is not related to this thread's topic please open a new thread. Thanks.
Also, please share as much information as possible on your plugin and on what you want to achieve.
Best wishes,
Sebastian