How to keep the point coordinates of a polygonObject up to date in Python code
-
Hello, I try to manipulate a polygon point in Python with the SetPoint() command.
So for instance I want to double the Values for X,Y en Z of point[0] = testPnt (for instance Vector(1,1,1))
I use the values of the point to double them. (I used the '×' to indicate multiplication the '*' messes up the post)
op.SetPoint(0,c4d.Vector(testPnt.x×2,testPnt.y×2,testPnt.z×2))
If later somewhere else in my code I change these values again, say I triple them
op.SetPoint(0,c4d.Vector(testPnt.x×3,testPnt.y×3,testPnt.z×3))
and print the values I still get the unchanged values. i.e. Vector(1,1,1)
I want to get (6,6,6) at the end.Here my testing code:
def main(): op = doc.GetActiveObject() #select a polygon object with Point[0] at (1,1,1) as example puntenLijst = op.GetAllPoints() testPnt = puntenLijst[0] print 'pnt0 at start: ' ,testPnt # check the coordinates before manipulation *#prints: pnt0 at start: Vector(1,1,1) ok* op.SetPoint(0,c4d.Vector(testPnt.x*2,testPnt.y*2,testPnt.z*2)) print 'pnt0 after SetPoint:' ,testPnt *#prints: pnt0 after SetPoint: Vector(1,1,1) not ok, got to send Message(c4d.MSG_UPDATE)* op.Message (c4d.MSG_UPDATE) print 'pnt0 after MSG_UPDATE' ,testPnt *#prints: pnt0 after MSG_UPDATE: Vector(1,1,1) not ok, got to do the c4d.EventAdd()* c4d.EventAdd() print 'pnt0 after c4d.EventAdd():' ,testPnt *#prints: pnt0 after c4d.EventAdd(): Vector(1,1,1) not ok, got to do ??* op.SetPoint(0,c4d.Vector(testPnt.x*3,testPnt.y*3,testPnt.z*3)) print testPnt # hoping for Vector(6,6,6) but nope got Vector(1,1,1)
finaly in the Structure Manager after running this code the point has coordinates (3,3,3) and not (6,6,6) the last SetPoint used the startingpoint(1,1,1) and I want to continue with the changed values i.e. (2,2,2)
-
I figured out how to do it.
It's fairly simple. I just have to reassing the pointvalues after the Update
so if I insert a new
puntenLijst = op.GetAllPoints() testPnt = puntenLijst[0]
the 'testPnt' has updated values.
-
Hi @SteveJLV welcome in the plugincafe community,
I would like to point you to some rules:
- Read Before Posting. Nothing wrong here, but just in case.
- Q&A New Functionality. I've setup your topic correctly.
As you already figured it out, you never assign a new value to the variable. In Python, everything is passed by value by default in 90% of the time.
Meaning when you do x = y will actually copy y to x, so afterward if you do x + 10 it will not affect y value.If you have more questions, don't hesitate.
Cheers,
Maxime.