Skip to main content

intro

Introduction to SAP2000 Open Application Programming Interface (OAPI)​

Overview​

The SAP2000 Open Application Programming Interface (OAPI) is a powerful tool that allows engineers to automate, customize, and extend the functionality of SAP2000. By leveraging OAPI, users can programmatically interact with SAP2000 models, enabling advanced analyses, batch processing, and integration with other software.

Key Features​

  1. Model Creation and Modification
    Automate the creation and modification of structural models, including defining nodes, elements, loads, and constraints.

  2. Data Access
    Extract results and data directly from SAP2000 for use in external analysis or reporting.

  3. Customization
    Create custom workflows, scripts, and plugins to enhance productivity and address unique project requirements.

  4. Integration
    Link SAP2000 with other software and tools, such as Excel, MATLAB, or Python, to streamline workflows.

Requirements​

  • Software: SAP2000 installed on the machine.
  • License: Ensure the SAP2000 license includes access to the OAPI.
  • Development Environment: Any environment that supports COM-based programming, such as:
    • Microsoft Excel (VBA)
    • Visual Basic .NET
    • C#
    • Python (with libraries like comtypes)

Getting Started​

  1. Enable OAPI
    Ensure OAPI is enabled in SAP2000. This can typically be done via the software settings or during installation.

  2. Reference the SAP2000 OAPI
    In your development environment, add a reference to the SAP2000 OAPI. For example, in Visual Studio:

    • Go to Project > Add Reference....
    • Select the SAP2000v1.dll file from the SAP2000 installation directory.
  3. Basic Structure of a Program Every OAPI program follows these basic steps:

    • Initialize and connect to SAP2000.
    • Create or open a model.
    • Perform operations (e.g., add elements, apply loads, run analysis).
    • Extract results and close the session.

Example Code​

Below is a simple example in Python using the comtypes library to create a new SAP2000 model and add a simple frame.

import comtypes.client

# Start SAP2000
sap_app = comtypes.client.CreateObject("CSI.SAP2000.API.SapObject")
sap_app.ApplicationStart()

# Connect to the model
sap_model = sap_app.SapModel

# Initialize a new model
sap_model.InitializeNewModel()
sap_model.File.NewBlank()

# Add a frame
sap_model.PointObj.AddCartesian(0, 0, 0)
sap_model.PointObj.AddCartesian(0, 0, 10)
frame_name = sap_model.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10)

# Run the analysis
sap_model.Analyze.RunAnalysis()

# Close SAP2000
sap_app.ApplicationExit(False)

Commonly Used Classes​

  • cSapModel
    The main class for interacting with a SAP2000 model.
  • PointObj
    Used to define and manage joints.
  • FrameObj
    Used to create and manipulate frame elements.
  • LoadCases and LoadPatterns
    Define and manage loads and load combinations.

Documentation and Resources​

  • SAP2000 OAPI Documentation: The official API documentation is available in the SAP2000 installation directory. It provides detailed descriptions of all available functions and classes.
  • CSI Knowledge Base: Visit the CSI Knowledge Base for additional resources, examples, and troubleshooting.

Tips for Beginners​

  1. Start Simple: Begin with small scripts to understand the API structure.
  2. Explore the Documentation: The API documentation is the ultimate reference for available methods and properties.
  3. Use Examples: Study example scripts provided in the SAP2000 installation directory or online forums.
  4. Debugging: Use logging and step-by-step debugging to identify issues in your scripts.

By using the SAP2000 OAPI effectively, you can significantly enhance your workflow efficiency and unlock new possibilities in structural analysis and design.