We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
General Mechanical

General Mechanical

Topics related to Mechanical Enterprise, Motion, Additive Print and more.

User button – Python commands

    • jean.collomb
      Subscriber

      Hi,

      I am trying to create a user butter in order to accelerate my post-processing in Ansys Mechanical.

      My dream when I click on the button is :

      1- Create one folder with : total displacement ; 3 directional displacements ; VM stress 

      2- Create one folder for a specific name selection with : total displacement ; 3 directional displacements ; VM stress 

      3- Export these results (min/max values) in a csv file.

      I found this command for the total displacement : ExtAPI.DataModel.Project.Model.Analyses[0].Solution.AddTotalDeformation()

      But I don't know how to fin other commands for directionnal displacements, VM stress, for creating folders, exports results ...

      Thanks you for your help :)

      Jean

    • Erik Kostson
      Ansys Employee

       

       

       

       

       

       

       

      Hi

      You can use the record in the mechanical scripting console, and add the directional deformation , etc., and you will see the commands (e.g., AddDirectionalDeformation(), AddEquivalentStress(), etc.)

      On how to het the max/min from these results, one can get that by:

      equivalent_stress = ExtAPI.DataModel.Project.Model.Analyses[0].Solution.AddEquivalentStress()

      MaxVMSt=equivalent_stress.Maximum

      Then export MaxVMSt to a csv file. Search the internet how to export there are many posts on that, e.g., : 

      https://www.programiz.com/python-programming/writing-csv-files

      Finally group is a bit hard, but not really needed in order to create the results, extract max/min and export these values.

      If needed folders/groups look at the below link for an example that adds these results and puts them into a folder.

      https://discuss.ansys.com/discussion/2540/how-can-add-certain-results-and-group-them#latest

      All the best

      Erik

       

       

       

       

       

       

       

    • jean.collomb
      Subscriber

      Hi Erik,

      Thanks a lot for your answer!

      I try with a simple code, and it works!

      I have two more questions:

      1- Is there any documentation to easily get these informations ?

      2- I try to create a displacement result for a named selection, but the record is incomplet I guess. I get the command bellow where the scoping method is "named selection", but I don't know how to affect a named selection.

      total_deformation_45 = solution.AddTotalDeformation()
      total_deformation_45.ScopingMethod = GeometryDefineByType.Component

      Thanks a lot,

      Jean

      nb : I did not try the export for now.

       

      Code example:

      #----------------------------------------------------------------
      solution = ExtAPI.DataModel.Project.Model.Analyses[0].Solution
      #----------------------------------------------------------------

       


      #----------------------------------------------------------------
      resgr=[]

      # Déplacement selon x, y, z, total
      directional_deformation_global_x = solution.AddDirectionalDeformation()
      directional_deformation_global_x.NormalOrientation = NormalOrientationType.XAxis
      directional_deformation_global_y = solution.AddDirectionalDeformation()
      directional_deformation_global_y.NormalOrientation = NormalOrientationType.XAxis
      directional_deformation_global_z = solution.AddDirectionalDeformation()
      directional_deformation_global_z.NormalOrientation = NormalOrientationType.XAxis
      total_deformation_global = solution.AddTotalDeformation()

      # Contraintes equivalentes Von Mises
      equivalent_stress_global = solution.AddEquivalentStress()

      resgr.append(directional_deformation_global_x)
      resgr.append(directional_deformation_global_y)
      resgr.append(directional_deformation_global_z)
      resgr.append(total_deformation_global)
      resgr.append(equivalent_stress_global)

      dossier_global = ExtAPI.DataModel.Tree.Group(resgr)
      dossier_global.Name = "Global"
      #----------------------------------------------------------------

    • Erik Kostson
      Ansys Employee

      Hi

      1. See this link: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/prod_page.html?pn=Customization%20Suite&prodver=22.2&lang=en
      2. See the link here on how to scope results to named selection (if this is not what you want search in the dev. forum): https://discuss.ansys.com/discussion/909/insert-total-deformation-result-in-modal-analysis-scoped-to-a-named-selection-and-define-maximum-and

        All the best
        Erik
    • jean.collomb
      Subscriber

      Hi Erik,

      Thanks for your answer.

      Regards,

      Jean

Viewing 4 reply threads
  • The topic ‘User button – Python commands’ is closed to new replies.