Hack of the day: add a method to Part.Shape (don't do that!)

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Hack of the day: add a method to Part.Shape (don't do that!)

Post by DeepSOIC »

Hi!
The more I get to know python, the more stupid things I can come up with. Here is one interesting.
Run this:

Code: Select all

def meth(self, arg):
    print self.Area

import gc
gc.get_referents(Part.Shape.__dict__)[0]["meth"] = meth
Now, all Shape objects have the new method meth!

Code: Select all

>>> App.ActiveDocument.Sphere.Shape.meth(5)
314.159265359
I don't have a clear idea on how evil this hack is. So, PLEASE DON"T USE :lol: .
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Hack of the day: add a method to Part.Shape (don't do that!)

Post by triplus »

Functions as first class objects?
Post Reply