Reputation: 11
I have a tuple called E3 containing element numbers, for instance:
(array([ 136, 2593, 3061, 4348], dtype=int64),)
Now, I would like to define the set of these elements.
Until now, I haven't succeeded to do something more "systematic" than
mdb.models['Model-1'].rootAssembly.Set(elements=
mdb.models['Model-1'].rootAssembly.instances['Part-1-1'].elements[E3[0][0]:E3[0][0]+1]+\
mdb.models['Model-1'].rootAssembly.instances['Part-1-1'].elements[E3[0][1]:E3[0][1]+1]+\
mdb.models['Model-1'].rootAssembly.instances['Part-1-1'].elements[E3[0][2]:E3[0][2]+1]+\
mdb.models['Model-1'].rootAssembly.instances['Part-1-1'].elements[E3[0][3]:E3[0][3]+1]
, name='Set-0')
Unfortunately, E3 is variable and usually has an arbitrary and large number of elements, so this is not practical at all.
I would love something like this:
mdb.models['Model-1'].rootAssembly.Set(elements=
mdb.models['Model-1'].rootAssembly.instances['Part-1-1'].elements[E3],
name='Set-0')
but "TypeError: Invalid index type tuple".
Or something like this:
mdb.models['Model-1'].rootAssembly.Set(elements=
mdb.models['Model-1'].rootAssembly.instances['Part-1-
1'].elements[E3[0]], name='Set-0')
but "TypeError: only integer scalar arrays can be converted to a scalar index".
Do you know a systematic way a creating a set from a tuple with element numbers?
Upvotes: 1
Views: 76
Reputation: 924
YES, there is!
You can use SetFromElementLabels
method. This method takes 2 arguments viz. name
and elementLabels
.
Part Level Element Set
If you want to create an element set at the part level, then you can use:
mdb.models[name].parts[name].SetFromElementLabels
# For example:
mdb.models['Model-1'].parts['Part-1'].SetFromElementLabels(
name='part_nset', elementLabels=(136, 2593, 3061, 4348)
)
# 136, 2593, 3061, 4348 --> node number at the part level
Assembly Level Element Set
If you want to create an element set at the assembly level (this is your case), then you can use:
mdb.models[name].rootAssembly.SetFromElementLabels
# For example:
mdb.models['Model-1'].rootAssembly.SetFromElementLabels(
name='instance_nset',
elementLabels=( ('Part-1-1', (136, 2593, 3061, 4348)), )
)
# ('Part-1-1', (136, 2593, 3061, 4348))
# (<instance name>, <tuple of element number in ascending order>)
# You can add element numbers from any number of instances
# --> elementLabels=(('Instance-1', (2,3,5,7)), ('Instance-2', (1,2,3)))
Upvotes: 1