UNSOLVED How can I print something in a new console items in python?

Hello!

Qustion:

Can I create a new item in console for get texts print like gsg do in python?

4d78eed5-8be8-4390-a995-d4070ac17757-image.png

Description:

I usually scripting when my Cinema 4D is rendering something , plugins and render engine always print logs to default and python console , it is hard to find my own reports in console but I have to keep them to know how it going .

So how can I ceate a new item with python and force my tool's log out to this ? (all my tools is also coding in python now)

hi,

this is not possible in python. But possible in c++, you can have a look at our manual

Once the logger is created in c++ you can print there with python.

Cheers,
Manuel

@m_magalhaes
Sad to that , I know nothing about c++ and how c++ works with c4d . I quickly checked @kbar c++ video but I didn't figer it out how it work quickly.

I also looked the example in the manual , but I don't know how can I make it works with c4d, (in python I guess I can check PluginMessage when c4d start and execute the code) could you provide a mini-worked example for this ?

hi,

To use a logger, you need to retrieve the reference to it. For now, you can only check if its name is the same as the one you expect.
Or you can write to one of the loggers you can find on this page

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 main() -> None:
    # Called when the plugin is selected by the user. Similar to CommandData.Execute.

    txt = "Printing in the {} console my text"
    # Write to a specific logger
    defaultLogger = maxon.Loggers.Default()
    defaultLogger.Write(maxon.TARGETAUDIENCE.ALL, txt.format("default"), maxon.MAXON_SOURCE_LOCATION(1), maxon.WRITEMETA.DEFAULT)
    # Write to all loggers.
    for log in maxon.Loggers.GetEntries():
        log.Write(maxon.TARGETAUDIENCE.ALL, txt.format(log.GetName()), maxon.MAXON_SOURCE_LOCATION(1), maxon.WRITEMETA.DEFAULT)


if __name__ == '__main__':
    main()

Cheers,
Manuel

@m_magalhaes
sorry to my bad descrptions , I just cann't figure out how the c++ manuual code how canbe work in cinema

// This example creates a new custom logger and adds it to the registered loggers.
// g_exampleLogger is a maxon::LoggerRef instance.

// define logger ID
const maxon::Id loggerID { "net.maxonexample.logger" };

// check if a logger with that ID already exists
if (!maxon::Loggers::Get(loggerID))
{
  // create the new logger and store it in a global variable for later access
  // make sure to set this object to nullptr when Cinema shuts down
  iferr (g_exampleLogger = maxon::LoggerRef::Create())
  {
    // if the logger could not be created, use the default logger instead
    g_exampleLogger = maxon::Loggers::Default();
  }
  else
  {
    // if the logger could be created
    // add the logger type "Application" to display logged messages in the "Console" window
    g_exampleLogger.AddLoggerType(maxon::TARGETAUDIENCE::ALL, maxon::LoggerTypes::Application()) iferr_return;

    // define logger name
    g_exampleLogger.SetName("Example Logger"_s);
    // insert the logger in the "Loggers" registry
    maxon::Loggers::Insert(loggerID, g_exampleLogger) iferr_return;

    // this message must be send to update the console window
    const maxon::Int32 BFM_REBUILDCONSOLETREE = 334295845;
    SpecialEventAdd(BFM_REBUILDCONSOLETREE);
  }
}

like code above , in python I can run it with scripts or reg a plugin, but I cann't find a reg like code in this example , I learn a little from kbar's tuts and seems it has to be compile to xdl64.file, but I don't know how it can work, e.g.: this example doesn't have a reg or message function to do some thing.

Could you provide a mini example works with c++ work flow, It's a hard to me to move on now 😵

you must use the pluginStart function (usually in main.cpp)

I edited the main.cpp file that you can find in our cinema4dSDK example. Those examples are available in all c4d installation inside the sdk.zip.

You must run the project tool on the directory to generate the project files for xcode or visual studio. You can doznload the project tools here.
Your sdk.zip should compile out of the box if you respect those IDE version.

24a42e87-f6ca-4f75-bab8-00b2bac27682-image.png

Cheers,
Manuel

@m_magalhaes
Hey, It's hard to change python to c++ to me now, I type the code in vs2019, and It is a lot of bugs like :: after has a class namelike this or something like this.
I also check Logerr topic form kbar, And all of it is bit hard to me to approach it, I guess since I can log some text to ohers Logger like Rendererwith maxon.Loggers , It probly can work for me -- Maybe the most dowside is I can not custom the logger name . As bad obsessional it is a little anosing.

Will python can do this or a Logger example for cpp githubin the furture if give a code out of box is not the purpose of the blog?

Sorry to that , I tried since a read this post and I realized I cann't make C++ works for me as soon.😧