Adams Python Interface
Adams Python Interface는 Adams View command language의 대안으로 Python 언어를 사용해 Adams와 상호작용할 수 있게 해주는 Python API다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.5].
정의·용도
Adams Python Interface는 Adams의 modeling object를 생성·수정할 수 있는 Python API(Application Programming Interface)이다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.5]. Python은 범용 객체지향(object-oriented) 스크립팅 언어이며, 이 interface는 Adams의 각 entity가 properties와 methods를 가진 Python class에 매핑되는 “object oriented” 방식으로 개발되었다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.5].
Adams Python Interface는 다음과 같은 방식으로 사용할 수 있다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.5]:
- Adams View에서 Python script를 import
- Adams View command window에서 Python 명령 집합을 실행
- Adams command line에 Python script 이름을 지정해 batch mode로 실행
- Adams View command line은 Python 통합 개발 환경(IDE)에서 가능한 연산도 지원
형식 / 구문
객체 생성과 조회 (Creation and lookup of objects)
Adams용 Python script를 작성할 때 자주 수행하는 작업은 object 생성, 생성된 object의 lookup, object property 수정이다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.12]. Adams python API 문서에는 object manager와 property의 전체 목록이 정리되어 있다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.12].
Manager는 Python dictionary처럼 iterable하며, dictionary와 마찬가지로 manager를 순회하면 child object의 이름인 key를 순회한다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.13]. 예를 들어 part.Markers.keys() 로 marker 이름 목록을, part.Markers.values() 로 marker 객체 목록을 얻는다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.13].
시작 시 Python script 실행 (Running a Python script at startup)
Adams View 시작 시 Python script를 실행하는 두 가지 방법이 있다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.11]:
PYTHONSTARTUP환경 변수를 Python script의 전체 경로로 설정한다. 읽을 수 있는 Python 파일 경로가 주어지면 Adams View 실행 시 aview.cmd 시작 파일 이후 해당 파일의 Python 명령이 실행되며, 대화형 명령과 동일한 namespace에서 실행되어 그 안에서 정의·import된 Adams View object를 대화형 세션에서 사용할 수 있다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.11].- 작업 디렉터리의 aview.cmd 파일에
run_python_code를 사용하는 라인을 넣어 지정한 Python 파일을 실행한다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.11].
cmd 스크립트와의 혼용
cmd 스크립트 안에서 cmd 명령과 adamspy(Adams Python Interface) 명령을 혼용할 수 있다 [Adams_2024.1_Adams_View_Command_User_Guide.pdf p.1195]. language switch_to python 명령은 이후 명령이 adamspy 명령임을 나타내며, adamspy에서 cmd로 다시 전환하려면 adamspy의 Adams.switchToCmd() method를 사용한다 [Adams_2024.1_Adams_View_Command_User_Guide.pdf p.1195].
사용 예
문자열 slicing 등 Python 기본 데이터 타입 연산을 그대로 사용할 수 있다 [Adams_2023.1_Python_Interface_User_Guide.pdf p.8]:
>>> myString = "This is a string."
>>> myString[:5]
'This '
>>> myString[8:]
'a string.'관련 항목
- View — Adams Python Interface를 import·실행하는 환경
- Solver
- Adams Installation Guide — Linux 등 플랫폼 설치 [Adams_2025.2_Installation_Guide.pdf p.52]
- Adams View Command Language — cmd와 adamspy 혼용
출처
- [Adams_2023.1_Python_Interface_User_Guide.pdf p.5] — Introduction, Python data types
- [Adams_2023.1_Python_Interface_User_Guide.pdf p.8] — Slicing
- [Adams_2023.1_Python_Interface_User_Guide.pdf p.11] — Running a Python script at startup
- [Adams_2023.1_Python_Interface_User_Guide.pdf p.12] — Creation and lookup of objects
- [Adams_2023.1_Python_Interface_User_Guide.pdf p.13] — Managers as iterables
- [Adams_2024.1_Adams_View_Command_User_Guide.pdf p.1195] — Mixing cmd and adamspy
- [Adams_2025.2_Installation_Guide.pdf p.52] — Installing Adams on Linux