Skip to content
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

ADSEC-2019 create sample files for using the api with excel #22

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/sanity_checks_for_prs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: sanity checks
# merge_group triggers happen in merge queues

# workflow_dispatch triggers happen when a user manually runs the workflow
# pull_request triggers happen when a pull request is updated
on: [merge_group, pull_request, workflow_dispatch]
Expand Down Expand Up @@ -30,5 +31,6 @@ jobs:
shell: bash
id: Run_pre-commit
# this makes sure we do not accidentally use hooks that need docker on the dev machines

env:
DOCKER_HOST: docker_intentionally_disabled
70 changes: 70 additions & 0 deletions AdSec/.NET/ApiToExcel/ApiToExcel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//Importing the necessary packages
using System;
using System.IO;
using System.Linq;
using ClosedXML.Excel; //Open source library That can be used for reading and writing in the excel file
using Oasys.AdSec;
using OasysUnits;
using OasysUnits.Units;
using Oasys.Profiles;
using Oasys.AdSec.StandardMaterials;
using Oasys.AdSec.DesignCode;

class Program
{
static void Main()
{
try
{
//Getting the workbook from the excel file.
var workbook = new XLWorkbook("Path to your file..");

var worksheet = workbook.Worksheet("Sheet1");
// Getting the load from the excel file
var load = worksheet.Range("A2:C" + worksheet.LastRowUsed().RowNumber()).Rows();
// creating adsec object and defining section material
var sectionMaterial = Steel.EN1993.Edition_2005.S235;
var adSec = IAdSec.Create(EN1992.Part1_1.Edition_2004.NationalAnnex.GB.Edition_2014);
//Creating a secion
var diameter = new Length(80, LengthUnit.Inch);
var circleProfile = ICircleProfile.Create(diameter);
var section = ISection.Create(circleProfile, sectionMaterial);
//Analysing the section
var circleSectionAnalysis = adSec.Analyse(section);
// Starting from 2 as the 1st row is the heading
int x = 2;
for (int i = 2; i < load.Count(); i++)
{
// Getting the loads and coverting it
var force_x = new Force(
(double)worksheet.Cell("A" + i).Value,
ForceUnit.Kilonewton
);
var moment_yy = new Moment(
(double)worksheet.Cell("B" + i).Value,
MomentUnit.KilonewtonMeter
);
var moment_zz = new Moment(
(double)worksheet.Cell("C" + i).Value,
MomentUnit.KilonewtonMeter
);
var circleLoad = ILoad.Create(force_x, moment_yy, moment_zz);
//Getting the strength results
var strengthResult = circleSectionAnalysis.Strength.Check(circleLoad);
var utilisation = Math.Round(strengthResult.LoadUtilisation.Percent, 1);
var ulsStatus = utilisation < 100 ? "Clear" : "Not Clear";
worksheet.Cell("D" + i).Value = utilisation;
worksheet.Cell("E" + i).Value = ulsStatus;
}
workbook.Save();
}
catch (FileNotFoundException)
{
Console.WriteLine("File not found");
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
10 changes: 10 additions & 0 deletions AdSec/.NET/ApiToExcel/ApiToExcel.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
46 changes: 46 additions & 0 deletions AdSec/Python/ApiToExcel.py
renefritze marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# importing packages
import openpyxl as op # OPen source library that can be used for reading and writing into the excel files
from Oasys.AdSec import IAdSec, ILoad, ISection
from Oasys.AdSec.DesignCode import EN1992
from Oasys.AdSec.StandardMaterials import Steel
from Oasys.Profiles import ICircleProfile
from OasysUnits import Force, Length, Moment
from OasysUnits.Units import ForceUnit, LengthUnit, MomentUnit

# Reading Values from the excel file

try:
workbook = op.load_workbook(filename=r"C:\Repo\oasys-api-samples\AdSec\Python\loads.xlsx")
sheet1 = workbook["Sheet1"]
load = [row for row in sheet1.iter_rows(min_row=2, max_col=3, values_only=True)]
# Defining the Section Material
section_material = Steel.EN1993.Edition_2005.S235

# Creating adsec object
adsec = IAdSec.Create(EN1992.Part1_1.Edition_2004.NationalAnnex.GB.Edition_2014)

# Creating a Circular Section
diameter = Length(float(80), LengthUnit.Inch)
circle_profile = ICircleProfile.Create(diameter)
section = ISection.Create(circle_profile, section_material)

# circular Section Analysis
circle_section_analyse = adsec.Analyse(section)
x = 2
max_utilization = 100
for row in load:
Force_x = Force(float(row[0]), ForceUnit.Kilonewton)
Moment_yy = Moment(float(row[1]), MomentUnit.KilonewtonMeter)
Moment_zz = Moment(float(row[2]), MomentUnit.KilonewtonMeter)
circle_load = ILoad.Create(Force_x, Moment_yy, Moment_zz)
strength_result = circle_section_analyse.Strength.Check(circle_load)
utilisation = round(strength_result.LoadUtilisation.Percent, 1)
uls_status = "Clear :)" if utilisation < max_utilization else "Not Clear :("
sheet1["D" + str(x)] = utilisation
sheet1["E" + str(x)] = uls_status
x += 1
workbook.save("loads.xlsx")
except FileNotFoundError:
print("file not found")
except Exception as e:
print("Error occured: ", e)