home
portfolio
services
notebook
links
This way out

 

 

 

CINEMA 4D, Revision 6

 

COFFEE plugin tutorial
A better dialog

 

(a link will be available for part 8 of this tutorial soon)

coffee tutorial 1:  Introduction
coffee tutorial 2:  Programming basics
coffee tutorial 3:  The nuts and bolts of a plugin
coffee tutorial 4:  Your first dialog box
coffee tutorial 5:  A better dialog box
coffee tutorial 6:  Creating a house object
coffee tutorial 7:  Interactive house modeling
coffee tutorial 8:  International resources

 

For QuickStarters:

* copy and paste the listing text (below) to a simple text editor and save it as a plain text file under the name 'lesson5.cof' into the C4D "plugins" folder.

* restart c4d (or use the menu command "Reload Plugins")

* Open the window "Console"

* execute the plugin-menu command "coffee-lesson-5"

* this time we move nearer to creating a house ;)


The Listing:


const var cPlugName = "coffee-lesson-5";
const var cPlugHelp = "Creates (almost) a house";
const var cS1 = "width";
const var cS2 = "length";
const var cS3 = "height";
const var cS4 = "rooftop";
const var cB1 = "new house";
const var cB2 = "reset";
const var cFMax = 1e3;
enum
{ eSlider=4000,eSlider1,eSlider2,eSlider3,eSlider4,
eBut=1000,eButNew,eButInit
}

const var cPluginID = 2000003;
var gDial;


// --- Create a house object
fMakeHouse()
{ // follows in coffee-lesson-6
}


// --- GeDialog
class oDialog : GeDialog
{ public:
oDialog();
CreateLayout();
Init();
Command(vID,vMSG);

}
oDialog::oDialog() { super(cPluginID); }
oDialog::CreateLayout()
{ SetTitle(cPlugName);
AddGroupBeginV(eSlider,BFH_SCALEFIT,2,"",0);
{ AddStaticText(0,BFH_LEFT,0,0,cS1,0);
AddEditSlider(eSlider1,BFH_SCALEFIT,200,0);
AddStaticText(0,BFH_LEFT,0,0,cS2,0);
AddEditSlider(eSlider2,BFH_SCALEFIT,200,0);
AddStaticText(0,BFH_LEFT,0,0,cS3,0);
AddEditSlider(eSlider3,BFH_SCALEFIT,200,0);
AddStaticText(0,BFH_LEFT,0,0,cS4,0);
AddEditSlider(eSlider4,BFH_SCALEFIT,200,0);
}
AddGroupEnd();
AddGroupBeginV(eBut,BFH_CENTER,2,"",0);
{ AddButton (eButNew ,0,0,0,cB1);
AddButton (eButInit,0,0,0,cB2);
}
AddGroupEnd();
return TRUE;

}
oDialog::Init()
{ SetFloat(eSlider1, 80.0,1,cFMax,1.0);
SetFloat(eSlider2,120.0,1,cFMax,1.0);
SetFloat(eSlider3, 50.0,1,cFMax,1.0);
SetFloat(eSlider4, 30.0,1,cFMax,1.0);
return TRUE;
}
oDialog::Command(vID,vMSG)
{ switch (vID)
{ case eButNew: fMakeHouse(); break;
case eButInit: Init(); break;
}
return TRUE;
}


// --- MenuPlugin
class oMenuPlugin : MenuPlugin
{ public:
oMenuPlugin();
GetID();
GetName();
GetHelp();
Execute(doc);
RestoreLayout(secret);
}
oMenuPlugin::oMenuPlugin() { super(); }
oMenuPlugin::GetID() { return cPluginID; }
oMenuPlugin::GetName() { return cPlugName; }
oMenuPlugin::GetHelp() { return cPlugHelp; }
oMenuPlugin::Execute(doc)
{ if (!gDial) gDial=new(oDialog);
gDial->Open(TRUE,-1,-1);
}
oMenuPlugin::RestoreLayout(secret)
{ if (!gDial) gDial=new(oDialog);
gDial->RestoreLayout(secret);
}
main()
{ Register(oMenuPlugin);
}

 

The Explanation:

In comparison to coffee-lesson-4 there has been added a lot of new stuff.


const, var und enum

There are different ways of programming. Some programmers code out of the blue, others tend to plan every step before typing a single letter. Extracting constants and variables lets you enhance and change your code more easily. For an explanation of constants and variables, please refer to a book on basic programming. The number of published books on this topic is overwhelming.


fMakeHouse()

Doesn't do anything yet. I want you to be able to see the evolution of the plugin step by step. Exaggerated examples just confuse rather than explain anything well.


oDialog::CreateLayout()

The input-element from coffee-lesson-4 has been rewritten and enhanced with a more complex dialogue. It is usual, that the user-interface takes up to 70% of the programming effort. It's always good to spend a significant time on this issue. Nobody likes to use an unfriendly, unusable Plugin.

Without AddGroupBeginV, the following input-fields would be arranged vertically. This group means that 2 fields are positioned together horizontally. The meaning of the parameters like AddEditSlider and AddStaticText can be looked up in the SDK-documentation at www.plugincafe.com. Change the parameters, reload the plugin and watch. Testing is the best teacher.

For a comparison, search the COFFEE SDK at www.plugincafe.com for the COFFEE flag "BFH_CENTER" and test the other flags. It is essential, that you are able to deal with the SDK-documentation. That's a programmer's bible. This is were our 10000 commandments are written down ;-)


oDialog::Init()

The function "Init" has also been added. It ignites the initialisation of the dialog box icon's properties. This function is executed automatically after the dialog box's creation and after "CreateLayout()". The button "reset" (see below) uses this function equally. As always: read the SDK-documentation and test: what could SetPercent or SetColorChooser mean...?


oDialog::Command(vID,vMSG)

After every operation in the dialog box, the function "command" is executed. This function decides if something - and what exactly has to be done. For example, after a click on the "reset" button, (eButInit), the function Init() is executed. Also, after a click on the "new house" button, a new house should be created. fMakeHouse() doesn't do anything... yet...

 

----------------------------------------
Text copyright © H. G. Seib 2000, HTML copyright © M. D. Abbott 2001

 

 


Vantage Graphics and Design Limited
9 Vicarage Lane, Harbury, LEAMINGTON SPA, Warwickshire CV33 9HA, UNITED KINGDOM
Telephone: 01926 614211 Fax: 01926 614226 ISDN: 01926 614210
E-mail: studio@vgd.co.uk

Page last updated: 05 July 2001