Problems with macro Airfoil Import & Scale

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
old-flyer
Posts: 13
Joined: Tue Jan 01, 2019 6:00 pm
Location: Netherlands

Problems with macro Airfoil Import & Scale

Post by old-flyer »

First my sys-info:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15969 (Git)
Build type: Release
Branch: master
Hash: 4765b7e2fe6d3609e9fbf3e3eb6648d7af1dd526
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Dutch/Netherlands (nl_NL)

My problems with this macro are the following:
I've opend FreeCad with a blank project.
1 When executing the macro, I get the following message:
<unknown exception traceback><class 'SyntaxError'>: ('invalid syntax', ('C:/Users/Caistor/AppData/Roaming/FreeCAD/Macro/Airfoil_Import_&_Scale.FCMacro', 40, 29, ' except Exception, e:\n'))

This is easely fixed by inserting ": #" between except and Exception

2 After the fix and trying to run the macro again, I get the following error message:
File "C:/Users/Caistor/AppData/Roaming/FreeCAD/Macro/Airfoil_Import_&_Scale.FCMacro", line 23, in <module>
filename, filefilter = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open An Airfoil File','*.dat')
<class 'AttributeError'>: 'NoneType' object has no attribute 'activeWindow'


And this is where I get stuck.

Is there a solution availble?
The same (2nd) error message appears on my Ubuntu laptop, with the following sys-info:
OS: Ubuntu 18.04.2 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13541 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 9948ee4f1570df9216862a79705afb367b2c6ffb
Python version: 2.7.15rc1
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Dutch/Netherlands (nl_NL)
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Problems with macro Airfoil Import & Scale

Post by Syres »

There appears to be quite a few issues with version 2.1 of this macro to handle the different builds of FreeCAD in use at the moment, so rather than a lot of back and forth I've tested the following on four builds going as far back as approximately July 2017 (0.17) up to a few days ago on both Py2Qt4 and Py3Qt5. Unfortunately all the builds are Windows based so at least one of your boxes should work fine but if you get any issues on other OS then I would look at the path statement line 23 first. Copy and paste the following code into the existing macro or create a new one with a different name:

Code: Select all

# # # #
#
# AIRFOIL IMPORT & SCALE v2.2
# 
# 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

path = FreeCAD.ConfigGet("UserAppData")
# path = 'C:/Data/FreeCAD/Airfoil_DATs'
filename = ""
try:
    filename = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Open An Airfoil File"),path,"*.dat")
except:
    filename, filefilter = QtGui.QFileDialog.getOpenFileName(None, "Open An Airfoil File", path,"*.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:
                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)
                try:
                    App.getDocument("Unnamed").removeObject("Wire")
                except:
                    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):
        if filename == "":
            print('Closing')
        else:
            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()
For future reference you maybe better submitting this kind of post to the Python scripting and macros forum to get a more swift response and probably a better coded solution as well, this isn't my specialist subject.
User avatar
pl7i92LCNC
Posts: 208
Joined: Tue Mar 12, 2019 3:03 pm
Location: RLP DE

Re: Problems with macro Airfoil Import & Scale

Post by pl7i92LCNC »

Hi here is a Standalone Python based Airfoil generator with 2 Shapes
phpBB [video]

it generates Hotwire G-code
old-flyer
Posts: 13
Joined: Tue Jan 01, 2019 6:00 pm
Location: Netherlands

Re: Problems with macro Airfoil Import & Scale

Post by old-flyer »

Thanks, Syres.
I've updated the macro and it is working well now. :D
Regards, Richard
Post Reply