The same is true, trying to rename objects in the OM: It works manually, but not via script. Is it an encoding issue?
Latest posts made by gaschka
-
RE: Rename Layers with Python containing Emoji?
-
Rename Layers with Python containing Emoji?
import c4d doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. def create_and_rename_layer(doc, layer_name): new_layer = c4d.documents.LayerObject() new_layer.SetName(layer_name) root_layer = doc.GetLayerObjectRoot() new_layer.InsertUnderLast(root_layer) c4d.EventAdd() return new_layer def main() -> None: layer_1_string = "Layer 1: \N{grinning face with smiling eyes}" print(layer_1_string) layer_1 = create_and_rename_layer(doc, layer_1_string) layer_2_string = "Layer 2: \U0001F600" print(layer_2_string) layer_2 = create_and_rename_layer(doc, layer_2_string) layer_3_string = "Layer 3: 🤣" print(layer_3_string) layer_3 = create_and_rename_layer(doc, layer_3_string) if __name__ == '__main__': main()
I've the code above, with which I try to create and rename layers, so they contain lovely Emoji. Though when I execute the code, I see the Emoji in the Console, but the layers refuse to rename accordingly.
When I edit a layer by hand, I can input Emoji with no issues:
-
RE: Python tag initalization?
@m_adam said in Python tag initalization?:
OM is not single threaded,
Oh, that's an interesting insight for me. Perhaps I was misinformed, as Character Rigs had the tendency to get slow quite easily in C4D, and Animators look envy over to Maya, as they do have a parallel evaluation (and caching). Though I'm aware that there are changes/improvements to C4D performance lately. Thanks for the link. A lot of new information to learn an absorb
-
RE: Python tag initalization?
@baca thanks for the insights! I guess I sit too long next to game devs who have a tendency for premature optimizations and got infected
But I can second that: I know so many C4D artists who don't have a clue, neither they care, about how to keep theirs scene performant. -
RE: Python script to Python tag hand over?
Thanks for your help and nudging me into the right direction, I think I can work with that
-
RE: Python: How to inject code into a Python tag?
Thanks to you both for your answers.
@m_adam Regarning my issue with the file linking, I'll try to come up with a procedure for reproduction of my issue soon: It was quite random, but I was in the flow of writing my script, so I circumvented with the string solution, but I would prefer the file solution for sure.
-
RE: Python tag initalization?
@m_adam thanks a lot for the explaination and the code. Messages is a new concept for me and something I'll definitely explore.
Referring to point 1: So checking if the object is changed, even with the OM traversal, is something I can ignore performance wise? I'm asking, because I want the tag to control a custom piece of a character rig, perhaps with multiple copies of it. Rigs tend to be quite performance critical and running single threaded in C4D due to the OM so I wonder if this kind of search in the OM can have a significant impact?
-
RE: Python: User Data Float Slider?
@i_mazlov Thank you for the friendly introduction and the hint to CUSTOMGUI and REALSLIDER, exactly what I was looking for.
@baca Thank you for the additional tip. -
Python: How to import files as modules?
Hello everybody,
I'm new to this forum, so please bear with me in case my questions are hardly noob ish. I tried my best to consult the docs and the search first, but still I do have this question:
Right now, I'm working on a script that hit the 600 lines mark, so I thought it's a good idea to create different files and use import to use these files as modules. But somehow C4D python refuses to find the file and use these files as modules. As soon as I deactivate the VSC C4D bridge, the import works (at least this is what the VSC console is telling me).
I've set up an Environment Variable to my script repo with the hope this would fix it, but without any luck.Is this bad practice for a script? Shall I turn it into a plugin to have this as an option?
-
Python: How to inject code into a Python tag?
I'm working on a script, which creates bunch of objects in the OM and then adds a Python Tag to one of them, to control my new objects with a script.
First I tried the following approach, which did not always work reliable from VSC, especially after restarting C4D. My impression was, that I had to open the linked file in the Script Manager once to be able to use the Execute in C4D command in VSC with that file linked successfully:def add_python_tag(obj, config): tag_file = os.path.join(os.path.dirname(__file__), "file_with_code_for_the_python_tag.py") if not obj or not os.path.exists(tag_file): return python_tag = c4d.BaseTag(c4d.Tpython) with open(tag_file, 'r') as f: python_code = f.read() python_tag[c4d.TPYTHON_CODE] = python_code obj.InsertTag(python_tag) c4d.EventAdd()
So I'm using this approach now, but this feels very hacky, and I loose the syntax highlighting for all the injected code, which makes me still maintain the file above and then copy and paste into the string:
def add_python_tag(obj): if not obj: return python_tag = c4d.BaseTag(c4d.Tpython) python_code = """ import c4d def main(): # my code for the Python tag # Execution if __name__ == '__main__': main() """ python_tag[c4d.TPYTHON_CODE] = python_code obj.InsertTag(python_tag) c4d.EventAdd()
I'm new to all of this, so I want to ask, if this a good practice, or are there other more slick ways to approach this?