Modifying MoText text property externally
-
On 18/03/2017 at 10:05, xxxxxxxx wrote:
First, I am a complete nube and this is my first post. I have a project where a MoText object is rendered and I want to make the text field configurable programmatically. I would like this to happen preferably from outside of C4D.
From my VERY preliminary poking around I cannot find anything that would do that from the command line. So it seems that I would have 2 options:
1: Use Melange, as I read that it can create / modify C4D project files directly
Or
2: Maybe use python or coffee scripting to read this value in from a text file and populate the text property of motext with the value
Are either of these reasonable approaches, if so are there any examples that you can point me to. Or if neither is a good option, can someone point me in the right direction? I'm currently using R17.
I appreciate any help that you can give me.
Thanks,
-E -
On 20/03/2017 at 05:43, xxxxxxxx wrote:
Hi,
welcome to the Plugin Café forums
This is a bit difficult to answer. There's certainly not only two options.
Melange should work as well as your second option.
I mean, in the end it comes down to setting one parameter of a MoText object, which boils down to identifying the correct object in a scene (depends on your needs, by name, by ID, ...) and setting a parameter (SetParameter()), ID is PRIM_TEXT_TEXT in this case. Or by getting the BaseContainer instance (GetDataInstance()) of the MoText object and changing the text in there. This is basically the same in Melange as Ciname 4D itself.
My question is, how does your scenario look like exactly? Why modify the text from outside C4D? Is it supposed to live update in C4D? Or can it be set upon a button press? It could even adapt on scene load to some text stored in a text file... there are so many options to achieve something alike.
One thing to keep in mind though, at some point you'll want to render the scene. For any live updating scenario you'd need to distribute the source of the text with the project, so it can be found on render clients.
Other options could be to add a command line option to Cinema 4D, which can be used to set the text. Something like "-motext objname string". Something like this would be done in PluginMessage() (with C4DPL_COMMANDLINEARGS). There's also a manual about PluginMessage().
All of the above, except the Melange solution, could also be done in Python, if you feel more familiar with.
-
On 22/03/2017 at 05:26, xxxxxxxx wrote:
Thanks for the reply! Yes, I want to be able to render from the command line but modify certain parts of the scene external from C4D. I don't want any GUI interaction for modifying the value or at least not from within C4D.
Is there a way to point the text property of MoText to the contents of a text file because that would save me work.
I'll look at the PluginMessage() docs and see what is there as well. Again, thank you for your response.
-E
-
On 22/03/2017 at 08:04, xxxxxxxx wrote:
I'm also interested how to implement the FontData since I get stuck at this in my ulgy code
BaseObject* RecurseHierarchy(BaseObject* op) { Int32 bufferType; while (op) { bufferType = op->GetType(); if (bufferType == 1019268) // Is there any constant and if so where can we find them into the sdk { return op; } RecurseHierarchy(op->GetDown()); op = op->GetNext(); } return nullptr; } void setData() { String myText = "this is my text"; BaseObject* op = RecurseHierarchy(doc->GetFirstObject()); if (op == nullptr) return; FontData myFont; //how to assign the value of myText to his? }
-
On 22/03/2017 at 10:04, xxxxxxxx wrote:
Hi,
unfortunately there's no "named ID" in Python for the MoText object. Sorry.
And I guess, there's some confusion about setting the text.
The text can be simply set like so (with op being the MoText object) :op[c4d.PRIM_TEXT_TEXT] = "Hello gr4ph0s"
The FontData under ID PRIM_TEXT_FONT is the font selection. See the note on FontChooserCustomGui.SetFont() for getting a correct FontData container. But that's actually a diffrent topic and should probably be better discussed in a new thread in Python sub-forum.