# Sap2000py
Sap2000py is a python module to interact with Sap2000 API
This Demo below shows how to interact with SAP2000 using the Sap2000py library. The project includes complete examples of creating and manipulating SAP2000 models, running analyses, and exporting results to Excel.
## Contents
- [Installation](#installation)
- [Usage](#usage)
- [Setting the Model Path](#setting-the-model-path)
- [Creating and Opening a SAP2000 Project](#creating-and-opening-a-sap2000-project)
- [Model Information](#model-information)
- [Adding Materials and Elements](#adding-materials-and-elements)
- [Analysis](#analysis)
- [Post-processing](#post-processing)
- [Saving and Closing](#saving-and-closing)
- [Dependencies](#dependencies)
## Installation
1. Clone this repository to your local machine.
2. Install the dependencies:
```bash
pip install Sap2000py
```
## Usage
Below are detailed instructions for using `Sap2000pyDemo.py`.
### Setting the Model Path
At the beginning of the script, set the path to your model file:
```python
ModelPath = 'F:\\python\\Sap2000\\Models\\Test.sdb'
```
### Creating and Opening a SAP2000 Project
Create a Sap2000py object and open the SAP2000 program:
```python
from Sap2000py.Saproject import Saproject
Sap = Saproject()
Sap.openSap()
Sap.File.Open(ModelPath)
```
### Model Information
Get basic information about your SAP2000 project:
```python
Sap.getSapVersion()
Sap.getProjectInfo()
Sap.getUnits()
```
Make changes to the model:
```python
# Set the project information with field and value
Sap.setProjectInfo("Author","Gou Lingyun")
Sap.setProjectInfo("Description","This is a test model")
# or you can set project information with a dictionary
Sap.setProjectInfo(info_dict={"Author":"Gou Lingyun","Description":"This is a test model"})
# Set the units of the model
Sap.setUnits("KN_m_C")
```
### Adding Materials and Elements
Add materials and elements to the model:
```python
# Add China Common Material Set·
Sap.Scripts.AddCommonMaterialSet(standard = "JTG")
# Add Joints and Elements
joint_coord = np.array([[0,0,0], [10,0,0], [20,0,0], [30,0,0]])
Sap.Scripts.AddJoints(joint_coord)
Sap.Scripts.AddElements([[1,2], [2,3], [3,4]])
```
### Analysis
Run a modal analysis:
```python
Sap.Scripts.Analyze.RemoveCases("All")
Sap.Scripts.Analyze.AddCases(Casename = ['DEAD', 'MODAL'])
Sap.Scripts.Analyze.RunAll()
```
### Post-processing
Export analysis results to an Excel file:
```python
filename = 'F:\\python\\Sap2000\\Models\\Test.xlsx'
wb = openpyxl.load_workbook(filename)
ws = wb.worksheets[0]
Sap.Scripts.SelectCombo_Case(["DEAD"])
Name, EleAbsForce, __, __ = Sap.Scripts.GetResults.ElementJointForce_by_Group("PierBottom")
Sap.Scripts.writecell(ws, EleAbsForce[:,[2]], "D22")
wb.save(filename)
```
### Saving and Closing
Save the project and close the SAP2000 program:
```python
Sap.File.Save()
Sap.closeSap()
```
## Dependencies
- python>=3.9
This project requires the following Python libraries:
- numpy
- os
- openpyxl
- comtypes>=1.1.11
- itertools
- rich
- loguru
- pathlib
- json
- sectionproperties>=3.3.0
For more information, please check [Sap2000pyDemo.py](./Sap2000pyDemo.py).
Raw data
{
"_id": null,
"home_page": "https://github.com/ganansuan647/Sap2000py",
"name": "Sap2000py",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9.0",
"maintainer_email": null,
"keywords": "Sap2000 API python",
"author": "Lingyun Gou",
"author_email": "17717910647@163.com",
"download_url": "https://files.pythonhosted.org/packages/18/61/871f38ed16e38a33501dadc86898eadfc69269de014df608c56b2e30c679/sap2000py-0.1.3.tar.gz",
"platform": null,
"description": "# Sap2000py\n\nSap2000py is a python module to interact with Sap2000 API\n\nThis Demo below shows how to interact with SAP2000 using the Sap2000py library. The project includes complete examples of creating and manipulating SAP2000 models, running analyses, and exporting results to Excel.\n\n## Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n - [Setting the Model Path](#setting-the-model-path)\n - [Creating and Opening a SAP2000 Project](#creating-and-opening-a-sap2000-project)\n - [Model Information](#model-information)\n - [Adding Materials and Elements](#adding-materials-and-elements)\n - [Analysis](#analysis)\n - [Post-processing](#post-processing)\n - [Saving and Closing](#saving-and-closing)\n- [Dependencies](#dependencies)\n\n## Installation\n\n1. Clone this repository to your local machine.\n2. Install the dependencies:\n\n```bash\npip install Sap2000py\n```\n\n## Usage\n\nBelow are detailed instructions for using `Sap2000pyDemo.py`.\n\n### Setting the Model Path\n\nAt the beginning of the script, set the path to your model file:\n\n```python\nModelPath = 'F:\\\\python\\\\Sap2000\\\\Models\\\\Test.sdb'\n```\n\n### Creating and Opening a SAP2000 Project\n\nCreate a Sap2000py object and open the SAP2000 program:\n\n```python\nfrom Sap2000py.Saproject import Saproject\n\nSap = Saproject()\nSap.openSap()\nSap.File.Open(ModelPath)\n```\n\n### Model Information\n\nGet basic information about your SAP2000 project:\n\n```python\nSap.getSapVersion()\nSap.getProjectInfo()\nSap.getUnits()\n```\n\nMake changes to the model:\n```python\n# Set the project information with field and value\nSap.setProjectInfo(\"Author\",\"Gou Lingyun\")\nSap.setProjectInfo(\"Description\",\"This is a test model\")\n\n# or you can set project information with a dictionary\nSap.setProjectInfo(info_dict={\"Author\":\"Gou Lingyun\",\"Description\":\"This is a test model\"})\n\n# Set the units of the model\nSap.setUnits(\"KN_m_C\")\n```\n\n### Adding Materials and Elements\n\nAdd materials and elements to the model:\n\n```python\n# Add China Common Material Set\u00b7\nSap.Scripts.AddCommonMaterialSet(standard = \"JTG\")\n\n# Add Joints and Elements\njoint_coord = np.array([[0,0,0], [10,0,0], [20,0,0], [30,0,0]])\nSap.Scripts.AddJoints(joint_coord)\nSap.Scripts.AddElements([[1,2], [2,3], [3,4]])\n```\n\n### Analysis\n\nRun a modal analysis:\n\n```python\nSap.Scripts.Analyze.RemoveCases(\"All\")\nSap.Scripts.Analyze.AddCases(Casename = ['DEAD', 'MODAL'])\nSap.Scripts.Analyze.RunAll()\n```\n\n### Post-processing\n\nExport analysis results to an Excel file:\n\n```python\nfilename = 'F:\\\\python\\\\Sap2000\\\\Models\\\\Test.xlsx'\nwb = openpyxl.load_workbook(filename)\nws = wb.worksheets[0]\n\nSap.Scripts.SelectCombo_Case([\"DEAD\"])\nName, EleAbsForce, __, __ = Sap.Scripts.GetResults.ElementJointForce_by_Group(\"PierBottom\")\nSap.Scripts.writecell(ws, EleAbsForce[:,[2]], \"D22\")\n\nwb.save(filename)\n```\n\n### Saving and Closing\n\nSave the project and close the SAP2000 program:\n\n```python\nSap.File.Save()\nSap.closeSap()\n```\n\n## Dependencies\n\n- python>=3.9\n\nThis project requires the following Python libraries:\n\n- numpy\n- os\n- openpyxl\n- comtypes>=1.1.11\n- itertools\n- rich\n- loguru\n- pathlib\n- json\n- sectionproperties>=3.3.0\n\nFor more information, please check [Sap2000pyDemo.py](./Sap2000pyDemo.py).\n",
"bugtrack_url": null,
"license": "GPL Licence",
"summary": "Sap2000 API python interface",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/ganansuan647/Sap2000py"
},
"split_keywords": [
"sap2000",
"api",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f9d11e227c035858495b1876a5fc6ee29e0b0256f8169ec6869ff43133e3e133",
"md5": "e5f058cd900f1f3a915f4fdf7b591035",
"sha256": "83c4f24bad29242d728f040135d6b5708f3be85a054a61ef00b53645bf82b375"
},
"downloads": -1,
"filename": "Sap2000py-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e5f058cd900f1f3a915f4fdf7b591035",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9.0",
"size": 14916,
"upload_time": "2024-08-02T06:59:02",
"upload_time_iso_8601": "2024-08-02T06:59:02.002649Z",
"url": "https://files.pythonhosted.org/packages/f9/d1/1e227c035858495b1876a5fc6ee29e0b0256f8169ec6869ff43133e3e133/Sap2000py-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1861871f38ed16e38a33501dadc86898eadfc69269de014df608c56b2e30c679",
"md5": "ef6b832a506f41ffcc420aa62ababaad",
"sha256": "a6446bed5836f8d6b9bc07e086197babe50ca5148d955370509cda4adcd32b81"
},
"downloads": -1,
"filename": "sap2000py-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "ef6b832a506f41ffcc420aa62ababaad",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9.0",
"size": 15133,
"upload_time": "2024-08-02T06:59:03",
"upload_time_iso_8601": "2024-08-02T06:59:03.429090Z",
"url": "https://files.pythonhosted.org/packages/18/61/871f38ed16e38a33501dadc86898eadfc69269de014df608c56b2e30c679/sap2000py-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-02 06:59:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ganansuan647",
"github_project": "Sap2000py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "sap2000py"
}