1

Py4D Icon Button UI Give Away

Today a client (who himself is a developer) approached to me and told me he needs a user-interface for a dialog which acts like a button but displays a small colored icon besides the text. I told him I’ll make it for free if I may give it away to the community. :)

What’s it?

Below you can find the source code for a user-area that implements a button-like interface, but additionally displays an icon on the left or right side. This icon can be a simple color or a bitmap.

IconButton UA Example

 

Source Code

The following is the source code for the above example. You can copy&paste the IconButton class and the AddIconButton function into your source code. As of version 1.2, the code is released under the WTFPL license, so do what the fuck you want with it!

The buttons act just like normal Cinema 4D buttons. If the user presses the button, you will receive a call to your GeDialog.Command() method with the button’s ID. The IconButton interface supports three different types of icons and four different display modes.

Icon types

The icon is passed as the foruth parameter to AddIconButton()

  • Color constant (eg. c4d.COLOR_TEXTFOCUS)
  • Vector color (eg. c4d.Vector(1.0, 0.66, 0.12'))
  • BaseBitmap instance
Display modes

The display mode is passed as the fifth argument to AddIconButton(). The default value is IconButton.M_ICONLEFT.

  • IconButton.M_NOICON: Display no icon at all, just the text
  • IconButton.M_ICONLEFT: Display the icon on the left-hand side
  • IconButton.M_ICONLEFT: Display the icon on the right-hand side
  • IconButton.M_FULL: Scale the icon to the full size of the button.

IconButton Example 2

Adjustments

You can do any adjustments to the code you like to fit your personal needs. For example, if you want the icon to be of another size, just modify the IconButton.S_ICON value either directly on the IconButton class or on an instance.

Niklas Rosenstein

I am Niklas Rosenstein. 18 years old, student at the LM-University in Munich. I program plugins for Cinema 4D and teach scripting and coding.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *