Python Cloner/Scatter plugin
-
Haay, I want to make a python plugin that clone spheres on top of other objects. The basic setup inside c4d would be like this:
Cloner with a shader effector where he use terrain mask.Now to the problem i created the basic object with the settings but i dont know where to start with the cloning part. I coded python in blender befor but i find not many infos how to start in c4d.
Are there some opensource plugins that use cloner or could someone help me with the basic start?
Core
-
Here's a great place to get started:
https://github.com/PluginCafe/cinema4d_py_sdk
There are tons of examples to use. As for the specifics of what you're trying to do:
The cloner is a BaseObject. You pass in the integer ID to the BaseObject class to create one:
cloner = c4d.BaseObject(1018544) <--- That number is for cloner. It is not in the documentation however.
The console window in C4D is a great resource for finding out all the names of parameters for anything in C4D. It's located in Extensions -> Console Window or Shift + F10. Click on the python tab on the leftside of the window. No you can drag anything into this console and it will tell you what it is. For instance if i drag a Cloner into the console window it will say Cloner. Now press enter inside the console window and it will print out the following:
<c4d.BaseObject object called Cloner/Cloner with ID 1018544 at 2984230868544>
This tells me that the object is a BaseObject and the ID for it is 1018544 (which is the ID from my code example from above). You can do the same thing with parameters. For instance, you can click and drag any of the parameter titles into the console and it will tell you their ID names as well. Clicking and dragging on 'Mode' in object properties for the cloner into the console window prints this:
Cloner[c4d.ID_MG_MOTIONGENERATOR_MODE]
Hitting enter will give the the value that it is set to.
Cloner[c4d.ID_MG_MOTIONGENERATOR_MODE]
3Using this method plus referring to the Python documentation is your best bet for doing things you haven't been able to find exampels of.
Hope that was helpful.
-
welcome to the forum and the Cinema 4D coding community. Thank you for reaching out to us @coreartz and thank you @wadams for providing an answer. We have not much to add here, @wadams gave you almost all of the relevant information.
It is noteworthy that Cinema does work very differently than Blender when it comes to its Python interfaces, where Blender takes a more procedural/factory-oriented approach, Cinema 4D is strictly object oriented due to its cache building scene logic. To implement a polygonal generator object, one has to implement a
ObjectData
plugin and there overwrite theGetVirtualsObjects
method to build the cache for that object type.One can also get its feet wet with the Python generator object in Cinema when one wants to implement a simple generator object returning polygonal data, i.e., the equivalent of what is done with
ObjectData.GetVirtualObjects()
. See attached example at the end for details. There are no examples in the Python (or C++) SDK for implementing something that wraps around a cloner object. TheObjectData
generator example in the Python SDK is the double circle example, but it deals with spline generators and not with polygonal generators.Cheers,
FerdinandThe scene file: example_python_generator.c4d
The result of the Python Generator object with some user data input:
The code:"""Simple example for a Python Generator object. Creates a cloner and a cube object and clones the cube with the cloner. The script expects an user data value with the id 1 one to be present on the Python Generator object. For simplicity please use the scene file provided. A Python Generator object can be viewed as entry point into writing an ObjectData plugin implementing GetVirtualObjects(), since its main() function is very similar to what one has to do in GetVirtualObjects(). Reference: [1] Python SDK: Types and Symbols List. url: https://developers.maxon.net/docs/py/2023_2/types/index.html As discussed in: https://developers.maxon.net/forum/topic/13470/ """ import c4d def main(): """ """ # Create a cloner object, as pointed out by wadams, there is unfortunately # no type symbol for the cloner object, i.e., there is no MGOCLONER # symbol. cloner = c4d.BaseObject(1018544) # Create a cube object as an object for the Mograph cloner to clone. cube = c4d.BaseObject(c4d.Ocube) # Return a null object if the allocation of either the cloner or cube # failed. if None in (cloner, cube): return c4d.BaseObject(c4d.Onull) # Get the user data parameter defining the offset. The attribute op is # predefined in most scripting object environments in Cinema 4D. In case # of the Python Generator object it does point to the Python Generator # object itself. offset = op[c4d.ID_USERDATA, 1] # Set the cloner to linear mode and 10 clones with an offset defined by # the user data. Apart form the console approach described by wadams, # there is also the symbols description [1] in the Python docs to identify # required symbols when writing code. cloner[c4d.ID_MG_MOTIONGENERATOR_MODE] = c4d.ID_MG_MOTIONGENERATOR_MODE_LINEAR cloner[c4d.MG_LINEAR_COUNT] = 10 cloner[c4d.MG_LINEAR_OBJECT_POSITION] = offset # Enable the fillet option for the cube object and set the fillet radius # to 10.0 units. cube[c4d.PRIM_CUBE_DOFILLET] = True cube[c4d.PRIM_CUBE_FRAD] = 10. # Add a phong tag to the cube, so that these filleted corners will be # shaded nicely. cube.MakeTag(c4d.Tphong) # Make the cube object a child of the cloner. cube.InsertUnder(cloner) # return the cloner as the cache we did build. return cloner
-
Thanks to both of you! This helps alot! You guys are so nice and helpful