Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating sets using the Python API

Status
Not open for further replies.

DrBwts

Mechanical
Nov 4, 2012
297
I created a simple box and meshed it & I would like to create 2 sets one that contains the central elements & a second that contains all the surrounding elements.

I can calculate quite trivially which elements I want in each set but I'm having problems creating the sets. I created a few sets in CAE and then inspected the *.jnl files to find the method but I just don't understand what I'm seeing, for instance,

Python:
mdb.models['Model-1'].parts['Part-1'].Set(elements=mdb.models['Model-1'].parts['Part-1'].elements.getSequenceFromMask(mask=('[#0:10 #4 #0:3 #12 ]', ), ), name='Set-1')

The above is what I get when I manually select elements in the CAE window, the numbers in no way match up with the element numbers that I picked.

I've been pouring over the Reference Manual but so far cant find a set generator method where I can just list the element numbers. I'm pretty sure there is one though.

Thanks
 
Replies continue below

Recommended for you

You have to change the /CAE python journal settings to INDEX.
Place the code below in a abaqus_v6.env, restart /CAE and create the set again. Now your .rpy file should look a bit different.

Code:
def onCaeStartup():
    session.journalOptions.replayGeometry
    session.journalOptions.setValues(replayGeometry=INDEX)
 
Unfortunately I dont have admin rights on this computer to do that.
 
Place the file in your work directory to get these options at least there.
 
do you mean put a copy of the amended abaqus_V6.env in my working directory?

I just tried that but it hasnt change the output in the *.jnl file. Its still using 'elements.getSequenceFromMask'

 
Try to create a new empty text file in your work directory. Add my code, save the file and then rename it to abaqus_v6.env. Then restart /CAE in that directory and try again.
 
Tried it, no luck, still the same.
 
I found the following method,

Python:
mdb.models['Model-1'].parts['Part-1'].Set(elements=mdb.models['Model-1'].parts['Part-1'].elements.getFromLabel(1, 2, 3, 4, ), name='testing')

Which gives the following error,

TypeError: too many arguments; expected 1, got 4

So I tried,

Python:
elList = [1,2,3,4]
mdb.models['Model-1'].parts['Part-1'].Set(elements=mdb.models['Model-1'].parts['Part-1'].elements.getFromLabel(elList), name='testing')

Which gave the error,

TypeError: arg1; found tuple, expecting int

So then I tried,

Python:
mdb.models['Model-1'].parts['Part-1'].Set(elements=mdb.models['Model-1'].parts['Part-1'].elements.getFromLabel(1), name='testing')

Which gave the following error,

TypeError: elements; found MeshElement, expecting tuple

Puzzling...
 
See Scripting Reference Guide 45.4.5 SetFromElementLabels()
 
Thanks Mustaine very much appreciated.
 
Just one more thing, would you know where there is a list of available internal variables for the API?

eg number of elements, how to access lists of elements in each set etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor