• Data, DataTypes, Python and GUI

    Cinema 4D SDK c++ python
    7
    0 Votes
    7 Posts
    1k Views
    E
    Ok thanks for the help Ferdinand. I will take the road of least resistance and just build on top of float64 vectors
  • 0 Votes
    2 Posts
    659 Views
    i_mazlovI
    Hi @heytraile, Please have a look at our Support Procedures: How to Ask Question section. Usually it is very helpful if one provides a relevant code snippet, demonstrating the issue. This helps to reduce the room for any misinterpretations of your original question. Regarding the issue you're describing, the "null" being logged to the console is often a symptom of an implementation issue within a function that overrides the base implementation. Specifically, if a function (such as Message() or RestoreLayout()) is expected to return a particular type (e.g., bool), but instead returns None or a mismatched type, it can result in unexpected behavior and the "null" log. Cheers, Ilia
  • Python - How to insert knots in c4d.Gradient

    Cinema 4D SDK python
    3
    0 Votes
    3 Posts
    694 Views
    V
    Thank you very much, @i_mazlov! This is what I needed!
  • Python - Set Take render state

    Cinema 4D SDK python
    4
    1
    0 Votes
    4 Posts
    844 Views
    J
    @ferdinand Okay I will do it in the future. Thanks for the code snippet, always helps to learn!
  • Syntax highlight in VS Code under MacOS

    Cinema 4D SDK python macos
    4
    0 Votes
    4 Posts
    1k Views
    ferdinandF
    I would heavily recommend using the extension, as it will automatically curate the paths for you. I.e., when you use the extension and connect to a Cinema 4D instance, it will make sure that the dummy modules of that Cinema 4D version are on the search paths. But when you really do not want to use it, you can also just edit your config so that the dummy module paths are discoverable for auto complete and the linter. [image: 1731583351292-2a76cd6c-35aa-451f-82db-02b03694e72d-image.png] What you will need in any case, is the Python and Pylance extension for VS Code, as they are the extensions which make use of these settings. When you install the connector, they will be installed automatically as a dependency. [image: 1731583415824-0b5d77af-5f23-4203-9a0a-276b8eafc62e-image.png] Cheers, Ferdinand
  • How to set the active documents preview image

    Cinema 4D SDK windows python
    2
    0 Votes
    2 Posts
    524 Views
    ferdinandF
    Hey @MMayrh, Thank you for reaching out to us. This is not how this parameter works. The parameter DOCUMENT_PREVIEW_IMAGE is of data type BitmapButtonStruct, not of BaseBitmap. [image: 1731082043337-54c636b2-05c8-4e3a-af41-9edf7e80bd24-image.png] The documentation is a bit misleading here. This is not the document preview bitmap, but sort of the preview bitmap delegate. I.e., an entity that is used to retrieve a preview bitmap (for a document in this case). A BitmapButtonStruct wraps a node, an ID, and a dirty flag. [image: 1731082143508-3e4681a7-7db6-45b7-a1da-5279cc028cf2-image.png] This parameter does not make too much sense in the Python API, here is what the C++ API does when the parameter is access for a document: [image: 1731082401202-459e7ff6-a8fe-4abf-ae35-adc803c17170-image.png] I.e., it returns itself (the doc), the ID of the parameter (DOCUMENT_PREVIEW_IMAGE) and the dirty state of its internal current preview bitmap as the BitmapButtonStruct bbs. What you could technically try, is implement a node, e.g., an object, and then set that object as the preview provider for a document. Your node would for that have to implement MSG_DESCRIPTION_GETBITMAP, because that is what effectively will be called. But that is all very theoretical, DOCUMENT_PREVIEW_IMAGE is largely unused in our code base, and I do not see any implemnation for the SetParameter part. So, the document will likely just ignore you trying to overwrite its preview provider. There could be some base implemenation kicking in, but I doubt it. But what you definitely cannot do, is just set there a bitmap to overwrite the preview image of the document (assuming that was what you wanted to do). That would also not make too much sense since a document is constantly recalculating its preview image. So, on the next update that image would be gone (if it would work like that). Cheers, Ferdinand
  • Python reading fields issue

    Moved Bugs python 2023 2024
    4
    2
    0 Votes
    4 Posts
    2k Views
    ferdinandF
    Yes, we will treat it as a bug. Apparently we implemented it, but then someone disabled the implementation (probably because it caused performance issues or something like that), and then we forgot do follow up on that disabled implementation. Generally we cannot give ETA's for fixes but we try to do them in a timely fashion, i.e., within a couple of minor releases such as 2024.1, 2024.2, 2024.3, etc. I am not the dev here, so I can give even less guarantees. We will update this thread when something blocks us from fixing this in the near future. And yes, it does work in C++. The reason why this is not working in Python is because of the C++ API changes with 2024.0. This link shows how you sample things in C++, the changes revolved around making sampling a field a const operation, i.e., an operation which does not change data on the object. Which was before not the case and now requires that mutable data to be manually passed arround as the extraData as shown in the example. The changes were carried out to speed up the core of Cinema 4D. Cheers, Ferdinand
  • Mesh Cleanup - script or plugin for C4D?

    Moved General Talk python 2024
    2
    1
    0 Votes
    2 Posts
    963 Views
    M
    Welcome to the Maxon developers forum and its community, it is great to have you with us! Getting Started Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules. Therefor I moved your topic to the General Talk which is the place to make request to the community. While Cinema 4D SDK board is purely about development questions. Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment. Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support. Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads. It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions. About your First Question There is no such plugins (at least that I'm aware) in Cinema 4D, however you may be able to find issue in your mesh via the Mesh Checking features available in the Mode of the Attribute Manager. [image: 1731077134354-1d38a2e5-3304-415b-803b-bf6859b55c34-image.png] I let the community answers regarding your request in case a developer have done a plugins that may fit your needs. Cheers, Maxime.
  • TempUVHandle always None! Why?

    Cinema 4D SDK r21 python windows
    3
    0 Votes
    3 Posts
    933 Views
    ThomasBT
    @i_mazlov Thank you very much for the hint with the texture view and for the helpful links. The second thread I have already read, but was not able to find the solution so far. I study these examples. Thank you.
  • Bake animation in the background

    Cinema 4D SDK python
    2
    0 Votes
    2 Posts
    755 Views
    i_mazlovI
    Hi @brian-michael, I've forked your posting in a dedicated thread. For your following postings please stick to our guidelines, which you can find in the Support Procedures, namely: Singular Subject: From all this follows that a topic must have a singular and sparse subject tied to a specific problem especially when it comes to N-years-old threads Regarding your question, please share more context on what specifically you're trying to do, because depending on that you can end up in a completely different ways of approaching your goal. For example, if you'd like to bake animation in a "read-only manner" (just take the object transformations and store/send them somewhere), then the suggested approach would be to clone document and process it in a separate C4DThread. You can check Ferdinand's code example on the exact same topic in application to rendering document: RenderDocument/PythonCallBack : how to display progress prints during the render. However, with such approach you're limited to not being able to modify original document (because you'd use the cloned document instead of the active one). Cheers, Ilia
  • 0 Votes
    3 Posts
    788 Views
    B
    Hey Ferdinand, Thank you for the quick response! Ah ok I see. Thank you for the provided information, I will have a look at it. But I can also wait for the moment. My work arround for now would be to simply set everything up / import the parameters and colors with color management set to 'Basic' and manually doing the conversion via 'Convert to OCIO' in the Project settings. Thats giving me the correct result. But thanks again! Cheers, Ben
  • 0 Votes
    8 Posts
    2k Views
    S
    Hello @ferdinand ! Thanks for answer it is very clear, i will use virtual resolution from now on
  • Hide Items (Object Plugin)

    Cinema 4D SDK 2024 python
    3
    0 Votes
    3 Posts
    731 Views
    R
    @m_adam Thanks, I await your info. Have a nice weekend
  • Vertex Map Tag not in sync error

    Cinema 4D SDK python 2024 windows
    3
    1
    0 Votes
    3 Posts
    855 Views
    D
    Hi Ilia, Thank you very much, I was not aware of that! Cheers!
  • MacOS C4D Python app questions

    Cinema 4D SDK python macos
    4
    0 Votes
    4 Posts
    999 Views
    ferdinandF
    Good to hear. When you want to know more about how to expose libraries, I would recommend reading the Python Libraries Manual, as there are quite a few differences to a vanilla CPython. The guide is a little bit dated, I haven't updated it yet to the pip support Maxime is adding, and I also did not yet cover there mxutils.LocalImportPath. Cheers, ferdinand
  • Help with C4D Preferences Plugin Installation/

    Cinema 4D SDK python 2024 2023
    2
    0 Votes
    2 Posts
    819 Views
    ferdinandF
    Hello @qq475519905, Thank you for reaching out to us. Your question is very ambiguous. But given your posting history, I assume this is a development question and not an end user question. I.e., you are a developer who struggles with setting up a plugin which is being loaded, and you are not a user struggling with installing someone else's plugin (the latter would be out of scope of support for the developer forum). We have plenty of Python plugin examples on Github, for anything more concrete, we will need a more concrete question from you. Most importantly executable example code which highlights your problem. Please have a look at Support Procedures: How to Ask Questions. Cheers, Ferdinand
  • Detect error-causing nodes in XPresso

    Cinema 4D SDK python
    4
    1
    0 Votes
    4 Posts
    1k Views
    K
    Hi @i_mazlov , Unfortunately, the python node approach is not effective for my use case, so I may have to emulate the error conditions on my own for each node. In any case, thank you for your answer.
  • 0 Votes
    4 Posts
    1k Views
    ferdinandF
    Oh, my bad, I did overlook that you flagged this as S26. Yes, mxutils is a 2024+ feature. I used it here to carry out type checks, e.g., that a document or bitmap are not null/none. The code will run without them, but it will fail more gracefully with these checks. You could replace these calls with manual checks: bmp: c4d.bitmaps.BaseBitmap = c4d.bitmaps.MultipassBitmap( int(rData[c4d.RDATA_XRES]), int(rData[c4d.RDATA_YRES]), c4d.COLORMODE_RGB)) if bmp is None: # or more precise: if not isinstance(bmp, c4d.bitmaps.BaseBitmap) ... raise MemoryError("Failed to allocate bitmap.") Cheers, Ferdinand
  • Dissipating fog volume

    Cinema 4D SDK python
    2
    0 Votes
    2 Posts
    586 Views
    ferdinandF
    Hey @ops, Thank you for reaching out to us. Please excuse the delayed reply. You must use the c4d.modules.volume.VolumeBuilder interface for what you want to do, specifically its GetInputObject method. You have to understand that a volume builder is not a singular object, but a virtual tree of objects, and most parameters are located on one of these child objects. Cinema 4D then only displays the parameters of the child objects inline in the GUI (i.e., description) of the Volume Builder object. [image: 1729163133931-5b76e06e-da90-4205-9e68-3e0ca7d14e8f-image.png] Fig.I: The internal makeup of a Volume Builder object. The virtual hierarchy in form of Volume Filter is inaccessible both via the Object Manager and things like GeListNode.GetChildren(). Instead we must use the dedicate UI and API interface to access them. Cheers, Ferdinand Code """Sets the new min and max values of a Volume Builder fog range object. Must be run as a Script Manager script with a Volume Builder object selected. """ import c4d doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. #: The volume builder fog range object type. We currently do not expose a symbol for this. c4d.Ofograngemap = 1039862 def main() -> None: """Called by Cinema 4D when the script is being executed. """ if not isinstance(op, c4d.modules.volume.VolumeBuilder): raise ValueError("The selected object is not a Volume Builder.") # Iterate over the objects in the Volume Builder 'Objects' parameter list. for i in range(op.GetInputObjectCount()): node: c4d.BaseList2D | None = op.GetInputObject(i) # Can happen for folders and on failure, there is no good way to distinguish between the two. if node is None: continue # This is a fog range object, we could do here further checks to ensure it is the correct one. if node.GetType() == c4d.Ofograngemap: print(f"{node[c4d.ID_VOLUMEFILTER_SDF_REMAP_NEW_MIN] = }") print(f"{node[c4d.ID_VOLUMEFILTER_SDF_REMAP_NEW_MAX] = }") # Set new values. node[c4d.ID_VOLUMEFILTER_SDF_REMAP_NEW_MIN] = 0.5 node[c4d.ID_VOLUMEFILTER_SDF_REMAP_NEW_MAX] = 2.0 # Push an update event to Cinema 4D to refresh the user interface. c4d.EventAdd() if __name__ == '__main__': main()
  • Render depth map using python

    Cinema 4D SDK python
    3
    0 Votes
    3 Posts
    794 Views
    G
    Thank you for the quick answer. Unfortunately this approach was quite destructive for my workflow, so i found a workaround using materials and 3d gradients. For anyone who want to render z-depth in python from c4d scene, this may be the approach. There may be some tweaks considering color space. It would be nice to get access to this kind of data inside cinema 4d's python without crazy workarounds. import c4d from c4d import gui, plugins, storage import os PLUGIN_ID = 1234567 # Replace this ID with your unique plugin ID from Maxon def GetFilterTypeFromFilename(filename): ext = os.path.splitext(filename)[1].lower() if ext == '.bmp': return c4d.FILTER_BMP elif ext == '.jpg' or ext == '.jpeg': return c4d.FILTER_JPG elif ext == '.png': return c4d.FILTER_PNG elif ext == '.tif' or ext == '.tiff': return c4d.FILTER_TIF elif ext == '.exr': return c4d.FILTER_EXR else: return c4d.FILTER_PNG # Default to PNG if extension is unrecognized class RenderDialog(gui.GeDialog): DESTINATION_FILE = 1001 BROWSE_BUTTON = 1002 RENDER_BUTTON = 2000 def CreateLayout(self): self.SetTitle("External Render Plugin") # Add Destination File Field self.GroupBegin(id=0, flags=c4d.BFH_SCALEFIT, cols=2) self.AddStaticText(id=0, flags=c4d.BFH_LEFT, name="Destination File:") self.AddEditText(id=self.DESTINATION_FILE, flags=c4d.BFH_SCALEFIT) self.GroupEnd() # Add Browse Button self.AddButton(id=self.BROWSE_BUTTON, flags=c4d.BFH_LEFT, name="Browse") # Add Render Button self.AddButton(id=self.RENDER_BUTTON, flags=c4d.BFH_CENTER, name="Render") return True def Command(self, id, msg): if id == self.BROWSE_BUTTON: path = storage.SaveDialog(title="Select Destination File") if path: self.SetString(self.DESTINATION_FILE, path) return True elif id == self.RENDER_BUTTON: path = self.GetString(self.DESTINATION_FILE) if not path: gui.MessageDialog("Please specify a destination file.") return True # Get the active document doc = c4d.documents.GetActiveDocument() # Create a large sphere object sphere = c4d.BaseObject(c4d.Osphere) sphere[c4d.PRIM_SPHERE_RAD] = 10000000 # Set radius to 10,000,000 m doc.InsertObject(sphere) c4d.EventAdd() # Check if a material named "LuminanceMaterial" already exists material = doc.SearchMaterial("LuminanceMaterial") if not material: # Create new material and set its parameters material = c4d.BaseMaterial(c4d.Mmaterial) material.SetName("LuminanceMaterial") material[c4d.MATERIAL_USE_COLOR] = False material[c4d.MATERIAL_USE_REFLECTION] = False material[c4d.MATERIAL_USE_LUMINANCE] = True # Create gradient shader and set it as luminance gradient_shader = c4d.BaseShader(c4d.Xgradient) if gradient_shader: gradient_shader[c4d.SLA_GRADIENT_TYPE] = c4d.SLA_GRADIENT_TYPE_3D_LINEAR # 3D Linear Gradient gradient_shader[c4d.SLA_GRADIENT_SPACE] = c4d.SLA_GRADIENT_SPACE_WORLD # World space gradient_shader[c4d.SLA_GRADIENT_CYCLE] = False material[c4d.MATERIAL_LUMINANCE_SHADER] = gradient_shader material.InsertShader(gradient_shader) # Insert material into the document doc.InsertMaterial(material) # Update gradient start and end points for the current camera gradient_shader = material[c4d.MATERIAL_LUMINANCE_SHADER] if gradient_shader: camera = doc.GetActiveObject() if not camera or camera.GetType() != c4d.Ocamera: camera = doc.GetRenderBaseDraw().GetSceneCamera(doc) if not camera: camera = doc.GetRenderBaseDraw().GetEditorCamera() if camera: start_position = camera.GetMg().off focus_distance = camera[c4d.CAMERAOBJECT_TARGETDISTANCE] end_position = start_position + (camera.GetMg().v3 * focus_distance) # Use v3 for z-axis direction gradient_shader[c4d.SLA_GRADIENT_START] = start_position gradient_shader[c4d.SLA_GRADIENT_END] = end_position # Enable material override in render settings rd = doc.GetActiveRenderData() rd[c4d.RDATA_MATERIAL_OVERRIDE] = True rd[c4d.RDATA_MATERIAL_OVERRIDE_LINK] = material # Set render settings rdata = rd.GetDataInstance().GetClone(c4d.COPYFLAGS_NONE) rdata[c4d.RDATA_PATH] = path rdata[c4d.RDATA_RENDERENGINE] = c4d.RDATA_RENDERENGINE_STANDARD # Create a bitmap to render into width = int(rdata[c4d.RDATA_XRES]) height = int(rdata[c4d.RDATA_YRES]) bmp = c4d.bitmaps.BaseBitmap() result = bmp.Init(width, height) if result != c4d.IMAGERESULT_OK: gui.MessageDialog("Failed to initialize bitmap.") return True # Trigger render render_result = c4d.documents.RenderDocument( doc, # Document to render rdata, # Render settings bmp, # Bitmap to render into c4d.RENDERFLAGS_EXTERNAL | c4d.RENDERFLAGS_DONTANIMATE # Flags ) if render_result != c4d.RENDERRESULT_OK: gui.MessageDialog("Render failed.") else: # Determine the appropriate file format filter filter_type = GetFilterTypeFromFilename(path) # Save the rendered image save_result = bmp.Save(path, filter_type, c4d.BaseContainer()) if save_result != c4d.IMAGERESULT_OK: gui.MessageDialog("Failed to save image.") else: gui.MessageDialog("Render completed and saved.") # Turn off material override after rendering rd[c4d.RDATA_MATERIAL_OVERRIDE] = False rd[c4d.RDATA_MATERIAL_OVERRIDE_LINK] = None # Delete the large sphere after rendering sphere.Remove() c4d.EventAdd() # Delete the material after rendering if material: material.Remove() c4d.EventAdd() # Refresh the document c4d.EventAdd() return True return False class ExternalRenderPlugin(plugins.CommandData): def __init__(self): self.dlg = None def Execute(self, doc): if not self.dlg: self.dlg = RenderDialog() self.dlg.Open(c4d.DLG_TYPE_ASYNC, defaultw=400, defaulth=100) return True if __name__ == "__main__": plugins.RegisterCommandPlugin( id=PLUGIN_ID, str="External Render Plugin", info=0, icon=None, help="Render current frame to a specified file", dat=ExternalRenderPlugin() )