• SetPortValue for Texture node ColorSpace

    python 2024 windows
    3
    0 Votes
    3 Posts
    685 Views
    M
    Thank you so much, this was very helpful to learn. All the best.
  • Render depth map using python

    python
    3
    0 Votes
    3 Posts
    545 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() )
  • Input port menu in Node Editor does not respect order index

    c++
    4
    1
    0 Votes
    4 Posts
    674 Views
    ferdinandF
    Hey Peter, you can reach out directly to us via mail. While there is some end-user aspect in this, I think it is best handled by SDK. But thanks for asking and caring about submitting to the right place! I will forward your mail/request to the right places. But as hinted at above, I do not see the Node team being all thrilled about this. Maybe also make the case why this is needed as making the case for something usually increases your chances compared to a "I want X"! Maybe also line out how you envision for this to work. E.g., request to introduce an attribute which can be set on port bundles. As for example maxon::DESCRIPTION::UI:NOSORT which is then respected by BuildPopupMenuForDescription. What we very likely will not do, is that we completely turn this off, as both Scene Nodes and Redshift have a lot of data types with many sub ports where it will be hard to find things without alpha-numerical sorting. I could be wrong about all this as I am neither in the Nodes nor Redshift team, but that is the hunch I have when I look at this system. Cheers, Ferdinand
  • Distribute asset library as a zip file

    2024
    3
    0 Votes
    3 Posts
    632 Views
    P
    Hi Ferdinand, Thank you for the detailed description, it's very useful, I have a good understanding now how this should work. Yes, the main goal here is installer optimization. Unfortunately, hosting online is not an option. I'll give it a thorough testing to see if we hit any limitations with this approach, and we might drop the idea if so. Thanks, Peter
  • What is the meaning of code like `doc: c4d.documents.BaseDocument`?

    python
    4
    0 Votes
    4 Posts
    884 Views
    L
    Hello, Ferdinand! Thank you for your attention to my question, your time, and your academic explanations.
  • 0 Votes
    5 Posts
    1k Views
    R
    I was just looking for the exact same thing and would second the need for these 3 hooks without the need for a Python Generator object. It would make the pipeline integration of C4D much more straightforward. @m_adam
  • How to change the projection type for a created material.

    2023 python windows
    5
    0 Votes
    5 Posts
    1k Views
    ferdinandF
    Hey @lednevandrey, without wanting to be rude, I really struggle with understanding what you want to convey. Material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW does not work because Python is case sensitive and you gave your BaseMaterial instance the symbol material. So, Python is complaining about that. But as said before, a material, i.e., BaseMaterial is not the right place to set the projection. It is the counter part to the thing you see in the Material Manager of Cinema 4D and has no projection. The projection is set in the Material Tag, which slightly confusingly is called TextureTag in the API. Cheers, Ferdinand """Assigns the first material in the document to the selected object and sets its projection to UVW. """ import c4d import mxutils doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. def main() -> None: """Called by Cinema 4D when the script is being executed. """ if not op: raise ValueError("Please select an object.") # Get the first material in the document. material: c4d.BaseMaterial = doc.GetFirstMaterial() if not material: raise ValueError("No materials found in the document.") # Get the first existing texture tag on #op or create a new one when none exists. tag: c4d.BaseTag = op.GetTag(c4d.Ttexture) or op.MakeTag(c4d.Ttexture) if not tag: raise ValueError("Failed to get or create a texture tag.") # Set the material and projection. tag[c4d.TEXTURETAG_MATERIAL] = material tag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW # Update the Cinema 4D UI. c4d.EventAdd() if __name__ == '__main__': main()
  • Shader crashes when quitting with unfinished IRR

    c++
    3
    0 Votes
    3 Posts
    593 Views
    R
    It seems not to crash now. I made sure I freed all the bitmaps and flushed all containers.
  • 0 Votes
    6 Posts
    1k Views
    ferdinandF
    Great to hear that you found your solution! Do not hesitate to ask more questions when you run into problems while exploring our Python API. But just as a heads up, we prefer users opening new topics for new questions. For details see the Support Procedures linked above. Cheers, Ferdinand
  • Query Morph Order Based on the UI Order?

    2024 python
    3
    1
    0 Votes
    3 Posts
    694 Views
    B
    Hi @ferdinand Thanks for the response. Found a workaround it. Basically, just name the poses properly in a sorting order. Query the GetName() method and perform my own sorting. Regards, Ben
  • Not able to post?

    s26 python
    2
    0 Votes
    2 Posts
    488 Views
    ferdinandF
    Hey @ELJeffery, Thank you for pointing this out. We are generally aware of this issue. If anyone else is experiencing similar issues, please point them out. While we are aware that the issue exists and we can see the incident reports in the back end, it is not 100% clear to us how frequent this does happen to human users (and how urgent this is issue is). So, when you run into the issue too, please drop us here the Cloudflare Ray ID of your error page. As an FYI, the issue usually rectifies itself after a few minutes. Cheers, Ferdinand
  • C4DAtom.SetParameter/GetParameter help

    2024 python
    3
    0 Votes
    3 Posts
    535 Views
    i_mazlovI
    Hi @ops, Thanks for reaching out to us and thanks for sharing your solution with the community, this is highly appreciated! You're right, the most common way of accessing object's attributes is by using subscript operator. Cheers, Ilia
  • Alembic Export Options Not Working

    python s22
    7
    0 Votes
    7 Posts
    2k Views
    BigRoyB
    Just want to confirm here that I'm facing this same issue - only setting the negative state first and then the positive state after seems to make this work. So, thanks for the workaround. Here's the reported bug on our pipeline: https://github.com/ynput/ayon-cinema4d/issues/6 And this is what fixed it: https://github.com/ynput/ayon-cinema4d/pull/8 Looking at 'what' fixes it this most definitely sounds like a bug. (I tested in Cinema4D 2023.2.2 on Windows 10)
  • React to Set Color Space from the Asset Inspector

    c++ 2023
    2
    1
    0 Votes
    2 Posts
    580 Views
    M
    Hi sadly it is not possible for the moment, I will talk to the responsible team to see if that's possible. Cheers, Maxime.
  • BakeShaderIntoBaseBitmap and Alphas

    c++
    4
    0 Votes
    4 Posts
    806 Views
    R
    @i_mazlov Here is a snippet of my code: BaseShader* shader; shader = (BaseShader*)dat->GetLink(CUBICFACE_BACK_TEXTURE, irs.doc); if (shader != nullptr) { AutoAlloc<BaseBitmap> bitmap; if (bitmap != nullptr) { const IMAGERESULT imageResult = bitmap->Init(quality, quality, 32, INITBITMAPFLAGS::NONE); if (imageResult == IMAGERESULT::OK) { shader->BakeShaderIntoBaseBitmap(*bitmap, *irs.doc, nullptr, true, irs.document_colorprofile, irs.linear_workflow, true, 0, quality-1, 0, quality-1); cfdata.bt_back = BaseBitmap::Alloc(); bitmap->CopyTo(cfdata.bt_back); } } } However, even if the texture placed in the link CUBICFACE_BACK_TEXTURE is a PNG with trnasparency or a shader that creates an alpha (like Fire or Flame), the resulting bitmap never gets an alpha.
  • SetUniqueIP gets lost

    c++
    4
    0 Votes
    4 Posts
    873 Views
    R
    @i_mazlov Well, I got lucky, then As I'm assigning a set of IDs to the objects, using SetUniqueIP inside the InitRender function and I'm being able to read then back inside the Output function, with GetUniqueIP. I mean... my shader is working fine now, and I just need to polish it a bit.
  • Import and managing 'merged' Alembic

    python 2023
    4
    1
    0 Votes
    4 Posts
    1k Views
    i_mazlovI
    Hi @BigRoy, in python the lifetime of the objects is handled automatically so you're right, there's no need to do anything special to destruct the object. Good job on your project! Thanks for sharing it with the community! Cheers, Ilia
  • Create a dynamic list of structs or BaseContainers

    c++
    4
    0 Votes
    4 Posts
    854 Views
    i_mazlovI
    Hi @rui_mac, As long as it fits your needs there's nothing to add against using BaseContainers in your case. However, if you don't need to store hierarchical data, the simpler approach of using BaseArray can sometimes end up in a cleaner implementation. You can use the generic Data type to handle values of different types. Cheers, Ilia
  • Merged Alembic Generator object, how to check if it is a camera?

    python
    2
    0 Votes
    2 Posts
    491 Views
    i_mazlovI
    Hi @BigRoy, For the alembic camera, you can use c4d.MSG_GETREALCAMERADATA, for example: def main(): data = dict() op.Message(c4d.MSG_GETREALCAMERADATA, data) print(data['res']) Another option (which would work for other object types as well) would be to check type of the object's cache using GetCache(). Cheers, Ilia
  • How to know inside a shader what exact object is the shader attached.

    c++
    3
    0 Votes
    3 Posts
    586 Views
    R
    Ok, found out what is wrong. The code inside the Output is being executed in multiple threads. So, one thread may be calculating the color of one object but the data I have in my struct is from another object being calculated by another thread. Is there any way to force a shader to be only calculate in a single thread? Or, is there any way to get a unique value from each object so that I can store a set of structures in the InitRender method, and detect which one is being rendered in the Output method and use the correct structure of data?