Python: Localized Plugin Name
-
I've read quite a few posts in the forum on how to use
GeLoadString
to get a localized string. I'm trying to do this for the name of an object generator plugin written in Python yet I'm always gettingStrNotFound
when callingGeLoadString
duringRegisterObjectPlugin
.Let me show you what I got. Keep in mind that I excluded stuff that's irrelevant to this topic.
This is my folder structure:
- res
- description
- omyobject.h
- omyobject.res
- strings_en-US
- description
- omyobject.str
- description
- strings_de-DE
- description
- omyobject.str
- description
- c4d_symbols.h
- description
- Omyobject.pyp
In res/description/omyobject.h is this:
#ifndef _omyobject_H_ #define _omyobject_H_ enum { Omyobject = <mypluginid> } #endif
...where
<mypluginid>
is my plugin ID.In res/strings_**-**/description/omyobject.str is this:
STRINGTABLE omyobject { Omyobject "My Object"; }
And finally in Omyobject.pyp I'm trying to register to plugin using this code:
c4d.plugins.RegisterObjectPlugin(id=c4d.Omyobject, str=c4d.plugins.GeLoadString(c4d.Omyobject), g=Omyobject, description="omyobject", icon=bmp, info=c4d.OBJECT_GENERATOR|c4d.PLUGINFLAG_HIDEPLUGINMENU)
str=c4d.plugins.GeLoadString(c4d.Omyobject)
returnsStrNotFound
and I don't know why.What is the intended way to do this?
- res
-
Hi @CJtheTiger, you had almost correct
The file are for the description aka the Object Manager and really specific to this part UI wise, if you want to store any string that you can use in any context you need to define in res/c4d_symbols.h.
enum { Omyobject = <mypluginid> }
And then you need to define your string in res/strings_-/c4d_strings.str.
STRINGTABLE { Omyobject "My Object"; }
Then instead of using str=c4d.plugins.GeLoadString(c4d.Omyobject), you need to use the ID directly since c4d_symbols are not automatically parsed.
Cheers,
Maxime. -
Thank you for your response @m_adam.
Unfortunately I'm still struggling even though I think I did what you suggested. I'm getting this error:
Error reading resource file '...\res\strings_en-US\c4d_strings.str'
Line 2The res\strings_en-US\c4d_strings.str has these contents:
STRINGTABLE omyobject { Omyobject "My Object"; }
Removed link to my repo since it's no longer relevant and will be outdated soon.
-
It seems like I found the working combination.
The
STRINGTABLE
in res\strings_en-US\c4d_strings.str must not be named. In my previous response I pasted the contents which as you can see started withSTRINGTABLE omyobject
whereas it should simply beSTRINGTABLE
without a name.- I guess this str-file cannot contain named
STRINGTABLE
s. My first suspicion was that the error was caused by trying to define twoSTRINGTABLE
s with the same name (since I had anotherSTRINGTABLE
with that name in the description folder) but even choosing another name in the c4d_strings.str resulted in the same error. Only when removing the name did I get rid of the error.
I added the plugin ID to both the res\c4d_symbols.h and the res\description\omyobject.h as an enum member called Omyobject.
- Having the ID in res\c4d_symbols.h allows for having a value outside of description resources (i.e. dialogs) which I required for the plugin name, as @m_adam already explained.
- Having the ID in res\description\omyobject.h allows for description resources to access an accordingly named value in the
STRINGTABLE
in res\strings_xx-XX\description\omyobject.str. It also definesc4d.Omyobject
which I'm now using inc4d.plugins.RegisterObjectPlugin
to access the plugin name in res\strings_xx-XX\c4d_strings.str.- Note that this requires the plugin ID to be defined in two places (res\c4d_symbols.h and res\description\omyobject.h) which decreases maintainability.
- Also note that I'm using the plugin ID from the description header to get a value from a non-description
STRINGTABLE
which sure enough does work but is probably not the cleanest solution.
Does this sort of sound right? Is this the intended way?
- I guess this str-file cannot contain named
-
Hi you are right, I double checked and my c4d_string.str was like that, sorry I copy-pasted your in my reply without notifying it.
// C4D-StringResource // Identifier Text STRINGTABLE { PLuginName "AAAAAA-ROUNDED Tube"; }
All the rest is correct in your sentences.
Cheers,
Maxime.