TAGGED: 3d-geomertry, ansys-spaceclaim, script-spaceClaim, spaceclaim
-
-
June 9, 2023 at 1:14 pm
Merel Meulendijks
SubscriberHi guys! I really need your help.
I created 1000 .txt files with each .txt file containing the coordinates of a trimmed cosine curve. This is the format:
1 2.41 -7.07
1 2.41 -7.0558
1 2.41 -7.0417
1 2.41 -7.0275
1 2.4099 -7.0134
1 2.4099 -6.9992Â etc.Â
In this example below, I load in one of these files in the SpaceClaim script editor:Â# Insert From FileDocumentInsert.Execute(r"C:\Users\20182785\iCloudDrive\TUe\BMT\Year 3\Q4\BEP\Matlab_probeersels\1000_cosines\trimmed_cos_points_7.txt", FileSettings1, GetMaps("f5a15159"))# EndBlockÂ# Set Sketch PlanesectionPlane = Plane.PlaneXYresult = ViewHelper.SetSketchPlane(sectionPlane, Info1)# EndBlockÂ# Solidify Sketchmode = InteractionMode.Solidresult = ViewHelper.SetViewMode(mode, Info2)# EndBlockÂ# Revolve 1 Sketch Curveselection = Curve2result = RevolveEdges.Execute(selection, Line.Create(Point.Create(MM(0), MM(0), MM(0)),ÂÂ Â Direction.DirY), DEG(360), False, ExtrudeType.None)# EndBlockÂ# Delete Objectsselection = CurveFolder1result = Delete.Execute(selection)# EndBlockÂ# Extrude 1 Edgeselection = Edge2secondarySelection = Edge2options = ExtrudeEdgeOptions()result = ExtrudeEdges.Execute(selection, secondarySelection, MM(-20), options, Info4)# EndBlockÂ# Extrude 1 Edgeselection = Edge1secondarySelection = Edge1options = ExtrudeEdgeOptions()result = ExtrudeEdges.Execute(selection, secondarySelection, MM(20), options, Info5)# EndBlockÂ# Fillselection = Edge3secondarySelection = Selection.Empty()options = FillOptions()result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info11)# EndBlockÂ# Fillselection = Edge4secondarySelection = Selection.Empty()options = FillOptions()result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info12)# EndBlockÂ# Rotate About X Handleselection = Body1anchorPoint = Move.GetAnchorPoint(selection)axis = Line.Create(anchorPoint, Direction.DirX)options = MoveOptions()result = Move.Rotate(selection, axis, DEG(90.0000000000002), options, Info3)# EndBlockÂfilename = r"C:\Users\20182785\iCloudDrive\TUe\BMT\Year 3\Q4\BEP\Save_geometries\Automated\scdocs\Artery7.scdoc"Â# Save FileDocumentSave.Execute(filename)# EndBlockÂ
If I run this script, the following geometry is created:
The problem is that I want to create a loop (in the script editor) in which I can loop over the 1000 txt files containing the trimmed cosine curve coordinates (instead of only loading in one file) in order to create and save the 1000 geometries. How can I do this? A large problem is that once one geometry is created, the second one will be created in the same "design" file resulting in geometries that overwrite each other (and errors). For that, a new 'design' file needs te be opened in each run of the loop. How can this be done? Thank you in advance.Â
-
June 12, 2023 at 8:40 am
Aniket
Forum ModeratorIf you check DocumentInsert.Execute command in the interpreter:
It can also be used as follows:
DocumentInsert.Execute(r"D:\Desktop\Desktop\test1.txt")
DocumentInsert.Execute(r"D:\Desktop\Desktop\test1.txt")
Now you can use other modules to get all files in a directory and import them in a for loop if you want the geometries in a single file. If you want them in different files, then you can simply use save as before importing new text file each time:
# Save File
options = ExportOptions.Create()
DocumentSave.Execute(r"D:\Desktop\Desktop\test3.scdoc", options)
# EndBlock-Aniket
-
- The topic ‘Creating 1000 geometries’ is closed to new replies.
-
3427
-
1057
-
1051
-
896
-
887
© 2025 Copyright ANSYS, Inc. All rights reserved.