How to get correct Joint's ObjectState under with Transaction(True)

Options
Louis
Louis Member Posts: 16
First Comment Photogenic Name Dropper
edited June 2023 in Structures

With below code, it shows 'NoState' for Joint ObjectState. It's incorrect status. But out of Transaction, it shows the correct status UnderDefined.

My question is how to get the correct ObjectState within Transaction(True):, so that it can go PromoteToRemotePoint successfully.

Because in my real case, there may be more than 100 Joints that need to do PromoteToRemotePoint, so think to do it with Transaction for speed purpose.


with Transaction(True):
  CreateJoint=ExtAPI.DataModel.Project.Model.Connections.AddJoint()
  CreateJoint.ConnectionType=JointScopingType.BodyToBody
  CreateJoint.Type=JointType.Fixed
  print 'in Transaction: '+str(CreateJoint.ObjectState)
  if CreateJoint.ObjectState==ObjectState.UnderDefined:
    CreateJoint.PromoteToRemotePoint()
print 'out of Transaction: '+str(CreateJoint.ObjectState)

Output:
in Transaction: NoState
out of Transaction: UnderDefined


Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 810
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    Hi @Louis , when using with Transaction() the Mechanical UI is not updated. Therefore the status of the joint cannot be updated either. I would recommend splitting that loop in two parts :

    • one loop to create the joints, in the with Transaction() method
    • refresh the Mechanical tree to get the correct status (Tree.Refresh())
    • create a list of the joints in undefined status, and loop on the objects in that loop to promote them to remote points
  • Louis
    Louis Member Posts: 16
    First Comment Photogenic Name Dropper
    Options

    Pernelle,

    Thank you for providing suggestion.

    step1. one loop to create the joints, in the with Transaction() method

    step2. refresh the Mechanical tree to get the correct status (Tree.Refresh())

    step3. create a list of the joints in undefined status, and loop on the objects in that loop to promote them to remote points


    Okay, step1 and step2 they work.

    But in step3 it seems not work for promote them to remote points while using with Transaction().

    It works while no Transaction.

    Hope to get a way working with Transaction() for speed purpose.

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 810
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    @Louis , for step 3 you will need to have the UI refresh, hence it will not run in a with Transaction method. I'm afraid there is no workaround around that one. But the list will be smaller than the initial one as we restrict the list to only undefined joints.