Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
I am a beginner in C4D python, i want to create a group of cylinders in python,This is my original script, it is simple but wrong, Thank you if you can solve my problem
import c4d def create_object(x): position = c4d.Vector(x, 0, 0) a = c4d.BaseObject(c4d.Ocube) a.SetAbsPos(position) return a def main(): for i in range(1,1000,100): create_object(i) '''
it should be a line array group of cylinders,the distance of each is 100,but
No response,i am so sad~
Hi ilad, thanks for reaching out us and welcome to our community
With regard to your issue, there are two main things to note:
create_object
Something like the code below should work.
import c4d def create_object(x): position = c4d.Vector(x, 0, 0) a = c4d.BaseObject(c4d.Ocube) a.SetAbsPos(position) return a def main(): for i in range(1,2000,400): doc.InsertObject(create_object(i)) c4d.EventAdd()
That said I also recommend you for the future to:
Keep enjoying your discovery of Cinema 4D Python API and feel free to get back with further questions
Riccardo
@r_gigante Thank for your kind and high-quality assistance! it is such a great forum to study and learn
Hi Ilad, I've overlooked one thing here: my notes above are useful if you're running the code as a script in the Script Manager but if you're using a Python generator then you've to return an object in your code that contains all the different cubes and, in this case, the EventAdd() can be skipped.
EventAdd()
Something like this should work:
import c4d def create_object(x): position = c4d.Vector(x, 0, 0) a = c4d.BaseObject(c4d.Ocube) a.SetAbsPos(position) return a def main(): mynull = c4d.BaseObject(c4d.Onull) for i in range(1,2000,400): create_object(i).InsertUnder(mynull) return mynull
Best, Riccardo
@r_gigante Thank for your professional help! I am so grateful for your commitment!