AI SHEET: /blog/grasshopper调用sap2000-api教程文档1/ REV: 2026-06-25

Grasshopper calls SAP2000 API tutorial document (1)

Zhou Wenqi (Venchy) 13 min read

Grasshopper calls SAP2000 API tutorial document (1)

Official Account: Non-Deconstructive · Author: Zhou Wenqi (Venchy)

1. Grasshopper calls SAP2000 API tutorial

1.1. SAP2000 API

1.1.1. SAP2000 API Overview

1.1.1.1. API basic associated files:

python/C#:C:\Program Files\Computers and Structures\SAP2000 22\SAP2000v1.dll VBA:C:\Program Files\Computers and Structures\SAP2000 22\SAP2000v1.tlb API documentation: C:\Program Files\Computers and Structures\SAP2000 22\CSI_OAPI_Documentation.chm Note: The SAP2000v1.dll and SAP2000v1.tlb files here need to be configured separately according to different SAP2000 versions.

1.1.1.2. Development environment configuration----Python

Install comtypes library pip install comtypes Two ways for Python to call SAP2000: (1) Get the currently running SAP2000 object import os import sys import comtypes.client SapObject = comtypes.client.GetActiveObject(“CSI.SAP2000.API.SapObject”) SapModel = SapObject.SapModel (2) Create a new SAP2000 object import os import sys import comtypes.client import comtypes

helper = comtypes.client.CreateObject(‘CSiAPIv1.Helper’) mySapObject = helper.CreateObject(r”C:\Program Files\Computers and Structures\SAP2000 22\SAP2000.exe”)

mySapObject = helper.CreateObjectProgID(“CSI.SAP2000.API.SapObject”)

mySapObject.ApplicationStart() SapModel = mySapObject.SapModel Note: To obtain progid, enter regedit into the registry and search under HKEY_LOCAL_MACHINE\SOFTWARE\Classes

1.1.1.3. Development environment configuration----C#

(1) Get the currently running SAP2000 object using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using SAP2000v1; namespaceSAP2000 { classProgram     { staticvoidMain(string[] args)         {             cOAPI mySapObject = null;             mySapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject(“CSI.SAP2000.API.SapObject”);             cSapModel sapModel = mySapObject.SapModel;         }     } } (2) Create a new SAP2000 object using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using SAP2000v1; namespaceSAP2000 { classProgram     { staticvoidMain(string[] args)         {             cHelper myHelper;             myHelper = new Helper();             cOAPI mySapObject = null;             mySapObject = myHelper.CreateObject(@“C:\Program Files\Computers and Structures\SAP2000 22\SAP2000.exe”); //or //mySapObject = myHelper.CreateObjectProgID(“CSI.SAP2000.API.SapObject”);             mySapObject.ApplicationStart();             cSapModel mySapModel;             mySapModel = mySapObject.SapModel;             mySapModel.InitializeNewModel((eUnits.kip_in_F));         }     } }

1.1.2. SAP2000 API simple case

Use python to call SAP2000 to analyze a beam with a span of 6m import os import sys import comtypes.client

defCaculation(SapModel,depth,force_z):

New SAP2000 model

    SapModel.InitializeNewModel()     ret = SapModel.File.NewBlank()

define material

    SapModel.PropMaterial.AddMaterial(“C40”,2,“China”,“GB”,“GB50010 C40”)

define section

    SapModel.PropFrame.SetRectangle(“Frame”,“C40”,depth,400)

Build model

    SapModel.FrameObj.AddByCoord(0,0,0,3000,0,0,“element1”,“Frame”,“element1”)     SapModel.FrameObj.AddByCoord(3000,0,0,6000,0,0,“element2”,“Frame”,“element2”)

Add constraints

    s_Point1=""     e_Point1=""     [s_Point1,e_Point1,ret]=SapModel.FrameObj.GetPoints(“element1”,s_Point1,e_Point1)

    s_Point2=""     e_Point2=""     [s_Point2,e_Point2,ret]=SapModel.FrameObj.GetPoints(“element2”,s_Point2,e_Point2)

    R=[True,True,True,True,True,True]     SapModel.PointObj.setRestraint(s_Point1,R)     SapModel.PointObj.setRestraint(e_Point2,R)

Add load

    SapModel.LoadPatterns.Add(“Live”,3)     Load=[0,0,force_z,0,0,0]     SapModel.PointObj.SetLoadForce(e_Point1, “Live”, Load)

Save model

    path=r’D:\2021\study\07-grasshopperTutorial\example_01\test01.sdb’     SapModel.File.Save(path)

    SapModel.Analyze.RunAnalysis()

Extract results

    SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput()     ret = SapModel.Results.Setup.SetCaseSelectedForOutput(“Live”)     NumberResults=0     Obj, Elm, LoadCase, StepType, StepNum, F1, F2, F3, M1, M2, M3=[],[],[],[],[],[],[],[],[],[],[]     [NumberResults, Obj, Elm, LoadCase, StepType, StepNum, F1, F2, F3, M1, M2, M3,ret] = SapModel.Results.JointReact(s_Point1, 0, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, F1, F2, F3, M1, M2, M3)     print(F1)     print(F2)     print(F3)

Get SAP2000 object

mySapObject = comtypes.client.GetActiveObject(“CSI.SAP2000.API.SapObject”) SapModel = mySapObject.SapModel depths=[500,600,700,800] force_zs=[1000,2000,3000,4000] for i,depth in enumerate(depths):     force_z=force_zs[i]     Caculation(SapModel,depth,force_z)

We at Non-Deconstruction have always focused on the organic integration of architectural art and structural technology.While we are doing a good job in design, we have always paid attention to the application of cutting-edge technologies such as digitalization and intelligence in the architectural design industry. We have been exploring and practicing these years.

We very much welcome outstanding people to join us, cross boundaries together, and become a slash youth who promotes the development of the industry.

Non-deconstruction | Recruitment of cross-border architects Non-deconstruction | Recruitment of cross-border structural engineers Non-deconstruction | Algorithm Engineer Recruitment Structural cross-border intern recruitment

In recent years, more and more friends are interested in parametric design. Our parametric design exchange group has grown to 5 groups. More friends are welcome to join and communicate and learn from each other.

Image

Add our “Da Feier” WeChat, Join the parametric design exchange group.

Image

If you don’t know us, you can come to make up lessons. Non-deconstruction | Digital technology helps explore new space for structural design Non-deconstruction | Discussion on the technical path of parametric architectural design Non-deconstruction | In-depth thinking on BIM workflow When structural design meets genetic algorithms When an architect dumps me a Rhino model (1) When an architect throws me a rhino model (2) Yingjianke, secondary development PKPM, secondary development

Image


This document is automatically collected and organized by AI from non-deconstructed public accounts and is for learning reference only.

#wechat

Original Source: https://mp.weixin.qq.com/s/3guGjat6eM2VqU3vundoMw

§

评论

COMMENT / REVIEW REQUIRED

LOADING…