From e99daaa4694076e3a7d0e51766a7819bde2e5532 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Wed, 31 Dec 2014 12:22:30 -0500 Subject: [PATCH] Added a function to set colors and transparency. --- CadQuery/Helpers.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 CadQuery/Helpers.py diff --git a/CadQuery/Helpers.py b/CadQuery/Helpers.py new file mode 100644 index 0000000..ea66bb2 --- /dev/null +++ b/CadQuery/Helpers.py @@ -0,0 +1,24 @@ +def show(cqObject, rgba=(204, 204, 204, 0.0)): + import FreeCAD + from random import random + + #Convert our rgba values + r = rgba[0] / 255.0 + g = rgba[1] / 255.0 + b = rgba[2] / 255.0 + a = int(rgba[3] * 100.0) + + ad = FreeCAD.activeDocument() + + #Generate a random name for this shape in case we are doing multiple shapes + newName = "Shape" + str(random()) + + #Set up the feature in the tree so we can manipulate its properties + newFeature = ad.addObject("Part::Feature", newName) + + #Change our shape's properties accordingly + newFeature.ViewObject.ShapeColor = (r, g, b) + newFeature.ViewObject.Transparency = a + newFeature.Shape = cqObject.toFreecad() + + ad.recompute()