'How to compare type while scripting in abaqus with python

I'm trying to compare type of abaqus object, but it doesn't work. An idea ?

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

I want those type of comparison or many other object, not only Model

I tried :

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


Solution 1:[1]

It is easy to confirm the Python's built-in data type, because as they are built-in, we don't need to import them. For ex.

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

However, Abaqus data types are not built-in. Hence, we must import then from respective modules to compare them. Following is the example for Model and Part data types.

# 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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Satish Thorat