Created
July 10, 2014 09:15
-
-
Save mlankenau/6e5d5a4c4bbc61b0543c to your computer and use it in GitHub Desktop.
FreeCAD create airfoil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division # allows floating point division from integers | |
import FreeCAD, Part, math | |
from FreeCAD import Base | |
class ProfileShape: | |
def __init__(self, obj): | |
''' Add the properties: Radius, Eccentricity, Height, Segments (see Property View) ''' | |
obj.addProperty("App::PropertyLength","Length","Airfoil","Forward pos").Length=100.0 | |
obj.addProperty("App::PropertyFloat","XPos","Airfoil","Sideways pos").XPos=0.0 | |
obj.addProperty("App::PropertyFloat","YPos","Airfoil","Forward pos").YPos=0.0 | |
obj.Proxy = self | |
def onChanged(self, fp, prop): | |
App.Console.PrintMessage("Hallo from onChange :)") | |
#if prop == "YPosStart" or prop == "YPosEnd" or prop == "XPos": #if one of these is changed | |
# self.execute(fp) | |
def execute(self, fp): #main part of script | |
length = float(fp.Length) | |
xpos = float(fp.XPos) | |
ypos = float(fp.YPos) | |
points = [ | |
[1.0000000, 0.0000000], | |
[0.9967600, 0.0000100], | |
[0.9870700, 0.0000700], | |
[0.9710100, 0.0003600], | |
[0.9487000, 0.0010800], | |
[0.9204100, 0.0025600], | |
[0.8866700, 0.0051600], | |
[0.8482800, 0.0090300], | |
[0.8060800, 0.0140600], | |
[0.7607600, 0.0200800], | |
[0.7130700, 0.0268800], | |
[0.6637700, 0.0342000], | |
[0.6135500, 0.0416300], | |
[0.5629600, 0.0487700], | |
[0.5124700, 0.0552900], | |
[0.4625100, 0.0609300], | |
[0.4134600, 0.0654600], | |
[0.3657600, 0.0687300], | |
[0.3196900, 0.0706300], | |
[0.2756000, 0.0711300], | |
[0.2338300, 0.0702300], | |
[0.1947300, 0.0679900], | |
[0.1586000, 0.0644500], | |
[0.1257300, 0.0596800], | |
[0.0963700, 0.0537700], | |
[0.0707100, 0.0468800], | |
[0.0488900, 0.0391500], | |
[0.0310200, 0.0308100], | |
[0.0171800, 0.0221400], | |
[0.0073900, 0.0134800], | |
[0.0016700, 0.0053300], | |
[0.0001500, -0.0014000], | |
[0.0042400, -0.0065000], | |
[0.0145600, -0.0108400], | |
[0.0302800, -0.0147100], | |
[0.0512300, -0.0180400], | |
[0.0771800, -0.0208200], | |
[0.1078500, -0.0230600], | |
[0.1429100, -0.0248100], | |
[0.1819400, -0.0260900], | |
[0.2244800, -0.0268800], | |
[0.2700800, -0.0271500], | |
[0.3182900, -0.0269100], | |
[0.3686400, -0.0262300], | |
[0.4205500, -0.0251700], | |
[0.4734500, -0.0238100], | |
[0.5267500, -0.0221900], | |
[0.5798300, -0.0203900], | |
[0.6320900, -0.0184600], | |
[0.6829200, -0.0164500], | |
[0.7317300, -0.0144300], | |
[0.7779200, -0.0124300], | |
[0.8209500, -0.0104900], | |
[0.8603000, -0.0086500], | |
[0.8954700, -0.0069100], | |
[0.9260300, -0.0052700], | |
[0.9516300, -0.0036700], | |
[0.9721100, -0.0021200], | |
[0.9873000, -0.0008800], | |
[0.9967800, -0.0001900], | |
[1.0000000, 0.0000000] | |
] | |
last = None | |
wire = None | |
lines = [] | |
for p in points: | |
if last: | |
line = Part.makeLine((xpos,ypos-length*p[0],length*p[1]),(xpos,ypos-length*last[0],length*last[1])) | |
lines.append(line) | |
last = p | |
wire = Part.Wire(lines) | |
fp.Shape = wire #result shape | |
def makeProfileShape(): | |
doc = FreeCAD.activeDocument() | |
if doc == None: | |
doc = FreeCAD.newDocument() | |
profileshape=doc.addObject("Part::FeaturePython","ProfileShape") #add object to document | |
profileshape.Label = "Profile Shape" | |
ProfileShape(profileshape) | |
profileshape.ViewObject.Proxy=0 | |
if __name__ == "__main__": #feature will be generated after macro execution | |
makeProfileShape() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment