-
Notifications
You must be signed in to change notification settings - Fork 4
How to Convert a Cinema 4D Script to a CommandData Plugin
Donovan Keith edited this page Mar 1, 2018
·
1 revision
This process should work with any script. For our purposes, we'll create one from scratch.
- In Cinema 4D go to
Script > Script Manager
- In the Script manager go to
File > New
- A new script will appear:
- Add a DocString to the top of the script, and remove the
#Welcome to...
line. - Save the script as
hello-world.py
by choosingFile > Save...
"""Name-US: Hello World
Description-US: Simple plugin that opens a dialog.
"""
-
Name-US
will become your plugin's name by default. -
Description-US
will become your plugin's help text by default.
HelloWorld.py
"""Name-US: Hello World
Description-US: Simple plugin that opens a dialog.
"""
import c4d
from c4d import gui
def main():
gui.MessageDialog('Hello World!')
if __name__=='__main__':
main()
- Open the Script Converter by going to
Plugins > Script Converter
- The Script Converter dialog will open
- The
Script *
pull-down is auto-populated with all of your scripts. Selecthello-world.py
from the list.
- Note that a
Plugin Name
andPlugin Help
have been auto-filled with the info from your DocString.
- Every C4D plugin needs a unique ID, click on the
Get Plugin ID
button. This will take you to Maxon's Developer page. If you're logged in, you should see this. If you aren't, you'll need to log in (and possibly create an account if you don't have one yet.) - Enter
Hello World
as yourWorking Plugin Title
and pressGet Plugin ID
- Double-click on the plugin ID to select it. Copy & Paste it into the
Plugin ID *
field inScript Converter
.
- If you want, you can further customize this plugin by selecting a custom icon or choose to save your plugin somewhere other than your C4D Prefs folder.
-
Press
Create
. Your plugin will be generated and a file browser should open to its location. -
Congratulations, you've successfully converted your plugin! If you restart Cinema 4D, you'll see it in your Plugins pull-down.
-
You can stop here. But we recommend that you...
- Open
hello-world.pyp
and complete the#TODO:
items.
# Copyright (c) <year> <author>
"""Name-US: Hello World
Description-US: Simple plugin that opens a dialog.
"""
# TODO: Remove redundant `if __name__ == '__main__':` check if it was in your script
# TODO: Remove redundant imports
# TODO: Update Copyright information
# TODO: Add a README file
# TODO: Keep in mind that the variables `doc` and `op` are no longer globally available
import c4d
import os
def load_bitmap(path):
path = os.path.join(os.path.dirname(__file__), path)
bmp = c4d.bitmaps.BaseBitmap()
if bmp.InitWith(path)[0] != c4d.IMAGERESULT_OK:
bmp = None
return bmp
import c4d
from c4d import gui
class HelloWorld(c4d.plugins.CommandData):
PLUGIN_ID = 1040748
PLUGIN_NAME = 'Hello World'
PLUGIN_INFO = 0
PLUGIN_ICON = load_bitmap('res/icons/hello-world.tiff')
PLUGIN_HELP = 'Simple plugin that opens a dialog.'
def Register(self):
return c4d.plugins.RegisterCommandPlugin(
self.PLUGIN_ID, self.PLUGIN_NAME, self.PLUGIN_INFO, self.PLUGIN_ICON,
self.PLUGIN_HELP, self)
def Execute(self, doc):
gui.MessageDialog('Hello World!')
return True
if __name__ == '__main__':
HelloWorld().Register()
The file should more-or-less look like this when you're done:
"""Name-US: Hello World
Description-US: Simple plugin that opens a dialog.
Copyright (c) 2018 Donovan Keith
"""
import c4d
from c4d import gui
import os
def load_bitmap(path):
path = os.path.join(os.path.dirname(__file__), path)
bmp = c4d.bitmaps.BaseBitmap()
if bmp.InitWith(path)[0] != c4d.IMAGERESULT_OK:
bmp = None
return bmp
class HelloWorld(c4d.plugins.CommandData):
PLUGIN_ID = 1040748
PLUGIN_NAME = 'Hello World'
PLUGIN_INFO = 0
PLUGIN_ICON = load_bitmap('res/icons/hello-world.tiff')
PLUGIN_HELP = 'Simple plugin that opens a dialog.'
def Register(self):
return c4d.plugins.RegisterCommandPlugin(
self.PLUGIN_ID, self.PLUGIN_NAME, self.PLUGIN_INFO, self.PLUGIN_ICON,
self.PLUGIN_HELP, self)
def Execute(self, doc):
gui.MessageDialog('Hello World!')
return True
if __name__ == '__main__':
HelloWorld().Register()