-
Notifications
You must be signed in to change notification settings - Fork 3
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/AdSec_API_factorised_sample #9
base: main
Are you sure you want to change the base?
Conversation
code_ec2_gb() | ||
|
||
new_rectangle_section(700, 500, 30) | ||
add_links(12) |
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.
I had expected links would not be added to the rectangular section, since global section
was not specified within add_links(), but post line 221, section did have links (I am confused!)
def add_links(diameter):
global bar_material
bar_dia = Length(float(diameter), LengthUnit.Millimeter)
rebar = ILinkGroup.Create(IBarBundle.Create(bar_material, bar_dia))
**section**.ReinforcementGroups.Add(rebar)
My understanding is that any operation on 'section' inside a function would be a local change within that function and shouldn't be reflected on the global section. Ideally I would need to declare global section within add_links() in order for the change to be operated on the global variable. But this isn't what has happened in this script. Same applies to all the rebar types added. Am I missing something?
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.
@VaradaNambiar I do not understand either why the functions are working without the global definition of the section. My suspicion is that the API is not respecting the local function restrictions in some way, which could be a concern.
@tim-lyon-arup @daviddekoning @nathanrobertsarup do you have any thoughts on this?
Just to be on the safe side I have added "global section" into each rebar function
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.
global variables are always accessible in lower scopes in Python. The global
keyword means that changes in the local scope will be reflected back up to the global scope.
If you just want to use a global variable in a lower scope, you do not need to explicitly declare them as global
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 in this instance, using the section in function changed the global instance, despite the function not declaring it as global, hence the confusion. So the following code does add rebar to the section. Is that as expected?
def add_links(diameter):
global bar_material
bar_dia = Length(float(diameter), LengthUnit.Millimeter)
rebar = ILinkGroup.Create(IBarBundle.Create(bar_material, bar_dia))
section.ReinforcementGroups.Add(rebar)
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 @PeterDebneyOasys @VaradaNambiar , my apologies, I lost track of my github mentions. Did you manage to sort out this issue?
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.
@PeterDebneyOasys @VaradaNambiar, as per the current agreed procedures, we shouldn't add the samples directly to this repo. Sample repo is a mirror of a part of Oasys combined, there we add the samples during the development and will publish the samples from the sample repo. If you think anything is missed from samples, please raise a request from Jira, that will be added to the main repository and add the tests to cover the code and then will be mirrored to the sample during the next release. If we add the content directly to this repo, it misses the tests and might not work with future releases and affect the quality of the samples that we publish to the users.
This sample file demonstrates how you can make the use of the API simpler by factorising the API calls from the training course.