Smart PolyChart Cinema 4D Plugin – fun with the UserArea

Smart PolyChart is a simple CommandData plugin which draws a neat bar chart from the polygon counts of all polygon objects in a scene.

You can download it here – the source is documented.

The part for users:

Just drag it into your /Plugins folder and open it from the ‘Plugins’ menu. The ‘Update’ button refreshes the view, a click on a column will select the corresponding object so you can optimize or remove it to lower the scenes polygon count.


The part for coders:

Why another CommandData Plugin? Well, I thought this one might actually be helpful for some users and a great excuse to have a little fun with the UserArea.

The UserArea is a Gadget that allows you to draw bitmaps, lines, etc. onto a canvas – and lets the user interact with them.

Since the previous post completed the little ‘advanced python plugin coding trilogy’ with a CommandData plugin, I don’t have to go into too much detail about the projects structure.

Just a quick note about the ‘worker.py’ – the code in that file just recourses through the documents to find all polygon type objects and return a list of them.
Ii could well have been a part of the ‘maindialog.py’ or the ‘canvas.py’ itself – but same as with the previous plugin, I kept it speparate.

Only a reminder that not everything has to be a class or included within the classes you extend from the Cinema4D API.


If you take a look at the ‘canvas.py’ and already have some 2D-drawing experience, you’ll find it pretty straight forward.

Just remember to set the clipping region to the area of the canvas you currently want to draw in.

Redrawing the whole canvas for every update is a bad practice – at least if you want to frequently update or even animate something.

Due to the nature of the graphic the plugin produces (a bunch of bars most times filling the complete ‘screen’ or workspace), there is little to be gained here by calling SetClippingRegion() – but it’s still used to keep the text elements from overlapping the outlines.

Still, it’s a good habit to look for parts of the canvas you can just leave alone in a following update – clip and re-draw only what needs to be changed.

The source also holds a little example on how to handle mouse events within a UserArea – keep in mind that the mouse coordinates need to be offset by the position of the gadget on the screen.

return

Trying to keep it short this time… – hope you have fun coding!

Leave a Comment

Your email address will not be published.