Macro Template Helper Error [SOLVED]

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Laurie Hartley
Posts: 522
Joined: Mon Feb 27, 2017 5:33 am
Location: Australia

Macro Template Helper Error [SOLVED]

Post by Laurie Hartley »

I have installed the macrow as described her:
https://wiki.freecadweb.org/Macro_TemplateHelper/en

It appears in the Macros Menu but when I execute it nothing appears an I get this error message in the report view which looks very strange:-

17:27:12 Traceback (most recent call last):
File "/home/Laurie/MEGA/MEGAsync/Bolts Macro/TemplateHelper.FCMacro", line 1331, in <module>
main()
File "/home/Laurie/MEGA/MEGAsync/Bolts Macro/TemplateHelper.FCMacro", line 1201, in main
form = InputWindow()
File "/home/Laurie/MEGA/MEGAsync/Bolts Macro/TemplateHelper.FCMacro", line 101, in __init__
self.initUI()
File "/home/Laurie/MEGA/MEGAsync/Bolts Macro/TemplateHelper.FCMacro", line 122, in initUI
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
<class 'NameError'>: name 'QtCore' is not defined

The path leads to my cloud folder??

Has anyone got any idea what is going on here? all advice appreciated.

EDIT : My Bolts Macro and FC Info Macros are working properly??
Attachments
Macro preference Page.png
Macro preference Page.png (84.95 KiB) Viewed 917 times
Last edited by Laurie Hartley on Sat Jul 23, 2022 1:04 am, edited 1 time in total.
User avatar
mfro
Posts: 663
Joined: Sat Sep 23, 2017 8:15 am

Re: Macro Template Helper Error

Post by mfro »

apparently, the macro is missing a required import:

Code: Select all

from PySide2 import QtCore
Add this near the top (around the existing imports) in your macro.
Cheers,
Markus
Laurie Hartley
Posts: 522
Joined: Mon Feb 27, 2017 5:33 am
Location: Australia

Re: Macro Template Helper Error

Post by Laurie Hartley »

mfro wrote: Fri Jul 22, 2022 9:05 am apparently, the macro is missing a required import:

Code: Select all

from PySide2 import QtCore
Add this near the top (around the existing imports) in your macro.
Thanks for your quick response Markus. Just be sure - am I right in my understanding that what I have to do is choose the edit option on the macro menu screen then add this line of code into it?
User avatar
mfro
Posts: 663
Joined: Sat Sep 23, 2017 8:15 am

Re: Macro Template Helper Error

Post by mfro »

Laurie Hartley wrote: Fri Jul 22, 2022 10:53 am Thanks for your quick response Markus. Just be sure - am I right in my understanding that what I have to do is choose the edit option on the macro menu screen then add this line of code into it?
Yes.
Cheers,
Markus
User avatar
FBXL5
Posts: 979
Joined: Sat Aug 03, 2019 8:45 pm

Re: Macro Template Helper Error

Post by FBXL5 »

mfro wrote: Fri Jul 22, 2022 9:05 am apparently, the macro is missing a required import:

Code: Select all

from PySide2 import QtCore
Add this near the top (around the existing imports) in your macro.
@mfro can you give me a hint, why this error never uccurs when I test this macro? It still runs fine without this line on my Mac

Code: Select all

OS: macOS 10.15
Word size of FreeCAD: 64-bit
Version: 0.21.29485 (Git)
Build type: Release
Branch: master
Hash: a236ca843fdd6674afb6d7ed1454fbd3b547f5ea
Python 3.10.5, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods: 
  * Reinforcement
  * Render 2022.2.0
  * sheetmetal 0.2.50
  * Help 1.0.3
  * Curves 0.5.2
  * Assembly3 0.11.3
Nevertheless I have included this line a minute ago. It makes no difference on my system, but if it is required to run on other systems...
Laurie Hartley
Posts: 522
Joined: Mon Feb 27, 2017 5:33 am
Location: Australia

Re: Macro Template Helper Error

Post by Laurie Hartley »

mfro wrote: Fri Jul 22, 2022 12:09 pm
Laurie Hartley wrote: Fri Jul 22, 2022 10:53 am Thanks for your quick response Markus. Just be sure - am I right in my understanding that what I have to do is choose the edit option on the macro menu screen then add this line of code into it?
Yes.
Thanks Markus - your solution worked like a charm.

I have attached a image showing the whereabouts of the edit which may be of help to others.
Attachments
Template_helper_macro_edit.png
Template_helper_macro_edit.png (25.27 KiB) Viewed 738 times
User avatar
mfro
Posts: 663
Joined: Sat Sep 23, 2017 8:15 am

Re: Macro Template Helper Error

Post by mfro »

FBXL5 wrote: Fri Jul 22, 2022 5:48 pm @mfro can you give me a hint, why this error never uccurs when I test this macro? It still runs fine without this line on my Mac
Wild guess: probably the module is already imported into the interpreter from elsewhere?

You can inspect which modules are imported like so:

Code: Select all

import sys

def listModules():
	for key in sys.modules.keys():
		print(key)

print('list of imported modules:')
listModules()
Cheers,
Markus
User avatar
FBXL5
Posts: 979
Joined: Sat Aug 03, 2019 8:45 pm

Re: Macro Template Helper Error [SOLVED]

Post by FBXL5 »

mfro wrote: Sat Jul 23, 2022 6:00 am Wild guess: probably the module is already imported into the interpreter from elsewhere?
Bingo!
It is loaded when freeCAD starts; same with link branch.

Is it OS specific or does it depend on where you loaded your FC package (i.e. who built it)?
User avatar
mfro
Posts: 663
Joined: Sat Sep 23, 2017 8:15 am

Re: Macro Template Helper Error [SOLVED]

Post by mfro »

FBXL5 wrote: Sat Jul 23, 2022 1:12 pm
mfro wrote: Sat Jul 23, 2022 6:00 am Wild guess: probably the module is already imported into the interpreter from elsewhere?
Bingo!
It is loaded when freeCAD starts; same with link branch.

Is it OS specific or does it depend on where you loaded your FC package (i.e. who built it)?
I have another suspicion: there is a setting in Preferences/General/Macro "Run macros in local environment" which is set by default.

Do you have that unset, by any chance?
Cheers,
Markus
User avatar
FBXL5
Posts: 979
Joined: Sat Aug 03, 2019 8:45 pm

Re: Macro Template Helper Error [SOLVED]

Post by FBXL5 »

mfro wrote: Sat Jul 23, 2022 1:20 pm I have another suspicion: there is a setting in Preferences/General/Macro "Run macros in local environment" which is set by default.

Do you have that unset, by any chance?
No, it is (still) checked. I follow the rule: Don't touch settings that you don't understand (yet). 8-)
Post Reply