Macro Airfoil Import & Scale/de: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
(Updating to match new version of source page)
(36 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
{{Macro/de|Icon=Text-x-python|Name=Macro Airfoil Import & Scale|Description=Trace the perimeter of a Airfoil from a .dat file.|Author=quick61|Version=1.5 , 2.0 and 2.1}}
{{Macro/de

|Name=Macro Airfoil Import & Scale
This Macro, when run, will first provide the user with a file browser to locate and select a .dat airfoil text file. Once selected, a chord length is entered and upon pressing the OK button, a properly scaled airfoil is produced. There are two versions provided here. Version 1.5 should work on FreeCAD versions, 0.13 stable as well as all 0.14 versions. Version 2 should only be used with FreeCAD versions equal to or greater than 0.14 3077 and will work best with versions built with OCE/OCC versions 6.7 or greater.
|Translate=Macro Airfoil Import & Scale
|Icon=Macro_Airfoil_Import_&_Scale.png
|Description=Verfolgen Sie den Umfang eines Airfoil aus einer DAT-Datei.
|Author=quick61
|Version=2.1.2
|Date=2019-07-16
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/0/0c/Macro_Airfoil_Import_%26_Scale.png ToolBar Icon]
}}


==Beschreibung==
See also [[Common_Airfoil_Data_Import|Common Airfoil Data Import]]
Wenn dieses Makro ausgeführt wird, wird es dem Benutzer zunächst mit einem Dateibrowser zur Verfügung gestellt, um eine .dat-Profildatei zu finden und auszuwählen. Nach der Auswahl wird eine Akkordlänge eingegeben und beim Drücken der OK-Taste wird ein ordnungsgemäß skaliertes Strömungsprofil erzeugt. Hier gibt es zwei Versionen. Version 1.5 sollte auf FreeCAD-Versionen funktionieren, 0,13 stabil sowie alle 0,14-Versionen. Version 2 sollte nur mit FreeCAD-Versionen größer oder gleich 0,14 3077 verwendet werden und funktioniert am besten mit Versionen, die mit OCE/OCC-Versionen 6.7 oder höher erstellt wurden.


Siehe auch [[Common_Airfoil_Data_Import|Common Airfoil Data Import]]


[[File:Macro_Airfoil_Import_&_Scale_00.png|480px]]
[[File:Macro_Airfoil_Import_&_Scale_00.png|480px]]
{{clear}}


==How To Use - Version 1.5==
==Wie benutzt man - Version 1.5==


===Select The File===
===Wähle die Datei===
Beim Ausführen des Makros wird dem Benutzer zunächst ein Dateibrowser angezeigt, in dem Sie die gewünschte DAT-Datei auswählen können. Navigieren Sie zu dem Speicherort der Airfoil-Datei, wählen Sie sie aus und drücken Sie Öffnen.
Running the Macro will first present the user with a file browser that will allow you to select the desired airfoil .dat file. Browse to where you have saved the airfoil file, select it and press Open.


[[File:File browser.png|center|File browser window for importing .dat airfoil files]]
[[File:File browser.png|center|File browser window for importing .dat airfoil files]]


===Enter Chord Length===
===Geben Sie die Akkordlänge ein===
Nachdem die Airfoil-Datei ausgewählt wurde, erscheint ein neuer Dialog, in dem Sie nach einer Akkordlänge gefragt werden. Jede Länge kann in Millimetern eingegeben werden. Nachdem Sie die gewünschte Länge eingegeben haben, erzeugt das Makro einen Zugdraht (DWire), der den Punkten entspricht, die in der zuvor ausgewählten .dat-Profildatei auf der für die Akkordlänge eingegebenen Skala angegeben sind.
Once the airfoil file has been selected, a new dialog will appear asking for a chord length. Any length may be entered, in millimeters. Once your desired length is entered, the Macro will produce a Draft Wire (DWire) following the points described in the previously selected .dat airfoil file at the scale you entered for the chord length.


[[File:Chord length.png|center|Chord length dialog for import and scale macro v1.5]]
[[File:Chord length.png|center|Chord length dialog for import and scale macro v1.5]]


The Airfoil, properly scaled, should now be ready for use in your project.
Das Airfoil ist nun richtig skaliert und kann nun in Ihrem Projekt verwendet werden.


==How To Use - Version 2==
==Verwendung - Version 2==
File selection is the same as version 1.5. With version 2 you now have the choice to either have the resulting airfoil made with a Draft Wire (DWire) or a Basic Spline (BSpline). As with version 1.5, you enter the desired chord length. Additionally you can now select which type of foil you want. Simply click on the BSpline radio button or leave as is for for the default DWire.
Die Dateiauswahl entspricht der Version 1.5. Mit Version 2 haben Sie nun die Wahl, entweder das resultierende Profil mit einem Zugseil (DWire) oder einem Basic Spline (BSpline) herstellen zu lassen. Wie bei Version 1.5 geben Sie die gewünschte Akkordlänge ein. Zusätzlich können Sie jetzt auswählen, welchen Folientyp Sie wünschen. Klicken Sie einfach auf das Optionsfeld BSpline oder belassen Sie es wie für das Standard-DWire.


[[File:V2 scale.png|center|Version 2 Airfoil Import and scale dialog with choice of DWire or BSpline]]
[[File:V2 scale.png|center|Version 2 Airfoil Import and scale dialog with choice of DWire or BSpline]]


==Makros==
===Editing The Default Selection===
If you primarily wish to have your imported and scaled airfoils made with BSplines rather than DWires, the Marco may be edited to default to the Bspline. This is done by editing the line -


==Neueste Version==
{{ExampleCode|
self.radio1.setChecked(True)
}}


<div class="mw-translate-fuzzy">
- and changing it to -
Die neueste Version des Makros ist zu finden auf [https://github.com/FreeCAD/FreeCAD-macros/blob/master/ObjectCreation/AirfoilImportAndScale.FCMacro AirfoilImportAndScale.FCMacro], aber der einfachste Weg zur Installation dieses Makros ist die Nutzung des [[Std_AddonMgr/de|Addon-Manager]]s.
{{ExampleCode|
</div>
self.radio2.setChecked(True)


===Version 2.1.2===

ToolBar icon [[Image:Macro_Airfoil_Import_&_Scale.png]]

'''Macro_Airfoil_Import_&_Scale.FCMacro'''

<!--NOT CHANGE THE <pre> </pre> BALISE CAUSE THE PIPE IN MACRO CODE CUT THE MACRO-->
{{MacroCode|code=
<nowiki>

# This Macro, when run, will first provide the user with a file browser to
# locate and select a .dat airfoil text file. Once selected, a chord length is
# entered and upon pressing the OK button, a properly scaled airfoil is
# produced. There are two versions provided here. Version 1.5 should work on
# FreeCAD versions, 0.13 stable as well as all 0.14 versions. Version 2 should
# only be used with FreeCAD versions equal to or greater than 0.14 3077 and
# will work best with versions built with OCE/OCC versions 6.7 or greater (See
# the Wiki page for all available version).
#
# (c) quick61

__Name__ = 'Airfoil Import and Scale'
__Comment__ = 'Imports and scales an Airfoil in the form of a Draft Wire (DWire) or Basic Spline (BSpline)'
__Author__ = "quick61"
__Version__ = '2.1.2'
__Date__ = '2019-07-16'
__License__ = ''
__Web__ = "http://forum.freecadweb.org/viewtopic.php?f=22&t=5554"
__Wiki__ = "http://www.freecadweb.org/wiki/Macro_Airfoil_Import_%26_Scale"
__Icon__ = 'https://www.freecadweb.org/wiki/images/0/0c/Macro_Airfoil_Import_%26_Scale.png'
__Help__ = ''
__Status__ = 'stable'
__Requires__ = 'Freecad >= 0.14.3706'
__Communication__ = ''
__Files__ = ''


import FreeCAD as app
import PySide
from PySide import QtCore, QtGui
from PySide.QtGui import QLineEdit, QRadioButton
import Draft
import importAirfoilDAT


# Select .dat airfoil data file to be imported

# PySide returns a tuple (filename, filter) instead of just a string like in PyQt

global filename
global nameFile

try:
filename, filefilter = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(), 'Open An Airfoil File', '*.dat')
except Exception:
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
path = param.GetString("MacroPath","") + "/" # macro path
filename, filefilter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Open An Airfoil File", path, "*.dat")

nameFile = filename.split("/")[-1][:-4]

class AirfoilImporterAndScaler():
def __init__(self):
self.dialog = None
self.s1 = None

# Make dialog box and get the scale size
self.dialog = QtGui.QDialog()
self.dialog.resize(350,100)
self.dialog.setWindowTitle("Airfoil Import & Scale")
la = QtGui.QVBoxLayout(self.dialog)
t1 = QtGui.QLabel("Chord Length")
la.addWidget(t1)
self.s1 = QtGui.QLineEdit()
la.addWidget(self.s1)

# Add radio buttons to select between DWire and BSpline
self.radio1 = QtGui.QRadioButton("Make DWire")
self.radio2 = QtGui.QRadioButton("Make BSpline")

# set default to DWire & make radio buttons - Change self.radio1.setChecked(True) to
# self.radio2.setChecked(True) to set BSpline as default

self.radio1.setChecked(True)
la.addWidget(self.radio1)
la.addWidget(self.radio2)

# Add OK / Cancel buttons
okbox = QtGui.QDialogButtonBox(self.dialog)
okbox.setOrientation(QtCore.Qt.Horizontal)
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
la.addWidget(okbox)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.proceed)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
QtCore.QMetaObject.connectSlotsByName(self.dialog)
self.dialog.show()
self.dialog.exec_()



def proceed(self):
global filename
global nameFile

if self.radio1.isChecked():
try:
# This produces a scaled Airfoil with a DWire
scalefactor=float(self.s1.text())
f1=str(filename)
importAirfoilDAT.insert(f1,"Unnamed")
try:
Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
except Exception:
Draft.scale(App.ActiveDocument.ActiveObject,scale=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0.0,0.0,0.0),copy=False)
App.ActiveDocument.ActiveObject.Label = nameFile + "_(DWire)"

except Exception as e:
app.Console.PrintError("Error, not a valid .dat file\n")

if self.radio2.isChecked():
try:
# This produces a scaled Airfoil with a BSpline
scalefactor=float(self.s1.text())
f1=str(filename)
importAirfoilDAT.insert(f1,"Unnamed")
points = app.ActiveDocument.ActiveObject.Points
App.getDocument("Unnamed").removeObject(App.ActiveDocument.ActiveObject.Name)
Draft.makeBSpline(points, closed=True)
try:
Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
except Exception:
for i in range(len(points)):
Draft.scaleVertex(App.ActiveDocument.ActiveObject, i, App.Vector(scalefactor,scalefactor,scalefactor), App.Vector(0.0,0.0,0.0))

App.ActiveDocument.ActiveObject.Label = nameFile + "_(BSpline)"

except:
app.Console.PrintError("Error, not a valid .dat file\n")

try:
# delete the directory created by importAirfoilDAT
for obj in App.ActiveDocument.Objects:
if (obj.TypeId == "App::DocumentObjectGroup") and (obj.Name == nameFile):
App.getDocument("Unnamed").removeObject(nameFile)
except Exception:
None

self.close() # close the window

def close(self):
self.dialog.hide()


AirfoilImporterAndScaler()

</nowiki>
}}
}}
A note on this is included within the text of the macro.


==The Macros==


===Version 1.5===
===Version 1.5===

{{Code|code=
'''Macro_Airfoil_Import_&_Scale.FCMacro'''

{{MacroCode|code=
# # # #
# # # #
#
#
Line 124: Line 291:


}}
}}
===Version 2===


==Bearbeiten der Standardauswahl==
{{VeryImportantMessage|'''Warning - Using this Macro with versions of FreeCAD lesser than 0.14, revision 3077 will not produce the expected results when using the BSpline option and can result in FreeCAD crashing and loss of unsaved data!'''}}
Wenn Sie vor allem möchten, dass Ihre importierten und skalierten Tragflächen mit BSplines anstatt mit DWires erstellt werden, kann der Marco so bearbeitet werden, dass er standardmäßig auf Bspline gesetzt wird. Dies geschieht durch Editieren der Zeile -
<pre>
{{ExampleCode|example=
self.radio1.setChecked(True)
}}<br />
- und ändern Sie es in - <br />
{{ExampleCode|example=
self.radio2.setChecked(True)
}}<br />
Ein Hinweis dazu ist im Text des Makros enthalten.

==Version 2== <!--T:15-->

{{VeryImportantMessage|'''Warning - Bei Verwendung dieses Makros mit weniger als 0.14-Versionen von FreeCAD liefert die Version 3077 bei Verwendung der Option BSpline nicht die erwarteten Ergebnisse. Dies kann zum Absturz von FreeCAD und zum Verlust nicht gespeicherter Daten führen
!'''}}
{{MacroCode|code=
<nowiki>
# # # #
# # # #
#
#
Line 141: Line 322:




from PyQt4 import QtCore, QtGui
from PySide import QtCore, QtGui
from PyQt4.QtGui import QLineEdit, QRadioButton
from PySide.QtGui import QLineEdit, QRadioButton
import FreeCAD, FreeCADGui, Draft
import FreeCAD, FreeCADGui, Draft
import importAirfoilDAT
import importAirfoilDAT
Line 231: Line 412:


p()
p()
</pre>
</nowiki>
}}


===Version 2.1===
===Version 2.1===
Updated by mangtronix to use PySide instead of PyQt (used in older versions of FreeCAD)
Updated by mangtronix to use PySide instead of PyQt (used in older versions of FreeCAD)

<pre>
{{MacroCode|code=
<nowiki>
# # # #
# # # #
#
#
Line 342: Line 526:
p()
p()
</pre>
</nowiki>
}}

==Link==
==Link==


Discussion on [http://forum.freecadweb.org/viewtopic.php?f=22&t=5554&p=45137&hilit=Airfoil#p45137 Forum]
Diskussion über [http://forum.freecadweb.org/viewtopic.php?f=22&t=5554&p=45137&hilit=Airfoil#p45137 Forum]


[http://aerospace.illinois.edu/m-selig/ads/coord_database.html#N UIUC Applied Aerodynamics Group Departement of Aerospace Engineering]
[http://aerospace.illinois.edu/m-selig/ads/coord_database.html#N UIUC Applied Aerodynamics Group Departement of Aerospace Engineering]
<languages/>

Revision as of 19:09, 3 November 2021

Other languages:

Macro Airfoil Import & Scale

Beschreibung
Verfolgen Sie den Umfang eines Airfoil aus einer DAT-Datei.

Versionsmakro : 2.1.2
Datum der letzten Änderung : 2019-07-16
FreeCAD version : All
Herunterladen : ToolBar Icon
Autor: quick61
Autor
quick61
Herunterladen
ToolBar Icon
Links
Macro-Version
2.1.2
Datum der letzten Änderung
2019-07-16
FreeCAD-Version(s)
All
Standardverknüpfung
None
Siehe auch
None

Beschreibung

Wenn dieses Makro ausgeführt wird, wird es dem Benutzer zunächst mit einem Dateibrowser zur Verfügung gestellt, um eine .dat-Profildatei zu finden und auszuwählen. Nach der Auswahl wird eine Akkordlänge eingegeben und beim Drücken der OK-Taste wird ein ordnungsgemäß skaliertes Strömungsprofil erzeugt. Hier gibt es zwei Versionen. Version 1.5 sollte auf FreeCAD-Versionen funktionieren, 0,13 stabil sowie alle 0,14-Versionen. Version 2 sollte nur mit FreeCAD-Versionen größer oder gleich 0,14 3077 verwendet werden und funktioniert am besten mit Versionen, die mit OCE/OCC-Versionen 6.7 oder höher erstellt wurden.

Siehe auch Common Airfoil Data Import

Wie benutzt man - Version 1.5

Wähle die Datei

Beim Ausführen des Makros wird dem Benutzer zunächst ein Dateibrowser angezeigt, in dem Sie die gewünschte DAT-Datei auswählen können. Navigieren Sie zu dem Speicherort der Airfoil-Datei, wählen Sie sie aus und drücken Sie Öffnen.

File browser window for importing .dat airfoil files
File browser window for importing .dat airfoil files

Geben Sie die Akkordlänge ein

Nachdem die Airfoil-Datei ausgewählt wurde, erscheint ein neuer Dialog, in dem Sie nach einer Akkordlänge gefragt werden. Jede Länge kann in Millimetern eingegeben werden. Nachdem Sie die gewünschte Länge eingegeben haben, erzeugt das Makro einen Zugdraht (DWire), der den Punkten entspricht, die in der zuvor ausgewählten .dat-Profildatei auf der für die Akkordlänge eingegebenen Skala angegeben sind.

Chord length dialog for import and scale macro v1.5
Chord length dialog for import and scale macro v1.5

Das Airfoil ist nun richtig skaliert und kann nun in Ihrem Projekt verwendet werden.

Verwendung - Version 2

Die Dateiauswahl entspricht der Version 1.5. Mit Version 2 haben Sie nun die Wahl, entweder das resultierende Profil mit einem Zugseil (DWire) oder einem Basic Spline (BSpline) herstellen zu lassen. Wie bei Version 1.5 geben Sie die gewünschte Akkordlänge ein. Zusätzlich können Sie jetzt auswählen, welchen Folientyp Sie wünschen. Klicken Sie einfach auf das Optionsfeld BSpline oder belassen Sie es wie für das Standard-DWire.

Version 2 Airfoil Import and scale dialog with choice of DWire or BSpline
Version 2 Airfoil Import and scale dialog with choice of DWire or BSpline

Makros

Neueste Version

Die neueste Version des Makros ist zu finden auf AirfoilImportAndScale.FCMacro, aber der einfachste Weg zur Installation dieses Makros ist die Nutzung des Addon-Managers.


Version 2.1.2

ToolBar icon

Macro_Airfoil_Import_&_Scale.FCMacro


# This Macro, when run, will first provide the user with a file browser to
# locate and select a .dat airfoil text file. Once selected, a chord length is
# entered and upon pressing the OK button, a properly scaled airfoil is
# produced. There are two versions provided here. Version 1.5 should work on
# FreeCAD versions, 0.13 stable as well as all 0.14 versions. Version 2 should
# only be used with FreeCAD versions equal to or greater than 0.14 3077 and
# will work best with versions built with OCE/OCC versions 6.7 or greater (See
# the Wiki page for all available version).
#
# (c) quick61

__Name__ = 'Airfoil Import and Scale'
__Comment__ = 'Imports and scales an Airfoil in the form of a Draft Wire (DWire) or Basic Spline (BSpline)'
__Author__ = "quick61"
__Version__ = '2.1.2'
__Date__ = '2019-07-16'
__License__ = ''
__Web__ = "http://forum.freecadweb.org/viewtopic.php?f=22&t=5554"
__Wiki__ = "http://www.freecadweb.org/wiki/Macro_Airfoil_Import_%26_Scale"
__Icon__ = 'https://www.freecadweb.org/wiki/images/0/0c/Macro_Airfoil_Import_%26_Scale.png'
__Help__ = ''
__Status__ = 'stable'
__Requires__ = 'Freecad >= 0.14.3706'
__Communication__ = ''
__Files__ = ''


import FreeCAD as app
import PySide
from PySide import QtCore, QtGui
from PySide.QtGui import QLineEdit, QRadioButton
import Draft
import importAirfoilDAT


# Select .dat airfoil data file to be imported

# PySide returns a tuple (filename, filter) instead of just a string like in PyQt

global filename
global nameFile

try:
    filename, filefilter = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(), 'Open An Airfoil File', '*.dat')
except Exception:
    param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
    path = param.GetString("MacroPath","") + "/"                        # macro path
    filename, filefilter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Open An Airfoil File", path, "*.dat")

nameFile = filename.split("/")[-1][:-4]

class AirfoilImporterAndScaler():
    def __init__(self):
        self.dialog = None
        self.s1 = None

        # Make dialog box and get the scale size
        self.dialog = QtGui.QDialog()
        self.dialog.resize(350,100)
        self.dialog.setWindowTitle("Airfoil Import & Scale")
        la = QtGui.QVBoxLayout(self.dialog)
        t1 = QtGui.QLabel("Chord Length")
        la.addWidget(t1)
        self.s1 = QtGui.QLineEdit()
        la.addWidget(self.s1)

        # Add radio buttons to select between DWire and BSpline
        self.radio1 = QtGui.QRadioButton("Make DWire")
        self.radio2 = QtGui.QRadioButton("Make BSpline")

        # set default to DWire & make radio buttons - Change self.radio1.setChecked(True) to
        # self.radio2.setChecked(True) to set BSpline as default

        self.radio1.setChecked(True)
        la.addWidget(self.radio1)
        la.addWidget(self.radio2)

        # Add OK / Cancel buttons
        okbox = QtGui.QDialogButtonBox(self.dialog)
        okbox.setOrientation(QtCore.Qt.Horizontal)
        okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        la.addWidget(okbox)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.proceed)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
        self.dialog.show()
        self.dialog.exec_()



    def proceed(self):
        global filename
        global nameFile

        if self.radio1.isChecked():
            try:
                # This produces a scaled Airfoil with a DWire
                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                try:
                    Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
                except Exception:
                    Draft.scale(App.ActiveDocument.ActiveObject,scale=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0.0,0.0,0.0),copy=False)
                
                App.ActiveDocument.ActiveObject.Label = nameFile + "_(DWire)"

            except Exception as e:
                app.Console.PrintError("Error, not a valid .dat file\n")

        if self.radio2.isChecked():
            try:
                # This produces a scaled Airfoil with a BSpline
                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                points = app.ActiveDocument.ActiveObject.Points
                App.getDocument("Unnamed").removeObject(App.ActiveDocument.ActiveObject.Name)
                Draft.makeBSpline(points, closed=True)
                try:
                    Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
                except Exception:
                    for i in range(len(points)):
                        Draft.scaleVertex(App.ActiveDocument.ActiveObject, i, App.Vector(scalefactor,scalefactor,scalefactor), App.Vector(0.0,0.0,0.0))

                App.ActiveDocument.ActiveObject.Label = nameFile + "_(BSpline)"

            except:
                app.Console.PrintError("Error, not a valid .dat file\n")

        try:    
            # delete the directory created by importAirfoilDAT
            for obj in App.ActiveDocument.Objects:
                if (obj.TypeId == "App::DocumentObjectGroup") and (obj.Name == nameFile):
                    App.getDocument("Unnamed").removeObject(nameFile)
        except Exception:
            None

        self.close()    # close the window

    def close(self):
        self.dialog.hide()


AirfoilImporterAndScaler()


Version 1.5

Macro_Airfoil_Import_&_Scale.FCMacro

# # # #
#
# AIRFOIL IMPORT & SCALE v1.5
# 
# Imports and scales an Airfoil in the form of a Draft Wire (DWire) 
#
# # # #


from PySide import QtCore, QtGui
from PySide.QtGui import QLineEdit
import FreeCAD, FreeCADGui, Draft
import importAirfoilDAT

# Select .dat airfoil data file to be imported

filename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open An Airfoil File','*.dat')

class p():

    def proceed(self):
            try:
                
                # This produces a scaled Airfoil with a DWire

                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
            
            except:
                FreeCAD.Console.PrintError("Error, not a valid .dat file\n")

            self.close()

    def close(self):
        self.dialog.hide()

    def __init__(self):
        self.dialog = None
        self.s1 = None

        # Make dialog box and get the scale size

        self.dialog = QtGui.QDialog()
        self.dialog.resize(350,100)
        self.dialog.setWindowTitle("Airfoil Import & Scale")
        la = QtGui.QVBoxLayout(self.dialog)
        t1 = QtGui.QLabel("Chord Length")
        la.addWidget(t1)
        self.s1 = QtGui.QLineEdit()
        la.addWidget(self.s1)

        # Add OK / Cancel buttons

#ori        okbox = QtGui.QDialogButtonBox(self.dialog)
#ori        okbox.setOrientation(QtCore.Qt.Horizontal)
#ori        okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel -PIPE- QtGui.QDialogButtonBox.Ok)
#        modify original code for install with addon-install cause -PIPE- 05-12-2016 FC 0.16

        okbox = QtGui.QDialogButtonBox(self.dialog)
        okbox.setOrientation(QtCore.Qt.Horizontal)
        okbox.setStandardButtons(QtGui.QDialogButtonBox.Ok)

        cancelbox = QtGui.QDialogButtonBox(self.dialog)
        cancelbox.setOrientation(QtCore.Qt.Horizontal)
        cancelbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel)
        cancelbox.move(0,62)

        la.addWidget(okbox)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.proceed)
        QtCore.QObject.connect(cancelbox, QtCore.SIGNAL("rejected()"), self.close)
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
        self.dialog.show()
        self.dialog.exec_()

p()

Bearbeiten der Standardauswahl

Wenn Sie vor allem möchten, dass Ihre importierten und skalierten Tragflächen mit BSplines anstatt mit DWires erstellt werden, kann der Marco so bearbeitet werden, dass er standardmäßig auf Bspline gesetzt wird. Dies geschieht durch Editieren der Zeile -

##exampleCode##
self.radio1.setChecked(True) 


- und ändern Sie es in -

##exampleCode##
self.radio2.setChecked(True) 


Ein Hinweis dazu ist im Text des Makros enthalten.

Version 2

Warning - Bei Verwendung dieses Makros mit weniger als 0.14-Versionen von FreeCAD liefert die Version 3077 bei Verwendung der Option BSpline nicht die erwarteten Ergebnisse. Dies kann zum Absturz von FreeCAD und zum Verlust nicht gespeicherter Daten führen !

# # # #
#
# AIRFOIL IMPORT & SCALE v2.
# 
# Imports and scales an Airfoil in the form of a Draft Wire (DWire) or Basic Spline (BSpline)
#
# For FreeCAD Versions = or > 0.14 Revision 3077
#
# Works best with OCC/OCE = or > 6.7
#
# # # #


from PySide import QtCore, QtGui
from PySide.QtGui import QLineEdit, QRadioButton
import FreeCAD, FreeCADGui, Draft
import importAirfoilDAT

# Select .dat airfoil data file to be imported

filename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open An Airfoil File','*.dat')

class p():

    def proceed(self):
        if self.radio1.isChecked():
            try:
                
                # This produces a scaled Airfoil with a DWire

                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
            
            except:
                FreeCAD.Console.PrintError("Error, not a valid .dat file\n")

            self.close()

        if self.radio2.isChecked():
            try:

                # This produces a scaled Airfoil with a BSpline

                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                points = FreeCAD.ActiveDocument.ActiveObject.Points
                Draft.makeBSpline(points, closed=True)
                Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
                App.getDocument("Unnamed").removeObject("DWire")

            except:
                FreeCAD.Console.PrintError("Error, not a valid .dat file\n")

            self.close()

    def close(self):
        self.dialog.hide()


    def __init__(self):
        self.dialog = None
        self.s1 = None


        # Make dialog box and get the scale size

        self.dialog = QtGui.QDialog()
        self.dialog.resize(350,100)
        self.dialog.setWindowTitle("Airfoil Import & Scale")
        la = QtGui.QVBoxLayout(self.dialog)
        t1 = QtGui.QLabel("Chord Length")
        la.addWidget(t1)
        self.s1 = QtGui.QLineEdit()
        la.addWidget(self.s1)

        # Add radio buttons to select between DWire and BSpline

        self.radio1 = QRadioButton("Make DWire")
        self.radio2 = QRadioButton("Make BSpline")

            # set default to DWire & make radio buttons - Change self.radio1.setChecked(True) to
            # self.radio2.setChecked(True) to set BSpline as default

        self.radio1.setChecked(True)
        la.addWidget(self.radio1)
        la.addWidget(self.radio2)

        # Add OK / Cancel buttons

        okbox = QtGui.QDialogButtonBox(self.dialog)
        okbox.setOrientation(QtCore.Qt.Horizontal)
        okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        la.addWidget(okbox)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.proceed)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
        self.dialog.show()
        self.dialog.exec_()

p()

Version 2.1

Updated by mangtronix to use PySide instead of PyQt (used in older versions of FreeCAD)

# # # #
#
# AIRFOIL IMPORT & SCALE v2.1
# 
# Imports and scales an Airfoil in the form of a Draft Wire (DWire) or Basic Spline (BSpline)
#
# For FreeCAD Versions = or > 0.14 Revision 3703
#
# Works best with OCC/OCE = or > 6.7
#
# # # #
 
 
from PySide import QtCore, QtGui
from PySide.QtGui import QLineEdit, QRadioButton
import FreeCAD, FreeCADGui, Draft
import importAirfoilDAT
 
# Select .dat airfoil data file to be imported
 
# PySide returns a tuple (filename, filter) instead of just a string like in PyQt
filename, filefilter = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open An Airfoil File','*.dat')

class p():
 
    def proceed(self):
        global filename
        if self.radio1.isChecked():
            #if True:
            try:
 
                # This produces a scaled Airfoil with a DWire
 
                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
 
            except Exception, e:
                FreeCAD.Console.PrintError("Error, not a valid .dat file\n")
 
            self.close()
 
        if self.radio2.isChecked():
            try:
 
                # This produces a scaled Airfoil with a BSpline
 
                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                points = FreeCAD.ActiveDocument.ActiveObject.Points
                Draft.makeBSpline(points, closed=True)
                Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
                App.getDocument("Unnamed").removeObject("DWire")
 
            except:
                FreeCAD.Console.PrintError("Error, not a valid .dat file\n")
 
            self.close()
 
    def close(self):
        self.dialog.hide()
 
 
    def __init__(self):
        self.dialog = None
        self.s1 = None
 
 
        # Make dialog box and get the scale size
 
        self.dialog = QtGui.QDialog()
        self.dialog.resize(350,100)
        self.dialog.setWindowTitle("Airfoil Import & Scale")
        la = QtGui.QVBoxLayout(self.dialog)
        t1 = QtGui.QLabel("Chord Length")
        la.addWidget(t1)
        self.s1 = QtGui.QLineEdit()
        la.addWidget(self.s1)
 
        # Add radio buttons to select between DWire and BSpline
 
        self.radio1 = QRadioButton("Make DWire")
        self.radio2 = QRadioButton("Make BSpline")
 
            # set default to DWire & make radio buttons - Change self.radio1.setChecked(True) to
            # self.radio2.setChecked(True) to set BSpline as default
 
        self.radio1.setChecked(True)
        la.addWidget(self.radio1)
        la.addWidget(self.radio2)
 
        # Add OK / Cancel buttons
 
        okbox = QtGui.QDialogButtonBox(self.dialog)
        okbox.setOrientation(QtCore.Qt.Horizontal)
        okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        la.addWidget(okbox)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.proceed)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
        self.dialog.show()
        self.dialog.exec_()
 
p()

Link

Diskussion über Forum

UIUC Applied Aerodynamics Group Departement of Aerospace Engineering