run a script in Discovery using run_discovery_script_file and get design back #1011
Replies: 2 comments 4 replies
-
Hi @kmahajan-cadfem! Thanks for opening this discussion. Couple of things from your script:
from ansys.geometry.core.math.point import Point2D
from ansys.geometry.core.sketch import Sketch
from ansys.geometry.core import launch_modeler_with_discovery
# Launch discovery
modeler = launch_modeler_with_discovery()
# Create a new design
design = modeler.create_design("Integrated_Example")
# Sketch a box and extrude it
design.extrude_sketch("Box", Sketch().box(Point2D([0, 0]), 1, 1), 1)
# Run a scripting file that creates a second body
values = modeler.run_discovery_script_file("integrated_script.py", {"radius": "1"})
# Script creates a 2nd body
assert int(values["numBodies"]) == 2
# Get the active design
design = modeler.get_active_design()
# Verify number of bodies
assert len(design.bodies) == 2
Conclusion: you are right, there is some unexpected behavior in your script - but it is due to the way |
Beta Was this translation helpful? Give feedback.
-
Hi all! From version For example, with the following script: from ansys.geometry.core.math.point import Point2D
from ansys.geometry.core.sketch import Sketch
from ansys.geometry.core import launch_modeler_with_discovery
# Launch discovery
modeler = launch_modeler_with_discovery()
# Create a new design
design = modeler.create_design("Integrated_Example")
# Sketch a box and extrude it
design.extrude_sketch("Box", Sketch().box(Point2D([0, 0]), 1, 1), 1)
# Run a scripting file that creates a second body
values = modeler.run_discovery_script_file("integrated_script.py", {"radius": "1"})
# Script creates a 2nd body
assert int(values["numBodies"]) == 2
# Verify number of bodies BEFORE syncing
assert len(design.bodies) == 1
# Get the active design
design = modeler.get_active_design()
# Verify number of bodies AFTER syncing
assert len(design.bodies) == 2 Another option is to call Closing this discussion as it is now addressed. |
Beta Was this translation helpful? Give feedback.
-
as far as I understand the
run_discovery_script_file
does not change design directly on the Python side because the default forimport_design
is set toFalse
.when a user is running a discovery script knowingly then that means the design should be changed on the python side as well, and hence I do not understand the default value of the
import_design
keyword.can any one shed some light on it?
as an example, following is an excerpt from one test
content of the
integrated_script.py
Beta Was this translation helpful? Give feedback.
All reactions