-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: driving dimensions #1340
base: main
Are you sure you want to change the base?
feat: driving dimensions #1340
Changes from 31 commits
6ea7e85
cf40188
a1ae758
f7b7408
43446c9
f0445bd
2d092ff
61bc06f
cf07838
f98afd4
bbe941e
3f91e63
9b71ccb
0fae95a
7fad5ca
a9ae7ae
d59a102
d0a75c0
f07ee2f
e4c3ea0
1040750
b9bc8bf
19eed42
b1de850
c541f27
13ae769
f80327e
091deaf
a864754
d9d9ed4
5619073
ded6cf2
bbfa8b7
24deb62
777533b
ce643b7
8c4bbb1
b2ce393
59416c8
1f7edbb
86e28ca
3b46ae3
9c427e1
bb2b7b1
ba914b2
2dd5169
9d575bf
4f8ea14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
driving dimensions |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,145 @@ | ||||||||||
--- | ||||||||||
jupytext: | ||||||||||
text_representation: | ||||||||||
extension: .mystnb | ||||||||||
format_name: myst | ||||||||||
format_version: 0.13 | ||||||||||
jupytext_version: 1.16.4 | ||||||||||
kernelspec: | ||||||||||
display_name: Python 3 (ipykernel) | ||||||||||
language: python | ||||||||||
name: python3 | ||||||||||
--- | ||||||||||
|
||||||||||
# Modeling: Using Design Parameters | ||||||||||
umutsoysalansys marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
You can read and update parameters that are part of the design. | ||||||||||
In this example, we have a simple design with two associated parameters. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Avoid "we" and use active voice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the reviews @PipKat, I used "we" based on the previous examples on this examples section, so maybe they need to be corrected as well? thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the guideline: Avoid first-person pronouns (I, we, us, our, and ours), For more information, see https://developers.google.com/style/pronouns#personal-pronouns. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @umutsoysalansys - correct, @PipKat tries to review our examples on a best effort basis, but she might have missed the one you linked. I will review that one myself so that it is in-line with the style guidelines. Thank you as always @PipKat! |
||||||||||
|
||||||||||
+++ | ||||||||||
|
||||||||||
## Perform required imports | ||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
import os | ||||||||||
import requests | ||||||||||
from ansys.geometry.core import launch_modeler | ||||||||||
from ansys.geometry.core.modeler import * | ||||||||||
from ansys.geometry.core.parameters import * | ||||||||||
``` | ||||||||||
|
||||||||||
The file for this example is in the integration tests folder, so let's download it. | ||||||||||
|
||||||||||
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Move this info to the download section. |
||||||||||
+++ | ||||||||||
|
||||||||||
## Download the example file | ||||||||||
|
||||||||||
+++ | ||||||||||
|
||||||||||
For this example, download the file from the pyansys-geometry repository. | ||||||||||
umutsoysalansys marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
import requests | ||||||||||
|
||||||||||
def download_file(url, filename): | ||||||||||
"""Download a file from a URL and save it to a local file.""" | ||||||||||
response = requests.get(url) | ||||||||||
response.raise_for_status() # Check if the request was successful | ||||||||||
with open(filename, 'wb') as file: | ||||||||||
file.write(response.content) | ||||||||||
|
||||||||||
# URL of the file to download | ||||||||||
url = "https://github.com/ansys/pyansys-geometry/blob/main/tests/integration/files/blockswithparameters.dsco" | ||||||||||
|
||||||||||
# Local path where the file will be saved | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
file_name = "blockswithparameters.dsco" | ||||||||||
current_path = os.getcwd() | ||||||||||
file_path = os.path.join(current_path, file_name) | ||||||||||
# Download the file | ||||||||||
download_file(url, file_path) | ||||||||||
print("File is downloaded to " + file_path) | ||||||||||
``` | ||||||||||
|
||||||||||
## Import a design with parameters | ||||||||||
|
||||||||||
+++ | ||||||||||
|
||||||||||
Importing the model using ``open_file`` method of the modeler. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
# Create a modeler object | ||||||||||
modeler = launch_modeler() | ||||||||||
design = modeler.open_file(file_path) | ||||||||||
design.plot() | ||||||||||
``` | ||||||||||
|
||||||||||
## Read existing parameters of the design | ||||||||||
|
||||||||||
You can get all the parameters of the design as a list of parameters. In this example there is two parameters. So we can see the two items in the list. | ||||||||||
umutsoysalansys marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
my_parameters = design.get_all_parameters() | ||||||||||
print(len(my_parameters)) | ||||||||||
``` | ||||||||||
|
||||||||||
A parameter object has a name, value, and unit. | ||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
print(my_parameters[0].name) | ||||||||||
print(my_parameters[0].dimension_value) | ||||||||||
print(my_parameters[0].dimension_type) | ||||||||||
|
||||||||||
print(my_parameters[1].name) | ||||||||||
print(my_parameters[1].dimension_value) | ||||||||||
print(my_parameters[1].dimension_type) | ||||||||||
``` | ||||||||||
|
||||||||||
Parameter values are returned in the default unit for each dimension type. Since default length unit is meter and default area unit is meter square, the value is returned in metersquare. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
+++ | ||||||||||
|
||||||||||
## Edit a parameter value | ||||||||||
|
||||||||||
You can edit the parameters name or value by simply setting these fields. Let's | ||||||||||
set the second parameter (p2 value to 350 mm. ) | ||||||||||
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I see parameter1 being set to 0.000440, but that's not what the text says. Is an update to the next needed? |
||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
parameter1 = my_parameters[1] | ||||||||||
parameter1.dimension_value = 0.000440 | ||||||||||
response = design.set_parameter(parameter1) | ||||||||||
print(response) | ||||||||||
print(my_parameters[0].dimension_value) | ||||||||||
print(my_parameters[1].dimension_value) | ||||||||||
``` | ||||||||||
|
||||||||||
After a successful parameter update the design in the backend might have been updated. Therefore you need to refresh the design on the client. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
design = modeler.read_existing_design() | ||||||||||
design.plot() | ||||||||||
``` | ||||||||||
|
||||||||||
The setParameter method returns a status message: "Success" if the parameter is updated, or "FAILURE" if the update fails. If parameter p2 depends on p1, updating p1 may also change p2. In such cases, the method returns "CONSTRAINED_PARAMETERS," indicating other parameters were also updated. | ||||||||||
umutsoysalansys marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
parameter1 = my_parameters[0] | ||||||||||
parameter1.dimension_value = 0.000250 | ||||||||||
response = design.set_parameter(parameter1) | ||||||||||
print(response) | ||||||||||
``` | ||||||||||
|
||||||||||
Therefore user can query the parameters once again to get updated list. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
my_parameters = design.get_all_parameters() | ||||||||||
print(my_parameters[0].dimension_value) | ||||||||||
print(my_parameters[1].dimension_value) | ||||||||||
``` | ||||||||||
|
||||||||||
## Close the modeler | ||||||||||
|
||||||||||
Close the modeler to free up resources and release the connection. | ||||||||||
|
||||||||||
```{code-cell} ipython3 | ||||||||||
modeler.close() | ||||||||||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
"""PyAnsys Geometry parameters subpackage.""" | ||
|
||
from ansys.geometry.core.parameters.parameter import Parameter, ParameterType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be interesting to add an extra body with a fixed size so that after modifying the parameters, when you request plotting, you can visually see the difference with respect to the first plot. This is just a suggestion though - feel free to disregard =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I replaced the file with another object on the side as a scale