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:
FreeCAD does something in the GUI which does not report in the python console.
FreeCAD python interpreter does not execute some commands such as print("")
there is something in FreeCAD API which I'm not using correctly
I would appreciate if you could help me know:
if this is a bug in FreeCAD/python or it is intentional
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.
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.
Related
I have only just begun to learn to code in Python. I have a bit of experience in HTML, but that's about it.
I am current taking the Intro to Programming nanodegree from Udacity.
The lessons I am working on is introducing students to using interactive mode via command line to test bits of code. The problem is that I have to use the python -i command to get into interactive mode, and I am unable to scroll through the history. The bigger problem, however, is that running things like the turtle module are spotty.
Following the instructions in the lesson, I am trying to run the following code:
import turtle
amy = turtle.Turtle()
amy.forward(100)
amy.left(90)
amy.forward(100)
etc...
What ends up happening is I am able to import the turtle, assign it the name "amy", but then when I try to give it movement commands, nothing happens. the >>> disappears and Git Bash stops responding. I have to close the terminal and start a new terminal everything.
Also, being unable to use the arrow keys to cycle through command history is frustrating and retyping the code over and over again any time a mistake is time consuming.
Are there any better ways to go about using the CLI to fulfill the requirements of the course? (I didn't say which requirements, because I'm not entirely sure to what extent the course will require me to utilize the CLI on upcoming projects.)
This problem has frustrated me so much and I am not able to get any useful information from the "mentors" on the Udacity forums, so I have basically stopped progressing through the course.
Any help is much appreciated.
One possible alternative would be to use, instead of a git bash shell, a true Linux session through WSL2 if you are using a recent enough Windows version.
That way, you would benefit from a regular shell, in which history would be available through arrow keys to cycle through.
I'm doing the same course and had the same problem. Found a solution at https://granatguitar.com/why-can't-i-run-python-in-git-bash-on-windows/
I tested it first from the $ prompt and it seemed to work OK, so then I set it up in .bash_profile.
I didn't have a .bash_profile file so I created one in ~ and edited it as granat suggested.
I added the line alias pythoni="winpty python" and saved the file. (I used pythoni rather than python because, well, it's python interactive.)
Now, when I enter pythoni at the $ prompt it starts python in interactive mode....and it works! All the problems with hanging and not moving the turtles have gone.
So I just created a simple script with selenium that automates the login for my University's portal. The first reaction I got from a friend was: ah nice, you can put that on my pc as well. That would be rather hard as he'd have to install python and run it through an IDE or through his terminal or something like that and the user friendliness wouldn't be optimal.
Is there a way that I could like wrap it in a nicer user interface, maybe create an app or something so that I could just share that program? All they'd have to do is then fill in their login details once and the program then logs them in every time they want. I have no clue what the possibilities for that are, therefore I'm asking this question.
And more in general, how do I get to use my python code outside of my IDE? Thusfar, I've created some small projects and ran them in PyCharm and that's it. Once again, I have no clue what the possibilities are so I also don't really know what I'm asking. If anyone gets what I mean by using my code further than only in my IDE, I'd love to hear your suggestions!
The IDE running you program is the same as you running your program in the console. But if you dont want them to have python installed (and they have windows) you can maybe convert them to exe with py2exe. But if they have linux, they probably have python installed and can run you program with "python script.py". But tell your friends to install python, if they program or not, it will always come in handy
I created a new Python workspace in Cloud 9 IDE.
I was able to run the included hello-world.py without any issues, using the terminal.
As for a Run button as described by all documentation, and referred to as missing or bugged in exactly zero Google search results, there is nothing. I've scoured the entire interface and cannot find this magical Run button anywhere.
I created a node.js workspace and the Run button was there, working perfectly.
Even hello-world.py says "# click the 'Run' button at the top to start this application"
Is this something that only appears if you pay?
You have to run most of everything through the terminal by either putting
#!/usr/bin/python at the top of your code or by calling $> python programName.py in the terminal.
I found this a little strange so I went and experimented a bit myself.
As you said, a node.js project has a run button in the status bar as it's supposed to have, but a python project does not.
This made me wonder which other languages do or don't have this button. I tried a couple others (C, C++, Ruby) and none of these had a run button either.
I did come across this in the docs on Running and Debugging
Note: Currently, only Javascript/Node.js applications can make use of
the debugger. You can also execute Javascript/Node.js, Python, Ruby,
and Apache+PHP applications.
I read this before I even began to experiment, but after having created apps for other non Javascript/Node.js projects only to find they did not have a run button either, I think we can assume that by saying this
only Javascript/Node.js applications can make use of the debugger.
the C9 team also meant that currently only only Javascript/Node.js applications can make use of the run function. If so, this could and perhaps should have been stated more clearly though.
Also, a little futher below on that same documentation page it says
Run in debug mode indicates that you want to run the current code
through the debugger. Auto show & hide debug tools will reveal (or
collapse) the debugging tools panel described below. You can also work
with this presentation by going to View > Panels, and configuring the
debugger there.
So I figured I'd try what would happend if I clicked View>Panels, but that option isn't even available, not for JavaScript/Node.js projects either. I'm not sure what's up with that.
So I'm trying to setup the terminal in conjunction with Notepad++ and I'm a little confused. I've managed to download Python 2.7 and load it up in Powershell but I don't really know where to go from there. Do I even need to use a terminal? I know it says you can't use IDLE but it would be a lot easier. If anyone can guide me through getting the right setup to go on with the book I'd appreciate it a lot.
If you managed to get python running in the powershell following the Exercice 0, and you read the "Warning For Beginners" section, you can proceed to Exercice 1.
Why do they recommend that setup? Notepad++ is on Windows a powerful text editor very similar to other text editors, so you will soon get familiar with it. You will need to save your scripts in files and type a special line in the powershell to run and test them. That way you will get accustomed to running programs with arguments and if you make a failure, you can edit your code, save it and run it again.
In IDLE, you are already in a Python environment, so you cannot give arguments to your program inside it (actually you can but it's complex). You can also get an editor, save your file and run the script but also here it's a harder and less obvious way than Notepad++. When you get comfortable with the environment in that book you may change to get something that suits better your way of doing.
I've found a lot of people having the reverse issue, but haven't yet found a question that involves IDLE not being able to run something that runs fine from the command line. I'm using a new module that I haven't used before that uses one .pyd file and one .dll, and involves a device that connects through USB. I sadly can't post in-depth code snippets since this is copyrighted code, but if anyone knows where to start on a problem like this I would be very grateful.
IDLE swaps out the sys.stdout and sys.stderr objects at the Python level this causes issues with some pyd modules. Try using another debugger.