Skip to content

Commit

Permalink
Refactors documentation content.
Browse files Browse the repository at this point in the history
  • Loading branch information
jspaquet committed Mar 13, 2024
1 parent 9720709 commit bf5a92f
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 82 deletions.
9 changes: 4 additions & 5 deletions docs/auto_attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ content via a Python script.
These attributes are created similar to the user-defined attributes in the Attributes dialog
(User profile -> Wood... -> Attributes) in the new Script Filled -> Configuration tab.

<figure markdown="1">
![Backup Text](img/auto.jpg "script-filled attributes"){: style="width:700px"}

</figure>

A created script-filled attribute is available for each element type in cadwork. In the tab "Type
script populated" the evaluation of the script can be limited to single element types. Tjis can be useful if, for example
Expand All @@ -53,7 +54,9 @@ attribute remains empty for all other element types. If the element type is subs
The execution status of the scripts can be controlled.
The icon for configuring the script-filled attributes is visualized in the Windows menu bar to the left of the message center icon. This display hides a button that can be used to subsequently change the selected status.

<figure markdown="1">
![Backup Text](img/auto_button.jpg "script-filled attributes settings"){: style="width:700px"}
</figure>

## available functions
The available functions are marked in the documentation with an info description.
Expand Down Expand Up @@ -140,7 +143,3 @@ for element_id in element_ids:
cadwork.set_auto_attribute([element_id], f'{material} - {storey}')
```

<noscript>
<img src="https://analytics.cadwork.ca/ingress/e6b1702b-6224-4e93-94b7-9e4c2cd7ae06/pixel.gif">
</noscript>
<script defer src="https://analytics.cadwork.ca/ingress/e6b1702b-6224-4e93-94b7-9e4c2cd7ae06/script.js"></script>
48 changes: 28 additions & 20 deletions docs/get_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ hide:
- toc
---

# Set upt Python in cadwork - Step by Step
# Setup Python in Cadwork

To use Python scripts in cadwork, they must be located in the userprofile in the folder api.x64.

Click in a 3D file on **Help** --> **Info** and open the folder named **Userprofile** which brings you to the api.x64 directory.

![Screenshot](img/info.png){: style="width:600px"}
<figure markdown="1">
![Screenshot](img/info.png){width=600}
</figure>

A folder must be created in the api.x64 directory for each script. The Python script must have the same name as the folder so that it can be executed.

![Screenshot](img/directory.png){: style="width:600px"}

![Screenshot](img/script.png){: style="width:600px"}
<figure markdown="1">
![Screenshot](img/directory.png){width=600}
</figure>

<figure markdown="1">
![Screenshot](img/script.png){width=600}
</figure>

Once you have placed a folder and a script in the directory, you can start a cadwork 3D file.

Expand All @@ -41,9 +46,9 @@ For the plugins you can add a description. To do this, you can use the following
Save the XML file under the name plugin_info.xml in the directory of your plugin.
The plugin info is then displayed as soon as the mouse pointer is hovered over the icon.

<br>
![Screenshot](img/info_xml.png)
<br>
<figure markdown="1">
![Screenshot](img/info_xml.png){width=500}
</figure>

#### plugin_info.xml
```xml
Expand Down Expand Up @@ -126,29 +131,35 @@ On macOS, there is one application menu. It dynamically changes according to the

Go to [Github - cadwork](https://github.com/CadworkMontreal/PythonConsole) -> click on Button **Code** and clone or Download ZIP into your directory -> c:\users\public\documents\cadwork\userprofil_28\API.x64\PythonConsole'.

![Screenshot](img/clone.png){: style="width:800px"}

<figure markdown="1">
![Screenshot](img/clone.png){width=800}
</figure>

### run Code
Open cadwork 3D and open the Python Console (IDLE) from the plugin bar.

Save your .py script an hit key F5 or go via Menu -> Run -> Run Module
![Screenshot](img/run.png){: style="width:800px"}
Save your .py script and press ++f5++ or go via Menu -> Run -> Run Module

<figure markdown="1">
![Screenshot](img/run.png){width=800}
</figure>

Example Code:

```python
# import modules
import cadwork
import element_controller as ec
import attribute_controller as ac
import cadwork
import element_controller as ec
import attribute_controller as ac

# get active element_ids
element_ids = ec.get_active_identifiable_element_ids()

for element_id in element_ids:
subgroup = ac.get_subgroup(element_id) # get subgroup name of active element_ids
print(subgroup) # print the subgroup names
subgroup = ac.get_subgroup(element_id) # get subgroup name of active element_ids
print(subgroup) # print the subgroup names
```


Expand All @@ -165,9 +176,10 @@ Cadwork uses CPython version 3.9.10

### Install CWAPI3D package on your device

```python
```bash
pip install cwapi3d
```

[Github - cwapi3d python](https://github.com/cwapi3d/cwapi3dpython){target=_blank}

[PyPi Python Package](https://pypi.org/project/cwapi3d/){target=_blank}
Expand All @@ -178,9 +190,5 @@ The script cannot be run from the IDE (PyCharm, VS Code, ...). The script call m



<noscript>
<img src="https://analytics.cadwork.ca/ingress/e6b1702b-6224-4e93-94b7-9e4c2cd7ae06/pixel.gif">
</noscript>
<script defer src="https://analytics.cadwork.ca/ingress/e6b1702b-6224-4e93-94b7-9e4c2cd7ae06/script.js"></script>


70 changes: 46 additions & 24 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,80 @@
---
hide:
- toc
- toc
---

# Cadwork Python Documentation

In front of you, you see the first version of the Cadwork Python Guide. This document is written in cooperation of the cadwork branches. Since version 27 cadwork offers an API connection to the script language Python. By scripting in cadwork with Python you can automate and customize your operations.
In front of you, you see the first version of the Cadwork Python Guide.
This document is written in cooperation of the Cadwork branches.
Since version 27 Cadwork offers an API connection to the script language Python.
By scripting in Cadwork with Python you can automate and customize your operations.

The API provides a multitude of basic functions of cadwork 3D. On the basis of the API external programs can be written, with which it is possible to e.g. create and manipulate parts.
The API provides a multitude of basic functions of Cadwork 3D.
On the basis of the API external programs can be written, with which it is possible to e.g. create and manipulate parts.

List calculations, list outputs, various import and export functions and much more is available via the API. This allows the implementation of customer specific functions without changing the program code of cadwork. By using the API, a wide range of helpers for various areas can be created and directly integrated into cadwork 3D. Cadwork itself delivers some of these small helpers by default. But also the development of small and large helpers by you as a user is possible.
List calculations, list outputs, various import and export functions and much more is available via the API.
This allows the implementation of customer specific functions without changing the program code of Cadwork.
By using the API, a wide range of helpers for various areas can be created and directly integrated into Cadwork 3D.
Cadwork itself delivers some of these small helpers by default.
But also the development of small and large helpers by you as a user is possible.

The Python Guide should enable you to start scripting in cadwork 3D. We hope we can convince you of the great potential with Python in cadwork.
The Python Guide should enable you to start scripting in Cadwork 3D.
We hope we can convince you of the great potential with Python in Cadwork.

## Discussion - Form

[GitHub Discussion - Ask and answer questions from the Community](https://github.com/cwapi3d/cwapi3dpython/discussions){target=_blank} :speech_balloon:
## Discussions

[GitHub Discussion - Ask and answer questions from the Community](https://github.com/cwapi3d/cwapi3dpython/discussions){target=_blank}

## Introduction

### What Is an API?
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build such a connection or interface is called an API specification. A computer system that meets this standard is said to implement or expose an API. The term API may refer either to the specification or to the implementation.

![Backup Text](img/python.png "cadwork API"){: style="width:700px"}
An application programming interface (API) is a connection between computers or between computer programs.
It is a type of software interface, offering a service to other pieces of software.
A document or standard that describes how to build such a connection or interface is called an API specification.
A computer system that meets this standard is said to implement or expose an API.
The term API may refer either to the specification or to the implementation.

<figure markdown="1">
![Cadwork API](img/python.png){ width="500" }
</figure>

### Why Python?
### Why Python?

* Python is easy to learn. Its syntax is easy and code is very readable.
* Python has a lot of applications. It's used for developing web applications, data science, rapid application development, and so on.
* Python allows you to write programs in fewer lines of code than most of the programming languages.
* The popularity of Python is growing rapidly. Now it's one of the most popular programming languages.

### What Is Python?
### What Is Python?

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.
Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together.
Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.
Often, programmers fall in love with Python because of the increased productivity it provides.
Since there is no compilation step, the edit-test-debug cycle is incredibly fast.
Debugging Python programs is easy: a bug or bad input will never cause a segmentation fault.
Instead, when the interpreter discovers an error, it raises an exception.
When the program doesn't catch the exception, the interpreter prints a stack trace.
A source level debugger allows inspection of local and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping through the code a line at a time, and so on.
The debugger is written in Python itself, testifying to Python's introspective power.
On the other hand, often the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-debug cycle makes this simple approach very effective.[^1]

Often, programmers fall in love with Python because of the increased productivity it provides. Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input will never cause a segmentation fault. Instead, when the interpreter discovers an error, it raises an exception. When the program doesn't catch the exception, the interpreter prints a stack trace. A source level debugger allows inspection of local and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping through the code a line at a time, and so on. The debugger is written in Python itself, testifying to Python's introspective power. On the other hand, often the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-debug cycle makes this simple approach very effective.[^1]
[^1]: [python](https://www.python.org/doc/essays/blurb/)
[^1]: [Python](https://www.python.org/doc/essays/blurb/){target=_blank}

```python
print("Hello cadwork World, let's get started!")
print("Hello Cadwork! Let's get started!")
```

Python provides some built-in data types, in particular, [dict](https://docs.python.org/3/library/stdtypes.html#dict){target=_blank}, [list](https://docs.python.org/3/library/stdtypes.html#list){target=_blank}, [set and frozenset](https://docs.python.org/3/library/stdtypes.html#set){target=_blank}, and [tuple](https://docs.python.org/3/library/stdtypes.html#tuple){target=_blank}. The [str](https://docs.python.org/3/library/stdtypes.html#str){target=_blank} class is used to hold Unicode strings, and the [bytes](https://docs.python.org/3/library/stdtypes.html#bytes){target=_blank} and [bytearray](https://docs.python.org/3/library/stdtypes.html#bytearray){target=_blank} classes are used to hold binary data.[^2]
[^2]: [data types](https://docs.python.org/3/library/datatypes.html)
Python provides some built-in data types, in particular, [dict](https://docs.python.org/3/library/stdtypes.html#dict){target=_blank}, [list](https://docs.python.org/3/library/stdtypes.html#list){target=_blank}, [set and frozenset](https://docs.python.org/3/library/stdtypes.html#set){target=_blank}, and [tuple](https://docs.python.org/3/library/stdtypes.html#tuple){target=_blank}.
The [str](https://docs.python.org/3/library/stdtypes.html#str){target=_blank} class is used to hold Unicode strings, and the [bytes](https://docs.python.org/3/library/stdtypes.html#bytes){target=_blank} and [bytearray](https://docs.python.org/3/library/stdtypes.html#bytearray){target=_blank} classes are used to hold binary data.[^2]

If you are unfamiliar with Python and still want to write helper scripts, I recommend doing a tutorial and then come back to cadwork. :woman_student: <br>
[^2]: [Data Types](https://docs.python.org/3/library/datatypes.html){target=_blank}

We recommend following a tutorial and coming back afterward if you are unfamiliar with Python. :woman_student:

* [The Python Tutorial](https://docs.python.org/3.4/tutorial/){target=_blank}
* [LearnPython](https://www.learnpython.org/){target=_blank}
* [RealPython](https://realpython.com/){target=_blank}

<noscript>
<img src="https://analytics.cadwork.ca/ingress/e6b1702b-6224-4e93-94b7-9e4c2cd7ae06/pixel.gif">
</noscript>
<script defer src="https://analytics.cadwork.ca/ingress/e6b1702b-6224-4e93-94b7-9e4c2cd7ae06/script.js"></script>
52 changes: 19 additions & 33 deletions docs/videos.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,23 @@ hide:
- toc
---

<div class="table">
<div class="media">
<div class="image">
<iframe width="560" height="315" src="https://www.youtube.com/embed/hn3AtHPqEqE" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="text">
This is video shows you how to build a plugin with python in cadwork.<br><br>
Video Language : English
</div>
</div>
<div class="media">
<div class="image">
<iframe width="560" height="315" src="https://www.youtube.com/embed/aO-vPemaKo8" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="text">
This is video shows you how to build and use python for auto populated attributes in cadwork 3D.<br><br>
Video Language : German
</div>
</div>
<div class="media">
<div class="image">
<iframe width="560" height="315" src="https://www.youtube.com/embed/YYlJGakHfMc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="text">
This video gives you an overview about the python API in cadwork 3D.<br> <br>
Video Language : German
</div>
</div>
</div>
## Building DualExport

<noscript>
<img src="https://analytics.cadwork.ca/ingress/e6b1702b-6224-4e93-94b7-9e4c2cd7ae06/pixel.gif">
</noscript>
<script defer src="https://analytics.cadwork.ca/ingress/e6b1702b-6224-4e93-94b7-9e4c2cd7ae06/script.js"></script>
<figure markdown="1">
<iframe width="560" height="315" src="https://www.youtube.com/embed/hn3AtHPqEqE" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<figcaption>Language: English</figcaption>
</figure>

## Auto-Attributes

<figure markdown="1">
<iframe width="560" height="315" src="https://www.youtube.com/embed/aO-vPemaKo8" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<figcaption>Language: English</figcaption>
</figure>

## Cadwork API Presentation

<figure markdown="1">
<iframe width="560" height="315" src="https://www.youtube.com/embed/YYlJGakHfMc" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<figcaption>Language: German</figcaption>
</figure>

0 comments on commit bf5a92f

Please sign in to comment.