TAGGED: curved-geometry, python, script, spaceclaim
-
-
June 17, 2023 at 3:21 pm
Merel Meulendijks
SubscriberI created this script below in the spaceclaim script environment. The goal is to import a .txt file, create the wanted geometry, save it and repeat this process so that 50 geometries are created and saved. However, when I run it, my previous geometry gets overwritten by the next one (in the same design file). How can I fix this? So the goal is to: create the geometry in new design, save and close the new design and open a new design to create the next geometry:
# Python Script, API Version = V23
filename = r"C:\Users\20182785\iCloudDrive\TUe\BMT\Year 3\Q4\BEP\Matlab_probeersels\1000_cosines\trimmed_cos_points_"
txtnums = map(str, range(1,51))
for i in txtnums:
DocumentInsert.Execute(filename+i+".txt", FileSettings1, GetMaps("f5a15159"))
# Set Sketch Plane
sectionPlane = Plane.PlaneXY
result = ViewHelper.SetSketchPlane(sectionPlane, Info6)
# EndBlock# Solidify Sketch
mode = InteractionMode.Solid
result = ViewHelper.SetViewMode(mode, Info5)
# EndBlock# Revolve 1 Sketch Curve
selection = Curve2
result = RevolveEdges.Execute(selection, Line.Create(Point.Create(MM(0), MM(0), MM(0)),
Direction.DirY), DEG(360), False, ExtrudeType.None)
# EndBlock
# Delete Objects
selection = CurveFolder1
result = Delete.Execute(selection)
# EndBlock
# Extrude 1 Edge
selection = Edge2
secondarySelection = Edge2
options = ExtrudeEdgeOptions()
result = ExtrudeEdges.Execute(selection, secondarySelection, MM(-20), options, Info7)
# EndBlock
# Extrude 1 Edge
selection = Edge1
secondarySelection = Edge1
options = ExtrudeEdgeOptions()
result = ExtrudeEdges.Execute(selection, secondarySelection, MM(20), options, Info8)
# EndBlock
# Fill
selection = Edge3
secondarySelection = Selection.Empty()
options = FillOptions()
result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info11)
# EndBlock# Fill
selection = Edge4
secondarySelection = Selection.Empty()
options = FillOptions()
result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info12)
# EndBlock# Rotate About X Handle
selection = Body1
anchorPoint = Move.GetAnchorPoint(selection)
axis = Line.Create(anchorPoint, Direction.DirX)
options = MoveOptions()
result = Move.Rotate(selection, axis, DEG(90.0000000000002), options, Info9)
# EndBlock# Create Named Selection Group
primarySelection = Face1
secondarySelection = Selection.Empty()
result = NamedSelection.Create(primarySelection, secondarySelection)
# EndBlock# Rename Named Selection
result = NamedSelection.Rename("Group1", "Inlet")
# EndBlock# Create Named Selection Group
primarySelection = Face2
secondarySelection = Selection.Empty()
result = NamedSelection.Create(primarySelection, secondarySelection)
# EndBlock# Rename Named Selection
result = NamedSelection.Rename("Group1", "Outlet")
# EndBlock# Create Named Selection Group
primarySelection = FaceRegion1
secondarySelection = Selection.Empty()
result = NamedSelection.Create(primarySelection, secondarySelection)
# EndBlock# Rename Named Selection
result = NamedSelection.Rename("Group1", "Wall")
# EndBlock# Create Named Selection Group
primarySelection = Body2
secondarySelection = Selection.Empty()
result = NamedSelection.Create(primarySelection, secondarySelection)
# EndBlock# Rename Named Selection
result = NamedSelection.Rename("Group1", "Fluid_domain")
# EndBlock
filename1 = r"C:\Users\20182785\iCloudDrive\TUe\BMT\Year 3\Q4\BEP\Save_geometries\Automated\scdocs\cartery
DocumentSave.Execute(filename1+i+".scdoc") -
June 20, 2023 at 8:19 am
mjmiddle
Ansys EmployeeThere is more than one way to to go about this.
- You can use DocumentOpen.Execute() instead of DocumentInsert.Execute(), to open in a new document instead of opening into the existing document. Don’t forget to close the current document at the end of the script using Window.ActiveWindow.Close().
- You could simply delete all geometry at the beginning of the loop just before the DocumentInsert.Execute() using the ClearAll() command. This way you keep working in the same document.
Also, rather than creating a map, using “txtnums = map(str, range(1,51)),” you can loop on the integer, which is more normal, and just convert to string where that type is necessary:
DocumentSave.Execute(filename1+str(i)+”.scdoc”)
-
- You must be logged in to reply to this topic.

Boost Ansys Fluent Simulations with AWS
Computational Fluid Dynamics (CFD) helps engineers design products in which the flow of fluid components is a significant challenge. These different use cases often require large complex models to solve on a traditional workstation. Click here to join this event to learn how to leverage Ansys Fluids on the cloud, thanks to Ansys Gateway powered by AWS.

Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.

Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- How to work with STL file?
- Rotate tool in ANSYS Design Modeler
- section plane
- Using Symmetry in DesignModeler and Expanding the Results
- ANSYS FLUENT – Operation would result in non manifold bodies
- drawing a geometry by importing a table of points
- material properties
- Coordinates orientation
- “contact pair has no element in it.” how to resolve this problem
- Parameters not imported into Workbench 18.2 from Solidworks/Inventor
-
7742
-
4502
-
2961
-
1449
-
1322
© 2023 Copyright ANSYS, Inc. All rights reserved.