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!

Abaqus/Python - commands to find nearest node to a given point

Status
Not open for further replies.

mika3049

Materials
Nov 4, 2016
17
Hi,
I need to write a python comman code to find a node (in a given set), nearest to a given point.
The code now looks as follows:
import sys
sys.path.insert(10,
r'c:/SIMULIA/Abaqus/6.13-3/code/python/lib/abaqus_plugins/findNearestNode')
import nearestNodeModule
nearestNodeModule.hideTextAndArrow()
a = mdb.models['FibreModel'].rootAssembly
n1 = a.instances['Fibre0-1'].nodes
pickedSelectedNodes = n1[0:599]
g=nearestNodeModule.findNearestNode(xcoord=101, ycoord=106, zcoord=58, name='', selectedNodes=pickedSelectedNodes, instanceName="'Fibre2-1'")
ct=g[0]

And I get an error:
File "SMAPyaModules\SMAPyaPluginsPy.m\src\abaqus_plugin s\findNearestNode\nearestNodeModule.py", line 71, in findNearestNode
AttributeError: 'NoneType' object has no attribute 'instances'

Does anyone know what is wrong there?

Leon
 
Replies continue below

Recommended for you

The name argument is empty. And the instanceName argument looks also strange.


I made a simple test and it worked with
nearestNodeModule.findNearestNode(xcoord=31, ycoord=0, zcoord=17, name='Job-1.odb')

and
nearestNodeModule.findNearestNode(xcoord=31, ycoord=0, zcoord=17, name='Job-1.odb', instanceName='block-1')
 
Thank you very much. Yes, it is probably correct - the problem might be with "name" argument. But this code is a part of a large code of CAE model generation. So, no ODB file exists when I run this PY file at Abaqus. What should I then place in name?
 
This worked too in my example:
nearestNodeModule.findNearestNode(xcoord=31, ycoord=0, zcoord=17, name='')

Be sure to use two ' instead of one ".
 
Thank you very much. in fact, it is quite strange. Sometime, the code gives an error:
File "SMAPyaModules\SMAPyaPluginsPy.m\src\abaqus_plugins\findNearestNode\nearestNodeModule.py", line 71, in findNearestNode
AttributeError: 'NoneType' object has no attribute 'instances.

But sometimes it works.
The code is given below.
I tried both sinlge and double quota marks, it did not change much.

-----------------------------------------
import sys
sys.path.insert(30,
r'c:/SIMULIA/Abaqus/6.13-3/code/python/lib/abaqus_plugins/findNearestNode')
import nearestNodeModule
session.viewports['Viewport: 1'].assemblyDisplay.setValues(mesh=ON)
session.viewports['Viewport: 1'].assemblyDisplay.meshOptions.setValues(
meshTechnique=ON)
nearestNodeModule.hideTextAndArrow()
a = mdb.models['FibreModel'].rootAssembly
n1 = a.instances['Fibre0-1'].nodes
pickedSelectedNodes = n1[0:599]
g=nearestNodeModule.findNearestNode(xcoord=200, ycoord=220, zcoord=230, name='',
selectedNodes=pickedSelectedNodes, instanceName="'Fibre0-1'")
ct=g[0]
setName='Set-'+str(ct)
p = mdb.models['FibreModel']
setName='Set-'+str(ct)
p.rootAssembly.Set(name=setName, nodes=p.rootAssembly.instances['Fibre0-1'].nodes[ct-1:ct])
a = mdb.models['FibreModel'].rootAssembly
region1=a.sets['Sta1']
a = mdb.models['FibreModel'].rootAssembly
region2=a.sets['Set-281']
mdb.models['FibreModel'].Coupling(name='Constraint-18', controlPoint=region1,
surface=region2, influenceRadius=WHOLE_SURFACE, couplingType=KINEMATIC,
localCsys=None, u1=ON, u2=ON, u3=ON, ur1=OFF, ur2=OFF, ur3=OFF)
 
My purpose is to write a Fotran code which output is this Python comman file. However, while the code works sometime when I copy/paste it from text, the Fortran produced PY file gives always the error.
 
I guess the problem is here:
instanceName="'Fibre0-1'"

Try
instanceName='Fibre0-1'
 
I tried, it didnt work. But when I add in the "name=" the ODB file, it works (although it is wrong file, and the command gives wrong results).
Can it be that this command works only with ODB files, and, thus can not help to build CAE file via Python code?
 
I made a simple test: Just started /CAE, created a block, meshed it and created a instance. No odb opened. Still this worked:
nearestNodeModule.findNearestNode(xcoord=1, ycoord=0, zcoord=0, name='')
 
Thank you. Indeed, now my PY file runs also. I still dont understand why it did not run before, and started now. Anyway, thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor