@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()
While trying to understand your code some questions raised in my head :
polyObj.GetAllPoints(). Is it not each point vector? If it's I don't
understand the idea of looping thru those vectors to get each pointPos.....
It's hard for me also to pick up the idea of calculation pointPos
inside the for loop. In your code you are multiplying polyObj global Matrix with point.....
At the moment if I have both null and Sphere at 0,0,0 coordinates all points are deleted. if I move sphere a few units in Y axis strangely the middle of the sphere get deleted.
I will spend more time on it to find out the solution. It seems like I will need some kind of channel(slider) while doing if distance < 100 so I could specified the radius by the slider.
I would also need to have this distance updated in real time so when I move null close to the sphere in the viewport the points inside the radius are automatically deleted.
I am really appreciated Sebastian your input here...Thanks
@s_bach
Thanks for the quick reply.
That's is simply awesome that you made this code so I can dive in and actually grasp some python basic.
I noticed that also yesterday, Xpresso wont allow me to delete points, I can iterate thru them but I could find the way how to literally delete it.
Will go thru the code and let you know my thoughts, for now THANKS A LOT for help.
Thanks
Hey zipit,
Thanks for your suggestions.
I am coming from vex Houdini so I can picture the code here how I can get this type of effect in Houdini I know it's not relevant to C4D but I am trying to make this simple effect in C4D.
In H it would be like this :
Hope that make sense:)
I did never script in c4d so I can not post here any examples:(
Ta
Hey Sebastian,
It's sound for me really complicated
What I would like to achieve is this :
Based on the distance between two object, remove points from the object_1 while the object_2 is close enough to the object_1.
Would that be possible in Xpresso and its point node?
Thanks again for your input.
Thanks,
Andrzej
I was considering the scenario when I have the object and let say one single point/null next to it.
And base on the distance between the null and my mesh I would like to delete the mesh points gradually. I tried xpresso a bit today with point node but I cant figured out how to do it.
From my understanding I would need position attribute from my mesh points and the distance from my null to the mesh as a variables and then I can run if condition saying if the distance is less then something remove points from my geo. If you Guys can help my with that using python or coffee I would be delighted
Thanks