Hi @bentraje I just came across this thread and quickly tested the above script in 2024. It still works as expected.
Without any further knowledge I would assume that A) you dont have a xpresso tag on your object or B) its not the the second tag on your object.
Best posts made by blkmsk
-
RE: How to add Strengths of each Pose I set in Pose Morph as Ports into Xpresso?
Latest posts made by blkmsk
-
RE: Correct OCIO Color Value Conversion via Python?
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 -
Correct OCIO Color Value Conversion via Python?
Hello^^
I want to import certain parameters from a JSON file with python. The loading of the file and parameter import works fine so far, the only thing I'm not sure about is how to correctly convert the color values.Here is a short script to demonstrate what I'm doing right now.
This will just set a userdata parameter with the name 'Color' on a selected null object to the value [255.0, 94.3499984741211, 76.5]import c4d def convert_rgb_to_color(rgb_list): if len(rgb_list) != 3: raise ValueError("RGB list must contain exactly 3 values.") r, g, b = rgb_list # Normalize 8-bit (0-255) to the range 0.0-1.0 r_normal = r / 255.0 g_normal = g / 255.0 b_normal = b / 255.0 return c4d.Vector(r_normal, g_normal, b_normal) def main(): # Get the active object obj = doc.GetActiveObject() # Check if an object is selected if obj is None: print("No object selected.") return # Define the color value color = [255.0, 94.3499984741211, 76.5] # Convert the color value color_vector = convert_rgb_to_color(color) # Check if the object has user data if not obj.GetUserDataContainer(): print("The selected object has no user data.") return # Iterate over the user data on the object for userdata_id, bc in obj.GetUserDataContainer(): if bc[c4d.DESC_NAME] == "Color": # Set the user data value to the color vector obj[userdata_id] = color_vector c4d.EventAdd() print("'Color' parameter has been set to:", color_vector) return # Execute the script if __name__ == '__main__': main()
When the project color management is set to Basic the value gets set to [255,94,77] as expected.
But when the color management is set to OpenColorIO the value gets set to:
sRGB[255,146,143] / RAW[255,94,77].How could I set the sRGB value to the desired value rather than the RAW value when color Management is OpenColorIO? Like this:
sRGB[255,94,77] / RAW[167,45,25].I'm Thankfull for any hints on the topic!
Cheers and best regards
Ben -
RE: Issue - Loading Spline Object with Python Tag from Asset Browser via Python Script
Awesome, Thank you so much @m_adam !
Cheers and best regards
Ben -
RE: Issue - Loading Spline Object with Python Tag from Asset Browser via Python Script
Hi I just wanted to follow up and ask if this will be fixed any time soon?
Its not super urgent but this bug is putting a project of mine on hold where I want to pull a rig (with several python tags on spline control objects) from the asset browser with a script. For the moment its not a problem to do it manually though but I would love to automate this.Cheers Ben
-
RE: How to add Strengths of each Pose I set in Pose Morph as Ports into Xpresso?
Hi @bentraje I just came across this thread and quickly tested the above script in 2024. It still works as expected.
Without any further knowledge I would assume that A) you dont have a xpresso tag on your object or B) its not the the second tag on your object. -
Issue - Loading Spline Object with Python Tag from Asset Browser via Python Script
Hello^^
I am experiencing a weird, but very specific behaviour in c4d 2024:
When I try to load a Spline Object with a Python Tag attached to it from the Asset Browser via a python script, Cinema 4D 2024 gets stuck. But this happens only with Spline Object and only in 2024. I tried it with a Null Object as well with a Polygon Object and those are loading fine.In Cinema 4D 2023 there is no issue. all three Objects (Spline, Null and Polygon) get loaded with the script and manually loading the Asset by double clicking it in the Asset Browser is also no problem in both versions. Could this be simply a bug?
Here is a small video to show you the behaviour in both R 2023 and R 2024.
The script I used is a striped down version from one of the example scripts on github.Thank you in advance for your time!
-
RE: Get value of texture node filepath port?
Oh wow! Thank you so much!
Yes I'm a beginner with python cinema 4D so I really appreciate your support and this definitly gives me a better understanding of the node structure. -
Get value of texture node filepath port?
Hello,
I have a RS standard Material with one texture node inside of it, linking to a texture file. Now I want to add additional texture nodes/files based on the file location of the original texture node with python.
I know how to add additional nodes but before I can do that I need to retrieve the value of the 'filename' port of the original texture node. (com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0)
Through some examples here on the forum I figured out how to get the value of the name but I'm not able to get the filepath.
here is a small part of my script where I try to print the name and the filepath of the texture node:
from typing import Optional import c4d import maxon doc: c4d.documents.BaseDocument # The active document op: Optional[c4d.BaseObject] # The active object, None if unselected def GetFileAssetUrl(aid: maxon.Id): # Bail when the asset ID is invalid. if not isinstance(aid, maxon.Id) or aid.IsEmpty(): raise RuntimeError(f"{aid = } is not a valid asset ID") # Get the user repository, a repository which contains almost all assets, and try to find the # asset description, a bundle of asset metadata, for the given asset ID in it. repo = maxon.AssetInterface.GetUserPrefsRepository() if repo.IsNullValue(): raise RuntimeError("could not access the user repository") asset = repo.FindLatestAsset( maxon.AssetTypes.File(), aid, maxon.Id(), maxon.ASSET_FIND_MODE.LATEST) if asset.IsNullValue(): raise RuntimeError(f"Could not find file asset for {aid}.") # When an asset description has been found, return the URL of that asset in the "asset:///" # scheme for the latest version of that asset. return maxon.AssetInterface.GetAssetUrl(asset, True) def GetAllMaterials(): materials = [] # Get the active document doc = c4d.documents.GetActiveDocument() # Get the material manager materialManager = doc.GetMaterials() # Iterate through all materials in the material manager for mat in materialManager: materials.append(mat) return materials def main() -> None: # Get the list of all materials in the Material Manager mat_all = GetAllMaterials() material = None for mat in mat_all: if mat.GetName() == "MatTest": material = mat if material is not None: idTextureNode = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler") # Get the RS node graph of the Material nodeMaterial = material.GetNodeMaterialReference() graph = nodeMaterial.GetGraph( maxon.Id("com.redshift3d.redshift4c4d.class.nodespace")) if graph.IsNullValue(): raise RuntimeError("could not get RS graph of the imported material") texResult = [] maxon.GraphModelHelper.FindNodesByAssetId(graph, idTextureNode, True, texResult) # print the texturesampler node name and the texture file path for tex in texResult: print("Name: "+ str(tex.GetValue(maxon.NODE.BASE.NAME))) print("Path: "+ str(tex.GetValue("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0"))) else: print("Cant find Material") print(" ") c4d.EventAdd() if __name__ == '__main__': main()
Maybe someone here can point me in the right direction?
Thanks in advance for your time!
-
RE: Check the state of record modes with python?
ah ok I figured it out. its possible to check those with the c4d.IsCommandChecked() function.
-
Check the state of record modes with python?
Hello,
I'm trying to figure out a way to check the state of the record modes (position, scale, rotation, parameters, pla) located under the 'animate -> record(modes)' menu with python?
I've already done a extensiv search in the documentation but could not find anything. Maybe someone has an idea and can push me in the right direction?
I know how to toggle the modes with c4d.CallCommand() but I want to check the state before toggeling.
Thank you in advance!