How to group joint results in the same groups we create in connections definition ?

Member Posts: 32
10 Comments 5 Likes First Anniversary Name Dropper
**

Hi,

I create a code in order the create joint results (force and moment) for each joint in the model. All the results are store in the same group.

  1. def def_JointExport(analysis,nom="Liaisons",temps=[]):
  2. numberAnalysis=Tree.GetPathToFirstActiveObject()
  3. nameAnalysis=numberAnalysis[numberAnalysis.find('[')+1:numberAnalysis.find(']')]
  4. solution = ExtAPI.DataModel.Project.Model.Analyses[int(nameAnalysis)].Solution
  5. connections = ExtAPI.DataModel.Project.Model.Connections
  6.  
  7. strForceUnit = ExtAPI.DataModel.CurrentUnitFromQuantityName("Force")
  8. strMomentUnit = ExtAPI.DataModel.CurrentUnitFromQuantityName("Moment")
  9. strLengthUnit = ExtAPI.DataModel.CurrentUnitFromQuantityName("Length")
  10. strVelocityUnit = ExtAPI.DataModel.CurrentUnitFromQuantityName("Velocity")
  11.  
  12. joints_temp = connections.GetChildren(DataModelObjectCategory.Joint,True)
  13. joints = [joint for joint in joints_temp if joint.Suppressed == False and len(joint.MobileLocation.Ids) != 0 and len(joint.ReferenceLocation.Ids) != 0]
  14.  
  15. liste_dossier = solution.GetChildren(DataModelObjectCategory.TreeGroupingFolder, True)
  16.  
  17. if len(temps) == 0:
  18. temps = analysis.StepsEndTime
  19.  
  20. # Suppresion du dossier DDC si deja existant
  21. for dossier in liste_dossier:
  22. if dossier.Name == "{}".format(nom):
  23. dossier.DeleteTreeGroupAndChildren()
  24.  
  25. # Create a joint probe for each joint not already having a result probe
  26. resgr=[]
  27. cpt = 0
  28. with Transaction(suspendClicks=True):
  29. for joint in joints:
  30. if joint.Suppressed == False:
  31. cpt = cpt + 1
  32. joint_probe = solution.AddJointProbe()
  33. joint_probe.BoundaryConditionSelection = joint
  34. joint_probe.Name = "Liaison_Pdt{}_F_{}_{}".format(str(temps[0]),str(joint.Type), joint.Name)
  35. joint_probe.DisplayTime = Quantity(str(temps[0]) + ' [sec]')
  36. #joint_probe.RenameBasedOnDefinition()
  37. resgr.append(joint_probe)
  38. joint_probe = solution.AddJointProbe()
  39. joint_probe.BoundaryConditionSelection = joint
  40. try:
  41. joint_probe.ResultType = ProbeResultType.MomentReaction
  42. joint_probe.Name = "Liaison_Pdt{}_M_{}_{}".format(str(temps[0]),str(joint.Type), joint.Name)
  43. joint_probe.DisplayTime = Quantity(str(temps[0]) + ' [sec]')
  44. #joint_probe.RenameBasedOnDefinition()
  45. resgr.append(joint_probe)
  46. except:
  47. joint_probe.ResultType = ProbeResultType.FrictionMomentProbe
  48. joint_probe.Name = "Liaison_Pdt{}_M_{}_{}".format(str(temps[0]),str(joint.Type), joint.Name)
  49. joint_probe.DisplayTime = Quantity(str(temps[0]) + ' [sec]')
  50. #joint_probe.RenameBasedOnDefinition()
  51. resgr.append(joint_probe)
  52. joint_probe = solution.AddJointProbe()
  53. joint_probe.BoundaryConditionSelection = joint
  54. joint_probe.ResultType = ProbeResultType.RotationProbe
  55. joint_probe.Name = "Liaison_Pdt{}_M_{}_{}".format(str(temps[0]),str(joint.Type), joint.Name)
  56. joint_probe.DisplayTime = Quantity(str(temps[0]) + ' [sec]')
  57. #joint_probe.RenameBasedOnDefinition()
  58. resgr.append(joint_probe)
  59. ExtAPI.DataModel.Tree.Refresh()
  60.  
  61. if cpt != 0:
  62. dossier_joints = ExtAPI.DataModel.Tree.Group(resgr)
  63. dossier_joints.Name = "{}".format(nom)
  64.  
  65. solution.EvaluateAllResults()

For now, I only get one folder with all results inside.

But in case I have multiple folders in the connection definition, is there a way to group joint results in the same groups ?

Here an example of folders :

Regards,
Jean

Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

  • Administrator, Employee Posts: 303
    Ancient Membership 100 Comments 100 Likes 25 Answers
    admin

    Hi Jean, thanks for your question, I am tagging the @AKD-Scripting-Team who should be able to help.

  • Member, Moderator, Employee Posts: 479
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭

    @Jean there isn't a direct API to do this. You need to loop over all the Joint results fetch their Boundary Condition and collect the ones that belong to a group together in a list and then create a Group.

    1. joint.BoundaryConditionSelection
    1. Tree.Group(joints)
  • Member Posts: 32
    10 Comments 5 Likes First Anniversary Name Dropper
    **

    @Ayush Kumar said:
    @Jean there isn't a direct API to do this. You need to loop over all the Joint results fetch their Boundary Condition and collect the ones that belong to a group together in a list and then create a Group.

    1. joint.BoundaryConditionSelection
    1. Tree.Group(joints)

    Hi Ayush,

    Thanks for your answer.

    Indeed, if for each joint I can have the information about its group, it will be easy.
    But I don't know how to get this information.

    In my script, I get all the joints :

    1. joints_temp = connections.GetChildren(DataModelObjectCategory.Joint,True)
    2. joints = [joint for joint in joints_temp if joint.Suppressed == False and len(joint.MobileLocation.Ids) != 0 and len(joint.ReferenceLocation.Ids) != 0]

    After that, I do a loop on these joints, to do some operation.

    For each joint, how can I know if the joint belong to a group or not (and if it belong to a group, the name of the group) ?

    Regards,
    Jean

  • Member, Moderator, Employee Posts: 479
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭

    @Jean, you can get the name of the groups by checking the Parent name.

    1. for joint in joints:
    2. print joint.Parent.Name

Welcome!

It looks like you're new here. Sign in or register to get started.