-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/GSA_to_Compos #6
base: main
Are you sure you want to change the base?
Conversation
This example uses gsapy so is not currently suitable for the non-Arup users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Peter,
I've made a pile of suggestions, which fit into two categories:
- Making the code more pythonic: this is mostly about how dictionaries are created (using comprehensions instead of looping), and looping directly over data structures instead of looping with an index
- Helpful functionality in gsapy: gsapy does a lot of work for you, so I've suggested a few ways to avoid re-doing it.
from tempfile import gettempdir | ||
from gsapy import GSA | ||
|
||
# gsapy references |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since these are internal to Arup, let's remove them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
extract the new sections to compos_results | ||
6. reopen the GSA model, | ||
use compos_results and sections_dictionary to update the members | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a note to this initial comment along the lines of If you would like more information about gsapy, please contact Oasys Support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
GSA/COM API/Python/GSA2Compos.py
Outdated
|
||
# get GSA data | ||
print("Opening GSA model") | ||
gsa_model = GSA(r'C:\Temp\Composite test.gwb', version='10.1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to simply say GSA('Composite test.gwb')
- it will look in the same directory the script is running in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
GSA/COM API/Python/GSA2Compos.py
Outdated
|
||
# gets the members from the first saved list | ||
search_list = \ | ||
str(gsa_model.get_all_saved_lists()[0]).split("\t")[4].split(" ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can replace your for loop with this:
for i in gsa_model._get_entities_in_named_list("Secondary beams"): # create list of members to be designed
member = gsa_model.get_members(i)
member_list.append([i, gsa_model.get_section_info(member.prop),
gsa_model.get_member_length(i)])
model._get_entities_in_named_list
returns a list of integers (member ids). It works even if the list is 1 to 10
or other complex definitions
gsapy creates a Member object with all the info you need, so there is no need to convert to str
and then parse the string.
member.prop
is the integer id of the section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
GSA/COM API/Python/GSA2Compos.py
Outdated
member_section = int(member.split("\t")[6]) | ||
member_list.append([int(i), gsa_model.get_section_info(member_section), | ||
gsa_model.get_member_length(int(i))]) | ||
sections_dictionary = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from gsapy.modules import Section
sections_dictionary = gsa_model.get(Section)
This creates a dictionary where the keys are the integer ids and the values are Section objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I see that you are using the section description as the key, so it needs something different:
sections_dictionary = {s.desc:s for s in gsa_model.get(Section).values}
or
sections_dictionary = {gsa_model.get_section_info(s.index):s for s in gsa_model.get(Section).values}
you could also expand it as
sections = gsa_model.get(Section) # this gives you the basic dict of sections (keys are the index)
sections_dictionary = {gsa_model.get_section_info(s.index) for s in sections}
https://www.geeksforgeeks.org/python-dictionary-comprehension/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daviddekoning this option does work
sections_dictionary = {}
for i in range(1, 93): # create sections dictionary: needs to match model
sections_dictionary[gsa_model.get_section_info(i)] = i
but is clunky but gives a dictionary in the form {'UB127x76x13':1 etc},
while
sections_dictionary4 = {s.desc:s for s in gsa_model.get(Section).values()}
is elegant but produces something very different.
Is there an elegant way to create the dictionary in the required form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could say s.desc.split("%")[2]:s for si in ....
, but what I did in my suggested changes is just use the full section name, since they are consistent across GSA and Compos. I just had to replace the %s with spaces:
sections_dictionary = {s.desc.replace("%", " "): i for i, s in sections.items()}
GSA/COM API/Python/GSA2Compos.py
Outdated
compos_model = win32com.client.Dispatch("Compos.Automation") | ||
compos_model.Open(gettempdir() + '\\compos_file.csv') | ||
compos_results = [] | ||
for i in range(len(member_list)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can iterate over the member list direction here too, and not use an index
GSA/COM API/Python/GSA2Compos.py
Outdated
compos_model.Close() | ||
print(" Compos model closed") | ||
|
||
print("Opening GSA model") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to re-open if you don't close above
GSA/COM API/Python/GSA2Compos.py
Outdated
compos_model.Design(member_name) | ||
section = compos_model.BeamSectDesc(member_name) | ||
print(member_name, section) | ||
compos_results.append([member_name[7:], section]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you make each list item a tuple, you can auto-expand in the last for loop:
compos_results.append((member_name[7:], section))
GSA/COM API/Python/GSA2Compos.py
Outdated
|
||
print("Opening GSA model") | ||
gsa_model = GSA(r'C:\Temp\Composite test.gwb', version='10.1') | ||
for i in range(len(compos_results)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for member_number, member_section in compos results
member_new_section = member_section.split()[2]
...
# gets section number of Compos | ||
# result | ||
member = gsa_model.get_members(member_number) | ||
member.prop = new_section |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the previous suggestion (line 47), you will have to change this line to
member.prop = new_section.index
GSA2Compos edits
No description provided.