Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop
#1
Hello,
I'm trying to create a code for postprocessing some FEA results by using a Python script associated with Abaqus scripting.
my current code is as follow

if Number_Fea == 1:
    xy1 = session.xyDataObjects['RF : %s' %Cases[0]]
    c1 = session.Curve(xyData=xy1)
    chart.setValues(curvesToPlot=(c1, ), )

if Number_Fea == 2:
    xy1 = session.xyDataObjects['RF : %s' %Cases[0]]
    xy2 = session.xyDataObjects['RF : %s' %Cases[1]]
    c1 = session.Curve(xyData=xy1)
    c2 = session.Curve(xyData=xy2)
    chart.setValues(curvesToPlot=(c1, c2, ), )
My question: I would like to loop through my code without repeating these lines of code for each "Number_Fea" value.
The line where I have a problem is the last one ( chart.setValues(curvesToPlot=(c1, c2, ), )). how can I add more variables (c3, c4, c5, ...) when the user gives the "Number of FEA"?
I was thinking about using a dictionary or a function but I couldn't make it work.
Thanks for your help
Larz60+ write Feb-08-2022, 12:23 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBcode tags on future posts.
Reply
#2
You could do
xy = [session.xyDataObjects['RF : %s' %Cases[k]] for k in range(Number_Fea)]
c = [session.Curve(xyData=v) for v in xy]
chart.setValues(curvesToPlot=tuple(c), )
BashBedlam likes this post
Reply
#3
(Feb-08-2022, 09:29 AM)Gribouillis Wrote: You could do
xy = [session.xyDataObjects['RF : %s' %Cases[k]] for k in range(Number_Fea)]
c = [session.Curve(xyData=v) for v in xy]
chart.setValues(curvesToPlot=tuple(c), )

Thank you a lot for your help, it works perfectly!! :)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020