简体   繁体   中英

How to read data from a CSV file in Abaqus/Python scipting

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? I tried to store my CSV Data into Data.csv and when I want to read it in the script I face the error, and error points to the following line:

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

The complete code is:

'''
 from abaqus import *
 from abaqusConstants import * 
 import __main__

 #def Macro2():




import section
import regionToolset
import displayGroupMdbToolset as dgm
import part
import material
import assembly
import step
import interaction
import load
import mesh
import optimization
import job
import sketch
import visualization
import xyPlot
import displayGroupOdbToolset as dgo
import connectorBehavior
import numpy as np
import job
import math
import os
import shutil
import csv
import sys

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}


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)

'''

As @Anbu mentioned, csv.reader does not return what you are expecting. It returns a line reader iterator. You have to use the iterator even if you just have one line.

If you do just want to read the first line (exactly with 3 values), you can do something like:

with open('Data.csv', 'r') as csv_file:
    data = tuple(float(x) for x in next(csv.reader(csv_file)))

In this snippet, next returns the value of the first iteration of your csv.reader , and the conversion to Tuple[float] is required for Abaqus.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM