-
Notifications
You must be signed in to change notification settings - Fork 16
Home
On these pages small snippets of code are presented that help you to automate tasks working with Industry Foundation Classes models. It is targeted at building domain experts (architects, civil engineers etc.) who have little or no background knowledge in coding. It uses the IfcOpenShell toolkit by Thomas Krijnen. In particular, an interactive viewer is used that allows for quick feedback between the interactions of the scripts with the model by visualizing the results. Even though a regular Python tutorial is strongly recommended, the
As a first check, to test whether the setup works, please start the viewer and load a model. Then, type in the words
print ("hello world")and press the Run button (or press Ctrl+P) which should print out the words hello world to the console window under the editor.
All code in the editor is regular Python code and will be evaluated by the Python interpreter when "Run" is pressed.
As in many programming languages, a python script consists of expressions that are executed by the interpreter and evaluated. A simple expression e.g. can be 1 + 1. This will instruct the interpreter to calculate the sum of 1 plus 1. In order to see the result, we have to do something with it. A simple way would be to print the result to the console. This can be achieved by using some of the functionalities offered by the Python language and interpreter. There are hundreds of functions built into the core language of Python itself. One of these handy functions is the print function, which takes any number of arguments, evaluates them and prints it to the console (or any other output) like so:
print (1 + 1)which should result in the console output
2Instead of printing out the results of an operation (like 1+1) it is often necessary to store the result in a variable. In Python, this is achieved by the assignment operator =:
result = 1 + 1This stores or 'assigns' the result of the operation "1 + 1" on the right hand side of the equals sign in a new variable result (the left hand side). Within certain limits, you are free to come up with any variable name of your own (e.g. my_result, resultaat, aResult etc.) Notice however, that you should have in mind that the variable name should be clear, readable and tell others (or yourself, when you pick up your work later on), what the purpose of the variable is.
We can then operate further with the variable, by e.g. printing out its contents:
result = 1 + 1
print ("the result is: ", result)
result = result + 1
print ("now the result is: ", result)This means that you can also include other libraries that might not be included in one of the standard modules of the language via the regular import ... statements.