Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Read point list from a CSV file in Abaqus

Status
Not open for further replies.

SM1994

Bioengineer
Mar 25, 2020
49
Hello
I am trying to generate a Path in abaqus using a script, but instead of feeding the path as coordinate manually, I want abaqus read a CSV file and generate a path based on that, but I get the following error:
TypeError: expression;found 'file', expecting a recognized type filling string dict.
I understand the script does not recongnize the input file, but I do not know how should I modify it?
The CSV file is attached.

error happens in:

session.Path(name='point_list', type=POINT_LIST, expression=Data)

Thanks for your help in advance.


Code:
.setValues(
	 #   displayedObject=session.odbs['C:/temp/Job-6.odb'])
pressure_range={170e-3,70e-3,20e-3,120e-3}
void_range={2,4,6,8,10,12,14,16,17}
Thickness_range={8,12,16,20}

#pressure_range={20e-3}
#void_range={2}
#Thickness_range={8}

i=0
for void in void_range:
	for Thickness in Thickness_range: 
   
		for Pressure_mag in pressure_range:
			pressure_name=Pressure_mag*1000
			pressure_name= int(pressure_name)
			void_name=int(void)
			Thickness_name=int(Thickness)
			i=i+1
			J_name='Job-'+str(i)+'Void_size'+str(void_name)+'mm'+'Thickness'+str(Thickness_name)+'mm'+str(pressure_name)+'Kpa_ogd'
		   

			ParentDir='W:/Saeed M/Abaqus results from NESI/1D_Model_3/Ver5/Model_3_ver5'+'/'
			JobDir=J_name+'/'+J_name+'.odb'
			JobDirectory=ParentDir+JobDir
			CSV_name=J_name+'.csv'
			CSVreadpath='W:/Saeed M/Abaqus results from NESI/1D_Model_3/Ver5/Model_3_ver5'
			#file=open(CSVreadpath,"r")
			with open ('Data.csv','r') as csv_file:
				Data=csv.reader (csv_file)
			




			o1 = session.openOdb(
				name=JobDirectory)
			session.viewports['Viewport: 1'].setValues(displayedObject=o1)
			session.Path(name='point_list', type=POINT_LIST, expression=Data)
			   





				


			#----------------------------------------------- is the proposed method for automatically save the excel files---------
			# Information obrained from: [URL unfurl="true"]https://www.eng-tips.com/viewthread.cfm?qid=391617[/URL]
			session.viewports['Viewport: 1'].odbDisplay.setPrimaryVariable(
					variableLabel='U', outputPosition=NODAL, refinement=(INVARIANT, 
					'Magnitude'), )

			xyp = session.xyPlots['XYPlot-1']
			chartName = xyp.charts.keys()[0]
			chart = xyp.charts[chartName]
			pth = session.paths['point_list']

			xy1 = xyPlot.XYDataFromPath(path=pth, includeIntersections=False, 
				projectOntoMesh=False, pathStyle=PATH_POINTS, numIntervals=10, 
			  projectionTolerance=0,   shape=UNDEFORMED, labelType=TRUE_DISTANCE)
			c1 = session.Curve(xyData=xy1)
			chart.setValues(curvesToPlot=(c1, ), )
			session.viewports['Viewport: 1'].setValues(displayedObject=xyp)
			session.xyPlots[session.viewports['Viewport: 1'].displayedObject.name].setValues(
				transform=(0.49697, 0, 0, -0.304173, 0, 0.49697, 0, -0.174628, 0, 0, 
				0.49697, 0, 0, 0, 0, 1))
			pth = session.paths['point_list']
			D=session.XYDataFromPath(name='Job_data', path=pth, includeIntersections=False, 
				projectOntoMesh=False, pathStyle=PATH_POINTS, numIntervals=10, 
				projectionTolerance=0, shape=UNDEFORMED, labelType=TRUE_DISTANCE)
			session.xyPlots[session.viewports['Viewport: 1'].displayedObject.name].setValues(
				transform=(0.704961, 0, 0, -0.0658641, 0, 0.704961, 0, -0.169147, 0, 0, 
				0.704961, 0, 0, 0, 0, 1))
			import sys
			#sys.path.insert(9, 
			  #  r'c:/SIMULIA/Abaqus/6.14-2/code/python2.7/lib/abaqus_plugins/excelUtilities')
			#import abq_ExcelUtilities.excelUtilities
			#abq_ExcelUtilities.excelUtilities.XYtoExcel(xyDataNames='Job_data', 
			 #   trueName='From Current XY Plot')
			#: XY Data sent to Excel
			#odb = session.odbs['C:/SIMULIA/Temp/Job-5.odb']
			#session.viewports['Viewport: 1'].setValues(displayedObject=odb)
			#session.viewports['Viewport: 1'].odbDisplay.display.setValues(plotState=(
			 #   CONTOURS_ON_DEF, ))


			import win32com.client
			from win32com.client import constants

			#xl = win32com.client.Dispatch("Excel.Application") #Fetch the application and assign it to a variable. You can now interact with excel using python/VBA.
			#xl.DisplayAlerts=False #Get rid of popup alerts that will prevent some scripts from running.
			#xl.Visible = 1 #Shows the excel app window, useful if you want to mess around issuing commands from the Abaqus GUI and observing what happens in the workbook.
			#xlBook = xl.Workbooks.Add() #Similar to what Abaqus does, creates a 'Book1'.
			#xlSheet = xlBook.Sheets(1) #Access a worksheet
			#xlSheet.Cells(1,1).Value  #Modify cell contents.
			#xlBook.SaveAs(Filename='Name', FileFormat='Format') #Here is the save command you were looking for.
			#xlBook.SaveAs("C:/test.xls")


			#x0 = session.xyDataObjects['S:Mises PI: PART-1-1 E: 4309 IP: 1']
			session.writeXYReport(fileName=CSV_name, xyData=(D, ))]



 
Replies continue below

Recommended for you

Create a small example and attach it together with the csv file and the script. Reduce the script to only the things that are not working.
 
Hello
I have made and example code (attached), I need to read the attached CSV file and assign it to a variable\reading section names "expression" in the last line, python wise it should work, but abaqus compiler does not recognise it.
The problem is in the last line of the code.
Thanks.
 
 https://files.engineering.com/getfile.aspx?folder=7e245a15-851a-4797-87c4-58ef3f5ce1ee&file=Engtips.rar
When you want to automate things in Abaqus, then you should do it in the GUI and then look into .rpy for the Python command. Afterwards you can use them with your own data.

Here is a script that can read data from a csv and modifies them in a way, that they are the Abaqus expects them. Uncomment the print statements to see what the commands do.

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

with open('points.csv') as f:
	x = csv.reader(f)
	data = list(x)

#print data

for k,x in enumerate(data):
	for i,j in enumerate(x):
		x[i] = float(j)
	data[k] = tuple(x)

#print data
data = tuple(data)
#print data


session.Path(name='Path-x', type=POINT_LIST, expression=data)

# original Abaqus command:
#session.Path(name='Path-1', type=POINT_LIST, expression=((0.0, 0.0, 0.0), (5.0, 
#    -2.0, 8.0), (10.0, -3.5, 16.0), (15.0, -5.0, 20.0)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor