Enter error message or question

Member Posts: 22
10 Comments Name Dropper
**
edited February 14 in General Language Questions

Hi Ansys-Team,

I've a question about updating a progress bar, which I created with Windows Forms.
When I go through a nested loop, I try to update every 25% the progress bar, which works for the label I created in the progress bar ui, but the progessbar itself is behind. For example when I reach 25%, the label shows 25%, but the progress bar is at 0. When the label is updated to 50%, which works, the progress bar shows 25%. Is there a solution for this?

  1. totalNodesToMove = len(dataToMoveNodeList) * len(mesh.Nodes)
  2. progressStep = max(1, int(totalNodesToMove * 0.25))
  3. nextProgressUpdate = progressStep
  4. pb = ProgressBarForm.ProgressBarForm(100, path)
  5. percent = 0
  6. pb.Show()
  7.  
  8. with Transaction(True):
  9. i = 1
  10. for data in dataToMoveNodeList:
  11. for node in mesh.Nodes:
  12. node_y = node.Y
  13. #some other code
  14.  
  15. if i >= nextProgressUpdate:
  16. percent = (i * 100) // totalNodesToMove
  17. pb.update_progress(percent, "Circumferential")
  18. #ExtAPI.Application.InvokeBackground(lambda p=percent: pb.update_progress(p, "Circumferential"))
  19. nextProgressUpdate += progressStep
  20. System.Windows.Forms.Application.DoEvents()
  21. i += 1
  22.  
  23. #Go to next node if rm is more or less equal to new calculated radius. This should save a lot of time for node move.
  24. if round(math.sqrt(math.pow(newX, 2) + math.pow(newZ, 2)), 4) == round(middle_radius, 4) or abs(fraction) <= 1e-12:
  25. continue
  26.  
  27. newLocX = Quantity(newX * correctionScaling, "m")
  28. newLocY = Quantity(node.Y * correctionScaling, "m")
  29. newLocZ = Quantity(newZ * correctionScaling, "m")
  30. nodeMove.MoveNode(node.Id, newLocX, newLocY, newLocZ)

Answers

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

    Hello! Where did you get the ProgressBarForm object from? This isn't strictly about Ansys so I'm not sure how much we can help, but what I can say is when working with front-end stuff like this you often need to redraw windows to get dynamic updates. That is certainly true with matplotlib. Does this have a similar concept going on?

  • Member Posts: 22
    10 Comments Name Dropper
    **

    Hello,

    thanks for the answer. I got the ProgressBarForm from System.Windows.Forms and I did ProgressBar.Refresh() as well as Application.DoEvents().

Welcome!

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