THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/09/2007 at 11:29, xxxxxxxx wrote:
The project that comes with C4D (in cinema4Dsdk) is sufficient as a template for building your own C++ projects. Actually, it is the recommended way to do so.
In the C++ SDK there is a MergeDocument() method. In what format are the 'parts' that you have ready for import?
The best way to do this is to make a Command plugin (a plugin that is run from the Plugins menu). If this is a one-time thing, you could hard code the path to all of the parts but it might be better to open a file dialog to point to the folder from which to start.
The problem with a source example is that there is a lot of infrastructure needed around the plugin besides the merging part. You'll need a Main.cpp with PluginStart, PluginEnd, and PluginMessage. Here's a skeletal Main.cpp:
Bool RegisterMyCmdPlugin();
//*---------------------------------------------------------------------------*
Bool PluginStart()
//*---------------------------------------------------------------------------*
{
GePrint("Starting My Plugin");
// register plugin and return
return RegisterMyCmdPlugin();
}
//*---------------------------------------------------------------------------*
void PluginEnd()
//*---------------------------------------------------------------------------*
{
}
//*---------------------------------------------------------------------------*
Bool PluginMessage(LONG id, void* data)
//*---------------------------------------------------------------------------*
{
if (id == C4DPL_INIT_SYS)
{
// initialize global resource object
if (!resource.Init()) return FALSE;
}
else if (id == C4DPL_ENDACTIVITY)
{
return TRUE;
}
else if (id == C4DMSG_PRIORITY) return TRUE;
return FALSE;
}
Then you'll need to derive a class from the CommandData like this:
Header:
////////////////////////////////////////////////////////////////
// MyCmdPlugin.h
////////////////////////////////////////////////////////////////
// Main Registered Class
////////////////////////////////////////////////////////////////
#ifndef _MYCMDPLUGIN_H_
#define _MYCMDPLUGIN_H_
class MyDialog;
// CLASS: MyCmdPlugin
class MyCmdPlugin : public CommandData
{
INSTANCEOF(MyCmdPlugin, CommandData)
private:
GeDialog* myDialog;
public:
MyCmdPlugin();
~MyCmdPlugin();
// CommandData
Bool Execute(BaseDocument* doc);
LONG GetState(BaseDocument* doc);
Bool RestoreLayout(void* secret);
};
#endif //_MYCMDPLUGIN_H_
Source:
////////////////////////////////////////////////////////////////
// MyCmdPlugin.cpp
////////////////////////////////////////////////////////////////
// Includes
#include "c4d.h"
#include "c4d_symbols.h"
#include "MyDialog.h"
#include "MyCmdPlugin.h"
// METHODS: MyCmdPlugin ==================================================================================================
// Constructor
//*---------------------------------------------------------------------------*
MyCmdPlugin::MyCmdPlugin()
//*---------------------------------------------------------------------------*
{
myDialog = NULL;
}
// Destructor
//*---------------------------------------------------------------------------*
MyCmdPlugin::~MyCmdPlugin()
//*---------------------------------------------------------------------------*
{
gDelete(myDialog);
}
// CommandData.Execute
//*---------------------------------------------------------------------------*
Bool MyCmdPlugin::Execute(BaseDocument* doc)
//*---------------------------------------------------------------------------*
{
if (!myDialog)
{
myDialog = gNew MyDialog;
if (!myDialog) return FALSE;
}
if (myDialog->IsOpen()) return TRUE;
return myDialog->Open(TRUE,ID_MYCMDPLUGIN,-1,-1,320,320,ID_MYDIALOG);
}
// CommandData.GetState
//*---------------------------------------------------------------------------*
LONG MyCmdPlugin::GetState(BaseDocument* doc)
//*---------------------------------------------------------------------------*
{
return CMD_ENABLED;
}
// CommandData.RestoreLayout
//*---------------------------------------------------------------------------*
Bool MyCmdPlugin::RestoreLayout(void* secret)
//*---------------------------------------------------------------------------*
{
if (!myDialog)
{
myDialog = gNew MyDialog;
if (!myDialog) return FALSE;
}
return myDialog>RestoreLayout(ID_MYCMDPLUGIN, ID_MYDIALOG, secret);
}
// Global Registrant Method for My Command plugin
//*---------------------------------------------------------------------------*
Bool RegisterMyCmdPlugin()
//*---------------------------------------------------------------------------*
{
return RegisterCommandPlugin(ID_MYCMDPLUGIN, GeLoadString(MY_PLUGIN_NAME), 0, "pluginicon.tif", "My Cmd Plugin", gNew MyCmdPlugin);
}
If you are going to need a dialog for any user input, you'll need to derive a class from GeDialog (MyDialog mentioned here). Use the GeDialog::Command method to get a button click for "OK" or similar to start the process. If you are just going for it with no dialog, you could have the process of merging and setting up work from the MyCmdPlugin::Execute method.
As for the process itself, you'll probably need a BrowseFiles class to traverse the folder and start loading the files. First get the current document:
BaseDocument* doc = GetActiveDocument();
if (!doc) return FALSE;
AutoAlloc<BrowseFiles> browse;
if (!browse) return FALSE;
StopAllThreads(); // Required when modifying a scene
// traverse files/folders in folder using the specified loop structure for BrowseFiles
if (!MergeDocument(doc, filename, flags, NULL)) continue;
etc.