Error with Macro Texture_Objects.FCMacro

Need help, or want to share a macro? Post here!
joel
Posts: 175
Joined: Thu Jan 26, 2017 8:17 pm
Location: Thonon les Bains

Error with Macro Texture_Objects.FCMacro

Postby joel » Tue Feb 12, 2019 6:08 pm

An error occurs with the Macro Texture_Objects.FCMacro:

File "/home/joel/.FreeCAD/Macro/Texture_Objects.FCMacro", line 6, in <module>
jpgfilename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open image file','*.jpg')
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'activeWindow'

This error occurs with 0.18 and 0.17 not with 0.17 or 0.16 .Appimage

The difference: Qt version 5.9.5 and 4.8.6
Should we change the line 6?

OS: Ubuntu 18.04.2 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15816 (Git)
Build type: Release
Branch: master
Hash: 7ee0e4d43909ec688299b8498b240cccf8362c47
Python version: 2.7.15rc1
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: French/France (fr_FR)
joel
Posts: 175
Joined: Thu Jan 26, 2017 8:17 pm
Location: Thonon les Bains

Re: Error with Macro Texture_Objects.FCMacro

Postby joel » Mon Feb 18, 2019 8:36 am

I modified the macro as well:

import FreeCADGui
import sys
from PySide import QtGui
from pivy import coin
from PySide2.QtWidgets import QApplication, QDialog, QLineEdit, QPushButton

class Form(QDialog):

def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.setWindowTitle("My Form")

if __name__ == '__main__':

# Create the form
form = Form()

# get a jpg filename
jpgfilename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open image file','*.jpg')

# apply textures
for obj in FreeCADGui.Selection.getSelection():
rootnode = obj.ViewObject.RootNode
tex = coin.SoTexture2()
tex.filename = str(jpgfilename[0])
rootnode.insertChild(tex,1)

and it works. I'm not sure it's in the rules of art.