-
-
February 13, 2024 at 8:35 amDayana BehrensSubscriber
Hello,
I'm trying to export an STL result from Ansys Mechanical using a Python script I run from Workbench (I have left out the part where I set up the model.).
I found two options in the Ansys online help to export an STL, but neither works within my script. Both options function when executed directly in the Mechanical scripting window in the Mechanical UI. Interestingly, I can export pictures and text files using the same script.
I'm unsure what's causing the issue. Can you help me?
commands="""
STATIC_STRUCTURAL=Model.Analyses[0]
SOLUTION=STATIC_STRUCTURAL.Solution
setting2d= Ansys.Mechanical.Graphics.GraphicsImageExportSettings()
setting3d = Ansys.Mechanical.Graphics.Graphics3DExportSettings() #######1st option
TOTAL_DEFORMATION_RESULT=SOLUTION.AddTotalDeformation()
CAMERA=Graphics.CameraSOLUTION.ClearGeneratedData()
SOLUTION.Solve()TOTAL_DEFORMATION_RESULT.Activate()
CAMERA.SetFit()
FOLDER_PATH = 'C:\Users\dbehrens\Desktop'
Graphics.ExportImage(FOLDER_PATH+'\\DEF7.png', GraphicsImageExportFormat.PNG, setting2d)
TOTAL_DEFORMATION_RESULT.ExportToTextFile(FOLDER_PATH+'\\Txt1.txt')
Graphics.Export3D(FOLDER_PATH+'\\test.stl', Graphics3DExportFormat.BinarySTL, setting3d)Â #######1st option
result = SOLUTION.Children[1] #######2nd option
result.ExportToSTLFile("C:\Users\dbehrens\Desktop\test1.stl") #######2nd option
"""
model3 = system2.GetContainer("Results")Â
model3.SendCommand(Language="Python", Command=commands) -
February 14, 2024 at 3:59 pmDayana BehrensSubscriber
I think the visibility of the results window is an issue.Â
I use Ansys 2023 r1.Â
If you want to export the stl file in the Mechanical Scripting window, it works in 2024 r1 even if the result window is not visible. In 2023 r1 the result window must be open.
However, I want to export via Workbench because I want to automate everything. I have tested my script in the free 2024 r1 version and it does not work via Workbench either.Â
In 2024 r1 it is also possible to export a stl file with "Python Code After Solve". It does not work in 2023 r1.
I think this does not work directly via Workbench as I wanted. -
February 15, 2024 at 4:08 ammjmiddleAnsys Employee
You can send commends from workbench. You just have to make sure you use commands to ensure Mechanical is open graphically for earlier versions:
model3 = system2.GetContainer("Results")
model3.Edit(Interactive=False)
model3.SendCommand(Language="Python", Command=commands)Â
-
February 15, 2024 at 2:13 pmDayana BehrensSubscriber
Hi,
thank you.Â
The problem was the name of the stl file in this line:
Graphics.Export3D(FOLDER_PATH+'\\test.stl', Graphics3DExportFormat.BinarySTL, setting3d)
When I use test.stl, it doesn't work. With Test.stl it works... I have not used test as a variable anywhere.
That's right, Mechanical 2023 must be open for the stl export to work.
-
February 16, 2024 at 12:10 ammjmiddleAnsys Employee
I haven't checked but maybe it doesn't overwrite existing files of the same name. Make sure test.stl doesn't currently exist. Also, you can do folder dividers in 3 ways:
r'path\file.ext'
'path\\file.ext'
'path/file.ext'The "r" in front means raw text in the first line. Sometimes the first two methods can give you trouble. The second one can especially be trouble when your code does double substitutions and you didn't realize. So sometimes you will see four backslashes in the path because of this in code, and it gets a bit messy. The 3rd method, using a forward slash, has worked for me in all cases, on Windows and Linux.
There is also an os.path.join() method you can use to build up directory and file structure that is going to do it correctly. You need to "import os" first.
Â
-
February 16, 2024 at 10:08 amDayana BehrensSubscriber
Hi,
thank you very much. In fact, the third notation also works with test.stl. I am using Windows.
-
- The topic ‘Mechanical stl export with Python in Workbench’ is closed to new replies.
- Problem with access to session files
- Ayuda con Error: “Unable to access the source: EngineeringData”
- At least one body has been found to have only 1 element in at least 2 directions
- Error when opening saved Workbench project
- Geometric stiffness matrix for solid elements
- How to select the interface delamination surface of a laminate?
- How to apply Compression-only Support?
- Timestep range set for animation export
- Image to file in Mechanical is bugged and does not show text
- SMART crack under fatigue conditions, different crack sizes can’t growth
-
1191
-
513
-
488
-
225
-
209
© 2024 Copyright ANSYS, Inc. All rights reserved.