############################################################## # Read Laboratori airfoil format type .txt, draw airfoil and show basic count numbers # (total airfoil points, extrados, vernts, intrados) # Reads .txt .dat .pfl airfoil standard files # Use as macro in FreeCAD 0.18.4 # Pere Casellas # LABORATORI D'ENVOL # http://www.laboratoridenvol.com # Version 01: 20200518 ############################################################## from FreeCAD import Base import Draft, Part import os from PyQt5.QtWidgets import QFileDialog #from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog #from PyQt5.QtGui import QIcon cwd = os.getcwd() #print(cwd) #os.chdir(cwd) # Remove all previosus objects def clearAll(): doc = FreeCAD.ActiveDocument for obj in doc.Objects: doc.removeObject(obj.Label) clearAll() # Get airfoil file by dialog def filePath(title): qfd = QFileDialog() path = "cwd" filter = "Airfoils .txt .dat .pfl(*.txt *.dat *.pfl);; All files(*,*)" f = QFileDialog.getOpenFileName(qfd, title, path, filter) return f nomf=filePath("LABORATORI D'ENVOL - Select your airfoil file .txt .dat or .pfl") # Detect file extension nomfile=nomf[0] extensio=nomfile[-3:] # Open file file = open(nomfile,"r") #file = open("/home/pere/.FreeCAD/Macro/gnua.txt","r") ################################################### # Detect .txt case (case 1 = Laboratori extended format, case 2 =standard) ################################################### nom_perfil = file.readline() Line1 = file.readline() nl1=len(Line1.split()) # nl1= 1 > case Laboratori # nl1=2 > case standard ################################################### # Case 1: txt file Laboratori using extended format ################################################### if extensio == "txt" and nl1 == 1: file.seek(0) nom_perfil = file.readline() npunts1 = file.readline() npunts2 = file.readline() npunts3 = file.readline() npunts4 = file.readline() npunts5 = int(npunts2)+int(npunts3)-1 wire = [] X=Y=Z = 0.0 # Read and draw extrados for i in range(1,int(npunts2)+1): point = file.readline() coordinates = point.split() X,Y= coordinates wire.append(FreeCAD.Vector(float(X),float(Y),float(Z))) # append the coordinates Draft.makeWire(wire,closed=False,face=False,support=None) # create the wire open FreeCADGui.ActiveDocument.getObject("Wire").LineColor = (1.000,0.000,0.000) xn4 = float(X[:int(npunts2)]) yn4 = float(Y[:int(npunts2)]) #print(xn4,yn4) # Read and draw vents file.seek(0) for i in range(1,5+int(npunts2)): point = file.readline() for i in range(1,int(npunts3)+1): point = file.readline() coordinates = point.split() X,Y= coordinates wire.append(FreeCAD.Vector(float(X),float(Y),float(Z))) # append the coordinates Draft.makeWire(wire,closed=False,face=False,support=None) # create the wire open FreeCADGui.ActiveDocument.getObject("Wire001").LineColor = (1.000,1.000,0.000) xn5 = float(X[:int(npunts3)]) yn5 = float(Y[:int(npunts3)]) #print(xn5,yn5) # Read and draw intrados file.seek(0) for i in range(1,5+int(npunts2)+int(npunts3)-1): point = file.readline() for i in range(1,int(npunts4)+1): point = file.readline() coordinates = point.split() X,Y= coordinates wire.append(FreeCAD.Vector(float(X),float(Y),float(Z))) # append the coordinates Draft.makeWire(wire,closed=False,face=False,support=None) # create the wire open FreeCADGui.ActiveDocument.getObject("Wire002").LineColor = (0.000,1.000,0.000) # Print text notes text0="Airfoil: "+nom_perfil text = Draft.makeText([text0],point=FreeCAD.Vector(0.0,0.28,0.0)) FreeCADGui.ActiveDocument.getObject("Text").FontSize = '0.02 mm' text1="Total points: "+str(npunts1) text = Draft.makeText([text1],point=FreeCAD.Vector(0.0,0.25,0.0)) FreeCADGui.ActiveDocument.getObject("Text001").FontSize = '0.02 mm' text2="Extrados points: "+str(npunts2)+" (from "+str(1)+" to "+str(npunts2)+")" text = Draft.makeText([text2],point=FreeCAD.Vector(0.0,0.22,0.0)) FreeCADGui.ActiveDocument.getObject("Text002").FontSize = '0.02 mm' text3="Vents points: "+str(npunts3)+" (from "+str(npunts2)+" to "+str(npunts5)+")" text = Draft.makeText([text3],point=FreeCAD.Vector(0.0,0.19,0.0)) FreeCADGui.ActiveDocument.getObject("Text003").FontSize = '0.02 mm' text4="Intrados points: "+str(npunts4)+" (from "+str(npunts5)+" to "+str(npunts1)+")" text = Draft.makeText([text4],point=FreeCAD.Vector(0.0,0.16,0.0)) FreeCADGui.ActiveDocument.getObject("Text004").FontSize = '0.02 mm' # Points notes text = Draft.makeText([str(1)],point=FreeCAD.Vector(1.0,0.01,0.0)) FreeCADGui.ActiveDocument.getObject("Text005").FontSize = '0.012 mm' text = Draft.makeText([str(npunts2)],point=FreeCAD.Vector(xn4-0.015,yn4-0.015,0.0)) FreeCADGui.ActiveDocument.getObject("Text006").FontSize = '0.012 mm' vinit=str(float(xn4*100))+"%" text = Draft.makeText([vinit],point=FreeCAD.Vector(xn4-0.015,yn4-0.015-0.015,0.0)) FreeCADGui.ActiveDocument.getObject("Text007").FontSize = '0.012 mm' FreeCADGui.ActiveDocument.getObject("Text007").TextColor = (0.333,0.000,1.000) text = Draft.makeText([str(npunts5)],point=FreeCAD.Vector(xn5-0.01,yn5-0.015,0.0)) FreeCADGui.ActiveDocument.getObject("Text008").FontSize = '0.012 mm' vfini=str(float(xn5*100))+"%" text = Draft.makeText([vfini],point=FreeCAD.Vector(xn5-0.01,yn5-0.015-0.015,0.0)) FreeCADGui.ActiveDocument.getObject("Text009").FontSize = '0.012 mm' FreeCADGui.ActiveDocument.getObject("Text009").TextColor = (0.333,0.000,1.000) text = Draft.makeText([str(npunts1)],point=FreeCAD.Vector(1.0,-0.015,0.0)) FreeCADGui.ActiveDocument.getObject("Text010").FontSize = '0.012 mm' Draft.autogroup(text) ################################################### # Case 2: Read standard format .txt .dat .pfl ################################################### if (extensio == "txt" and nl1 == 2) or extensio == "dat" or extensio == "pfl": nol = len(open(nomfile).readlines( )) npunts1=nol-1 file.seek(0) nom_perfil = file.readline() wire = [] X=Y=Z = 0.0 # Read and draw points for i in range(1,nol): point = file.readline() coordinates = point.split() X,Y= coordinates wire.append(FreeCAD.Vector(float(X),float(Y),float(Z))) # append the coordinates Draft.makeWire(wire,closed=False,face=False,support=None) # create the wire open FreeCADGui.ActiveDocument.getObject("Wire").LineColor = (1.000,0.000,0.000) # Print text notes text0="Airfoil: "+nom_perfil text = Draft.makeText([text0],point=FreeCAD.Vector(0.0,0.28,0.0)) FreeCADGui.ActiveDocument.getObject("Text").FontSize = '0.02 mm' text1="Total points: "+str(npunts1) text = Draft.makeText([text1],point=FreeCAD.Vector(0.0,0.25,0.0)) FreeCADGui.ActiveDocument.getObject("Text001").FontSize = '0.02 mm' # Parameters view Gui.ActiveDocument.ActiveView.setAxisCross(True) Gui.ActiveDocument().activeView().viewTop() Gui.SendMsgToActiveView("ViewFit") App.ActiveDocument.recompute() # Export airfoil to DXF __objs__=[] def selectAll(): doc = FreeCAD.ActiveDocument for obj in doc.Objects: __objs__.append(doc.getObject(obj.Label)) selectAll() #import importDXF #importDXF.export(__objs__,u"/home/pere/.FreeCAD/Macro/salvat.dxf") del __objs__ file.close()