@m_magalhaes
Thanks.
Next time I will follow the instruction.
Thanks
@m_magalhaes
Thanks.
Next time I will follow the instruction.
Thanks
I have my user date applied on to the null plus python tag is also sitting on the null.
So I think in def main():
I need to get the tag first and then null in order to read the data from userdata......
That's make sense for me anyway)
Thanks
So Did I missed the actual link to my null object?
Ok I figured it out
import c4d
#Welcome to the world of Python
desc_x = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))
desc_y = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION,c4d.DTYPE_VECTOR, 0),
c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))
desc_z = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0))
def createPositionTracks(object):
trackPosX = object.FindCTrack(desc_x)
trackPosY = object.FindCTrack(desc_y)
trackPosZ = object.FindCTrack(desc_z)
if trackPosX is None:
track = c4d.CTrack(object, desc_x)
object.InsertTrackSorted(track)
if trackPosY is None:
track = c4d.CTrack(object, desc_y)
object.InsertTrackSorted(track)
if trackPosZ is None:
track = c4d.CTrack(object, desc_z)
object.InsertTrackSorted(track)
def setPositionKey(object, time, pos):
trackPosX = object.FindCTrack(desc_x)
trackPosY = object.FindCTrack(desc_y)
trackPosZ = object.FindCTrack(desc_z)
curvePosX = trackPosX.GetCurve()
curvePosY = trackPosY.GetCurve()
curvePosZ = trackPosZ.GetCurve()
keydict = curvePosX.AddKey(time)
key = keydict["key"]
key.SetValue(curvePosX,pos.x)
keydict = curvePosY.AddKey(time)
key = keydict["key"]
key.SetValue(curvePosY,pos.y)
keydict = curvePosZ.AddKey(time)
key = keydict["key"]
key.SetValue(curvePosZ,pos.z)
return True
def main():
o = op.GetObject()
source = o[c4d.ID_USERDATA,1]
target = o[c4d.ID_USERDATA,2]
offset = o[c4d.ID_USERDATA,3]
if source is not None and target is not None:
t = doc.GetTime()
createPositionTracks(target)
setPositionKey(target,t,source.GetAbsPos() + offset)
when I having target = op[c4d.ID_USERDATA,2] it;s coming with this error : AttributeError: parameter access failed
Hi Zipit,
Thanks for reply. Yes I have made a mistake typing FindTrack(). It should be FindCTrack().
Can you explain what do you mean by some_node?
Thanks again:)
Hi, I am trying to transfer pos of one obj on the other obj but I am getting this error AttributeError: 'list' object has no attribute 'FindTrack'
I am not sure how to sort it out.
Thanks for any help
import c4d
#Welcome to the world of Python
desc_x = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))
desc_y = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION,c4d.DTYPE_VECTOR, 0),
c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))
desc_z = c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0))
def createPositionTracks(object):
trackPosX = object.FindTrack(desc_x)
trackPosY = object.FindTrack(desc_y)
trackPosZ = object.FindTrack(desc_z)
if trackPosX is None:
track = c4d.CTrack(object, desc_x)
object.InsertTrackSorted(track)
if trackPosY is None:
track = c4d.CTrack(object, desc_y)
object.InsertTrackSorted(track)
if trackPosZ is None:
track = c4d.CTrack(object, desc_z)
object.InsertTrackSorted(track)
def setPositionKey(object, time, pos):
trackPosX = object.FindTrack(desc_x)
trackPosY = object.FindTrack(desc_y)
trackPosZ = object.FindTrack(desc_z)
curvePosX = trackPosX.GetCurve()
curvePosY = trackPosY.GetCurve()
curvePosZ = trackPosZ.GetCurve()
keydict = curvePosX.AddKey(time)
key = keydict["key"]
key.SetValue(curvePosX,pos.x)
keydict = curvePosY.AddKey(time)
key = keydict["key"]
key.SetValue(curvePosY,pos.y)
keydict = curvePosZ.AddKey(time)
key = keydict["key"]
key.SetValue(curvePosZ,pos.z)
return True
def main():
source = [c4d.ID_USERDATA,1]
target = [c4d.ID_USERDATA,2]
offset = [c4d.ID_USERDATA,3]
if source is not None and target is not None:
t = doc.GetTime()
createPositionTracks(target)
setPositionKey(target,t,source.GetAbsPos() + offset)
I thing after short research that c4d.plugins.ObjectData could actually be the solution I am after.
I will be posting my progress here.
Once again Thanks Guys for heads up!!!!!
Thanks
Here I uploaded the effect I am after :
I know that using Boole in C4D I can have exactly the same effect BUT my goal is to start from this simple effect as a python journey.
Thanks for any suggestion.
Thanks
Here is the code I am playing with now
import c4d
from c4d import gui
from c4d import utils
#Welcome to the world of Python
def main():
nullObj = doc.SearchObject("Null")
polyObj = doc.SearchObject("Sphere")
if nullObj:
print("Null is")
if not nullObj:
print("no Null")
if polyObj:
print("Sphere is")
if not polyObj:
print("no Sphere")
#get nullObj world space position
nullWSMg = nullObj.GetMg().off
print nullWSMg
#get matrix and points from polyObj
polyObjWSMg = polyObj.GetMg().off
polyObjPointsPos = polyObj.GetAllPoints()
#print polyObjPointsPos
print polyObjWSMg
#point selection of the polygon object
selection = polyObj.GetPointS()
selection.DeselectAll()
#check each point
for i, point in enumerate(polyObjPointsPos):
#get WS pos of the points
pointPos = polyObjWSMg * point
#get the distance from point to the null
diff = nullWSMg - pointPos
distance = diff.GetLength()
#check distance
if distance < 100:
selection.Select(i)
#delete selected points
mode = c4d.MODELINGCOMMANDMODE_POINTSELECTION
res = c4d.utils.SendModelingCommand(c4d.MCOMMAND_DELETE, list = [polyObj], doc = doc, mode = mode)
c4d.EventAdd()
if __name__=='__main__':
main()