Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Collection for surfaces with python 1

Status
Not open for further replies.

BJI

Mechanical
Feb 3, 2017
318
I am looking to combine surfaces using python but I can't seem to simply add them like I would for faces and cells to create a region. I can use SurfaceByBoolean but I can't find any way around adding each surface manually. Since the number of parts vary, the number of surfaces vary and using findAt at the assembly level would be too tedious and I would like to be able to use the surface created in the part level, then loop through and add these all to the boolean. I am thinking there must be an easier way to combine surfaces but currently haven't had much luck.

Any ideas would be much appreciated.
Cheers.
 
Replies continue below

Recommended for you

Just collect them in a list and use that list as tuple afterwards.

Here is a similar example at assembly level.

Code:
from abaqus import *
from abaqusConstants import *
from caeModules import *

a = mdb.models['Model-1'].rootAssembly

all_surfs = []
for i in mdb.models['Model-1'].rootAssembly.surfaces.keys():
	all_surfs.append(a.surfaces[i])

a.SurfaceByBoolean(name='Surf-merge', surfaces=tuple(all_surfs))
 
Thanks, worked well using the tuple. For another case, if I choose to use getClosest instead of findAt, then I get a dictionary object which I can convert to a list of just the faces (e.g. tempList=[tempDict[0][0],tempDict[1][0],.. etc) but when I use the surface method I can't seem to use the tuple approach to do the same thing. Does this work differently? The nice part of findAt is that it returns a sequence, even for a single selection, so the results can be added directly. Is there a way to get a type sequence or is this really stored as a mask?

Python:
region=a.Surface(side1Faces=tuple(tempList), name='Surf')

This returns feature creation failed, no additional information. I have check the input is a tuple of the required faces.
 
Check that each entry of this list is referenced the way it is required. So print the entries of the list in my example and check if the printout in your example is similar.
 
I have the SurfaceByBoolean working, similar to your example. However, I also need to create a surface from faces but I think I will need to manually create a sequence since I am not using findAt. I have checked the references for my faces and they seem to be identical to the output created by Abaqus (i.e. the coordinates are not included, only the face key), the only difference that I can see is that one is a sequence of faces and the other is a tuple of faces.

I don't have access to check yours now but isn't it a slightly different example?
 
I did have a look at yours again and it is a list of named surfaces. This is the same as I used for the boolean and it works fine.

To create a surface from faces with Abaqus it is a sequence of face IDs, which is the same as what I am extracting from the dictionary object getClosest. I have checked the manual and my inputs many times and it appears to be correct, the only thing that is different is the type 'sequence' which I don't have. I can't really find any documentation on manually creating a sequence, but hopefully there is a simpler approach.

In the interim, I calculated the precise points on my curved geometry and used findAt without any issues. Would still be good to get the other methods working though.

Thanks for the assistance.
 
I'm not sure I understand the problem you have. Just take the output of getClosest(), create a surface with that and repeat+merge when you have more than one.

Here is an example with three coordinates/surfaces on a simple block:

Code:
from abaqus import *
from abaqusConstants import *
from caeModules import *

coord1 = (10.0,0.1,15.0)
coord2 = (10.0,-2.0,21.0)
coord3 = (14.0,-2.0,15.0)


p = mdb.models['Model-1'].parts['block']
f = p.faces
s1 = f.getClosest(coordinates=(coord1,))
s2 = f.getClosest(coordinates=(coord2,))
s3 = f.getClosest(coordinates=(coord3,))

surf1 = f[s1[0][0].index:s1[0][0].index+1]
p.Surface(side1Faces=surf1, name='Surf-coord1')

surf2 = f[s2[0][0].index:s2[0][0].index+1]
p.Surface(side1Faces=surf2, name='Surf-coord2')

surf3 = f[s3[0][0].index:s3[0][0].index+1]
p.Surface(side1Faces=surf3, name='Surf-coord3')

"""
# check coordinates with datum points
p.DatumPointByCoordinate(coords=coord1)
p.DatumPointByCoordinate(coords=coord2)
p.DatumPointByCoordinate(coords=coord3)
"""

all_surfs = []
for i in p.surfaces.keys():
	all_surfs.append(p.surfaces[i])

p.SurfaceByBoolean(name='Surf-merge', surfaces=tuple(all_surfs))
 
Thanks, as I thought the issue was converting the output to a sequence per your code below. I couldn't find anything in general python or Abaqus documentation about this. Much appreciated.

Code:
f[s1[0][0].index:s1[0][0].index+1]

The below is the application for an assembly. Last question, if you want the full dictionary (s in example below) converted to a sequence, and assuming the number of items are variable or impractical to list one at a time, could the lines creating surf1, surf2 and surf3 be simplified to create one variable containing the full sequence surf1+surf2+surf3?

Code:
coord1 = (10.0,0.1,15.0)
coord2 = (10.0,-2.0,21.0)
coord3 = (14.0,-2.0,15.0)

a = mdb.models['Model-1'].rootAssembly
f = a.instances['Part-1'].faces
s = f.getClosest(coordinates=(coord1, coord2, coord3, ))

surf1 = f[s[0][0].index:s[0][0].index+1]
surf2 = f[s[1][0].index:s[1][0].index+1]
surf3 = f[s[2][0].index:s[2][0].index+1]
a.Surface(side1Faces=surf1+surf2+surf3, name='Surf-New')
 
You should change the way A/CAE reports the geometry in the .rpy. This allows to see directly the way the indexes are used. Enter those commands in the CLI to change the reporting. Or use them in an Abaqus environment variable to have it always active. But it will reduce performance a bit.

Code:
session.journalOptions.replayGeometry
session.journalOptions.setValues(replayGeometry=INDEX)


It is not hard to make the script flexible for any number of coordinates. Below is my previous example adopted to this.
Use the CLI to develop the next steps of a script. Use print and type() to get information and TAB to check the next options in the Abaqus objects.

Code:
from abaqus import *
from abaqusConstants import *
from caeModules import *

mycoords = (
(10.0,0.1,15.0),
(10.0,-2.0,21.0),
(14.0,-2.0,15.0))


p = mdb.models['Model-1'].parts['block']
f = p.faces
s = f.getClosest(coordinates=mycoords)
#print s

for a,i in enumerate(s.values()):
	surfx = f[i[0].index:i[0].index+1]
	p.Surface(side1Faces=surfx, name='Surf-'+str(a+1))


"""
# check coordinates with datum points
for i in mycoords:
	p.DatumPointByCoordinate(coords=i)
"""

all_surfs = []
for i in p.surfaces.keys():
	all_surfs.append(p.surfaces[i])

p.SurfaceByBoolean(name='Surf-merge', surfaces=tuple(all_surfs))
 
I was using the CLI to work though it but had set the journal to coords not index. Thanks for the assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor