The code generates a shape. This needs to be converted to a solid shape in the Part WB before you can further use it for bool operations. I looked at the code in the console when doing so and tried to copy the same transformations into the macro, but it doesn't do the same thing.
Code: Select all
import FreeCAD, Part, math, Draft
from FreeCAD import Base
class Antenna:
def __init__(self, obj):
''' Add the properties: Radius, Eccentricity, Height, Segments (see Property View) '''
print "Antenna::__init__"
obj.addProperty("App::PropertyLength","Diameter","Antenna","Antenna apreture diameter").Diameter=60.0
obj.addProperty("App::PropertyLength","Height","Antenna","Height of antenna").Height=20.0
#obj.addProperty("App::PropertyLength","Focal","Antenna","Focal distance to antenna base").Focal=30.0
obj.Proxy = self
def onChanged(self, fp, prop):
print "Antenna::onChanged", prop
if prop == "Diameter" or prop == "Height" or prop == "Focal": #if one of these is changed
self.execute(fp)
def execute(self, fp): #main part of script
tu = FreeCAD.Units.parseQuantity
thickness = tu('0.01 mm')
d = fp.Diameter
#f = fp.Focal
h = fp.Height + thickness
a = h / d / d * 4
f = a/a / 4 / a # we use a/a to get it into the right units
print "focal length", f
steps = 100
increment = d / 2 / steps
y = 0.0
for i in range(steps):
x1= i * increment
z1= a * x1 * x1
x2= x1 + increment
z2= a * x2 * x2
seg=Part.makeLine((x1,y,z1),(x2,y,z2))
if i == 0:
wire = Part.Wire([seg])
else:
wire=Part.Wire([wire,seg])
# move wire back to the center
seg= Part.makeLine((x2,y,z2), (0.0, y, z2))
wire = Part.Wire([wire, seg])
shell=wire.revolve(App.Vector(0,0,0),App.Vector(0,0,1),360)
# make a solid
solid=Part.Solid(shell)
solid = solid.Faces
solid = Part.Solid(Part.Shell(solid))
# apply a thickness
thick=solid.makeThickness([solid.Faces],-thickness,0.001)
#create a small cross at the focal point
#c1 = Part.makeLine((-1.0, 0.0,f.Value), (1.0, 0.0, f.Value))
#c2 = Part.makeLine(( 0.0,-1.0,f.Value), (0.0, 1.0, f.Value))
#c3 = Part.makeLine(( 0.0, 0.0,f.Value-1),(0.0, 0.0, f.Value+1))
#cross = Part.makeCompound([c1, c2, c3])
fp.Shape = thick
def makeAntenna():
doc = FreeCAD.activeDocument()
if doc == None:
doc = FreeCAD.newDocument()
antenna = doc.addObject("Part::FeaturePython","Antenna") #add object to document
antenna.Label = "Antenna"
Antenna(antenna)
antenna.ViewObject.Proxy=0
if __name__ == "__main__": #feature will be generated after macro execution
makeAntenna()