如何在使用 python 在 abaqus 中编写脚本时比较类型

How to compare type while scripting in abaqus with python

我正在尝试比较 abaqus 对象的类型,但它不起作用。一个想法?

>>> m = mdb.models['Model-1']
>>> type(m)
<type 'Model'>
>>> type(m) == Model
NameError: name 'Model' is not defined

我想要那些类型的比较或许多其他对象,而不仅仅是模型

我试过了:

>>> import Model
ImportError: No module named Model
>>> type(m) == mdb.models.Model
AttributeError: 'Repository' object has no attribute 'Model'

确认Python的built-in数据类型很容易,因为它们是built-in,我们不需要导入它们。例如

a = []
type(a) == list  # similar for other built-in python data types

但是,Abaqus 数据类型不是 built-in。因此,我们必须从各自的模块中导入以比较它们。以下是 ModelPart 数据类型的示例。

# importing the modules
import abaqus as ab  # just for demonstation I'm importing it this way
import part as prt

# accessing the model and part objects
myModel = ab.mdb.models['Model-1']
myPart = myModel.parts['Part-1']

#checking the data types
type(myModel) == ab.ModelType  # Model is imported from Abaqus module
type(myPart) == prt.PartType   # Part is imported from Part module

# you can use 'isinstance()' method also
isinstance(myModel, ab.ModelType)  # Model is imported from Abaqus module
isinstance(myPart, prt.PartType)   # Part is imported from Part module