General Mechanical

General Mechanical

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

User Defined Result

    • Dustin Lochmüller
      Subscriber

      Hi,

      I am currently using a “User Defined Result” to evaluate the equivalent (von-Mises) stress along a construction geometry (path). I use this Python code to generate the result: 

      solution = Model.Analyses[0].Solution.AddUserDefinedResult()
      solution.ScopingMethod = GeometryDefineByType.Path
      solution.Location = DataModel.GetObjectsByName(“PATH_NAME”)[0]
      solution.Expression = r'seqv'
      solution.GraphControlsXAxis = GraphControlsXAxis.Time
      solution.CreateParameter(“Maximum”)

      The path runs through two bodies, but I want to limit it to one body using the geometry option (see screenshot). This works manually by selecting the body, but unfortunately, I can't find a way to do this via the scripting interface.



      Does anyone know how to update the geometry option (something like “solution.Geometry = DataModel.GetObjectsByName(“BODY_NAME”)”)? Thanks in advance.

       

      Kindest Regards

      Dustin

    • Aniket
      Forum Moderator

      try recording the function from mechanical scripting,

      You will get something like:

      #region Details View Action
      selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
      selection.Ids = [64]
      user_defined_result_60.Location = selection

      -Aniket

      Forum Rules & Guidelines

    • Dustin Lochmüller
      Subscriber

      Thanks for the prompt answer, I have already tried that. I already set the location parameter with the path (see code excerpt above). If I set the location parameter again with a body, then the scoping method changes to “Named Selection” and the path is no longer used.

    • Erik Kostson
      Ansys Employee

       

       

       

      The below is working – needs to be in this order:

      model=ExtAPI.DataModel.Project.Model # refer to Model
      analysis = model.Analyses[0]
      solution = analysis.Solution
      geometry = DataModel.GetObjectsByName(‘Solid.1’)[0]
      path = DataModel.GetObjectsByName(‘Path’)[0]
      res=solution.AddUserDefinedResult()
      gId=geometry.GetGeoBody().Id
      SlMn = ExtAPI.SelectionManager
      SlMn.ClearSelection()
      Sel = SlMn.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
      Sel.Ids = [gId]
      res.ScopingMethod=GeometryDefineByType.Path
      res.Location=Sel
      res.Location=path

      res.Expression=’UX'

       

      or if we are using a named selection (NS) say called Selection2:

      model=ExtAPI.DataModel.Project.Model # refer to Model
      analysis = model.Analyses[0]
      solution = analysis.Solution
      ns=DataModel.GetObjectsByName(‘Selection2’)[0] # change name of NS as needed
      path = DataModel.GetObjectsByName(‘Path’)[0] # change name of path as needed
      res=solution.AddUserDefinedResult()
      res.ScopingMethod=GeometryDefineByType.Path
      res.Location=ns
      res.Location=path

      res.Expression=’UZ'

      both are working fine .




      Still if for some reason it is not then read here for more info and alternative:

      https://discuss.ansys.com/discussion/2491/how-to-set-path-and-geometry-scoping-when-defining-result-object-with-path-as-the-scoping-method

       

       

      • Dustin Lochmüller
        Subscriber

         

         

        Thank you, Erik! It is working now. My mistake was that I always did it the other way around (first defined the path and then the geometry) and that didn’t work.

         

        Do you also have some advice on how to export the result as a table? The script recording is not showing any output when I run it by hand.

        If I use "res.ExportToTextFile("PATH_TO_FILE")" it exports the data from the path over distance. I want to change the X-Axis to Time and export those Min, Max, and Average values, but that seems not to work. I did the following but still got the values over distance:

         

        res.GraphControlsXAxis = GraphControlsXAxis.Time
        res.ExportToTextFile("PATH_TO_FILE")

         

        and then I got this:

        but I want to export this:

    • Erik Kostson
      Ansys Employee

      Hi

       

      Does not seem to be a direct command.

       

      One way to do it is posted here:

      https://discuss.ansys.com/discussion/4344/path-results-vs-time-graphic-control

      All the best

      Erik

      • Dustin Lochmüller
        Subscriber
        Hello!
         
        I greatly appreciate your help! Thank you, this has helped me a lot. I'm doing it now, similar but a bit different. I just create a user-defined result for each time step and add the maximum value to the parameter set.
         
        Thank you, it really helped me a lot.
        Dustin
    • Erik Kostson
      Ansys Employee

      In the future post any script related questions in the linked (discuss) forums which are dedicated to that.

      Closing this as it might help others.

    • Dustin Lochmüller
      Subscriber

      Thank you for your detailed answer. Unfortunately, I am unable to make it work.

      In this picture you can see the analysis I am currently using. I generate the path I want to use in static structural. The solid I intend to apply to the geometry parameter is the solid imported from the mechanical model. A named selection contains this body, how can I use the named selection to assign the body to the Geometry parameter?

      And another thing I can't find a solution for currently: Is there a way to export the user defined results data in table form using scripting? Like in this picture 

       

      Thanks for helping 

      Dustin

Viewing 5 reply threads
  • The topic ‘User Defined Result’ is closed to new replies.