nr.c4d.modeling¶
-
class
nr.c4d.modeling.Error[source]¶ This exception is generally raised if an exception in a modeling function occurred. For instance, if the required preconditions for the “Current State to Object” command are not met, it will return no object in which case this exception is raised.
Kernel Objects¶
-
class
nr.c4d.modeling.Kernel(doc=None)[source]¶ The Kernel class provides all modeling functionality. Some modeling functions require a document to operate in, others may even require it to be the active Cinema 4D document as it may use
c4d.CallCommand()to achieve its goal. Yet, the Kernel does not necessarily be initialized with a document. You will be able to use all functions that do not require it. Some methods are even static as they require no specialised context.To create a temporary document, you should use the
nr.c4d.utils.TemporaryDocumentclass.-
boole(obja, objb, boole_type, high_quality=True, single_object=False, hide_new_edges=False, break_cut_edges=False, sel_cut_edges=False, optimize_level=0.01)[source]¶ Uses the Cinema 4D “Boole Object” to perform a boolean volumetric operation on obja and objb and returns the resulting object hierarchy. The method parameters reflect the “Boole Object” parameters.
Parameters: - obja – The first object for the boole operation.
- objb – The second object for the boole operation.
- boole_type –
One of the boole modes:
c4d.BOOLEOBJECT_TYPE_UNIONc4d.BOOLEOBJECT_TYPE_SUBTRACTc4d.BOOLEOBJECT_TYPE_INTERSECTc4d.BOOLEOBJECT_TYPE_WITHOUT
- high_quality – See Boole Object documentation.
- single_object – See Boole Object documentation.
- hide_new_edges – See Boole Object documentation.
- break_cut_edges – See Boole Object documentation.
- sel_cut_edges – See Boole Object documentation.
- optimize_level – See Boole Object documentation.
Returns: The result of the Boole operation converted using
current_state_to_object().Requires: - The Kernel must be initialized with a document.
Raises: - RuntimeError – If the Kernel was not initialized with a document.
- TypeError – If obja or objb is not a BaseObject.
- ValueError – If boole_type is invalid.
- Error – When an unexpected error occurs.
-
connect_objects(objects)[source]¶ Joins all PolygonObjects and SplineObjects the list objects into a single object using the Cinema 4D “Connect Objects” command.
This method will move all objects to the internal document temporarily before joining them into one object.
Parameters: objects – A list of
c4d.BaseObject.Returns: The new connected object.
Requires: - The Kernel must be initialized with a document.
Raises: - RuntimeError – If the Kernel was not initialized with a document.
- TypeError –
- If objects is not iterable
- If an element of objects is not a BaseObject
- Error – When an unexpected error occurs.
Important
The returned object axis is located at the world center. If you want to mimic the real “Connect Objects” command in that it positions the axis at the location of the first object in the list, use the
nr.c4d.utils.move_axis()function.
-
current_state_to_object(obj)[source]¶ Executes the Cinema 4D “Current State to Object” on obj and returns the resulting object. The object will be temporarily moved into the document the Kernel was initialized with. If you want to keep links (eg. texture tag material links), the Kernel should have been initialized with the objects document.
Note
All parent objects of obj will be moved with it as it may have influence on the outcome (eg. deformers applied on a hierarchy in a Null-Object).
Requires: - The Kernel must be initialized with a document.
Raises: - RuntimeError – If the Kernel was not initialized with a document.
- TypeError – If obj is not a BaseObject.
- Error – When an unexpected error occurs.
-
static
optimize(obj, tolerance=0.01, points=True, polygons=True, unused_points=True)[source]¶ Optimizes the PolygonObject obj using the Cinema 4D “Optimize” command. The parameters to this method reflect the parameters of the Cinema 4D command.
Raises: - TypeError – If obj is not a PolygonObject.
- Error – When an unexpected error occurs.
-
polygon_reduction(obj, strength, meshfactor=1000, coplanar=True, boundary=True, quality=False)[source]¶ Uses the Cinema 4D “Polygon Reduction” deformer to create a copy of obj with reduced polygon count. The parameters to this function reflect the parameters in the “Polygon Reduction” deformer.
current_state_to_object()is used to obtain the deformed state of obj.Requires: - The Kernel must be initialized with a document.
Raises: - RuntimeError – If the Kernel was not initialized with a document.
- TypeError – If obj is not a BaseObject.
- Error – When an unexpected error occurs.
Important
In rare cases, the returned object can be a null object even though the input object was a polygon object. In that case, the null object contains the reduced polygon object as a child.
-
static
triangulate(obj)[source]¶ Triangulates the PolygonObject obj in place.
Raises: - TypeError – If obj is not a PolygonObject.
- Error – When an unexpected error occurs.
-
static
untriangulate(obj, angle_rad=None)[source]¶ Untriangulates the PolygonObject obj in place.
Parameters: - obj – The
c4d.PolygonObjectto untriangulate. - angle_rad – The untriangulate angle radius. Defaults to 0.1°.
Raises: - TypeError – If obj is not a PolygonObject.
- Error – When an unexpected error occurs.
- obj – The
-