0

I'm trying to learn FreeCAD python scripting. Basically I open the python console and do what I want to do in the GUI and then look into the python console to learn the commands. and then read the API for that specific task to learn the correct form of python commands.

Things were going fine till I got stuck in this weird issue where the program (I.E FreeCAD) does not execute parts of my code. For example in this macro I create three boxes and then fuse two toghther, and it works just fine. But in this one I create 3 boxes, fuse two of them together, and then try to cut the fusion out of the bigger box. and it doesn't work. I even tried including some flags using print("flag"), but it does not execute these commands. If I copy and past the exact commands into the python consol and run it works fine!

so my speculations are:

  1. FreeCAD does something in the GUI which does not report in the python console.
  2. FreeCAD python interpreter does not execute some commands such as print("")
  3. there is something in FreeCAD API which I'm not using correctly

I would appreciate if you could help me know:

  1. if this is a bug in FreeCAD/python or it is intentional
  2. how can I solve the issue so the FreeCAD python interpreter runs my macro/script as I expect?

P.S. I posted the exact same question here in FreeCAD forum.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193

1 Answers1

0

OK, I figured the problem out. you may see the correct macro here in this Github Gist

explanation: Basically the solution is that when we want to run a Boolean operation on two existing objects we should not change their visibility to false (as the default GUI commands do). If we include those commands then none of the commands after them will be executed.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193