This blog describes how to create 2D sketch (then the part) from .txt file that contains coordinates. Make sure that the given .txt file is available in the set working directory.The commands are in pink and comments are in blue.
This script is adapted from the example script given in the Scripting User’s Manual
The text file for the coordinates were generated from MATLAB® for my problem
# import commands to get library file stored in abaqus
from abaqus import * from abaqusConstants import * backwardCompatibility.setValues(includeDeprecated=True, reportDeprecated=False) import sketch import part # creating variables by calling the constructors myModel = mdb.Model(name='Model A') mySketch = myModel.ConstrainedSketch(name='Sketch A', sheetSize=200.0) lines = open('redmodel.txt', 'r').readlines() # give your text file here # readlines() function reads all lines from the given .txt file pointList = [] # Creating empty array for line in lines: # reading line by line and performing action pointList.append( eval( '(%s)' % line.strip() ) )
# strip() func removes all the white spaces from a line. eval() function which evaluates # a string as though it were an expression and returns a result and append adds each # coordinate as last element of array
for i in range(len(pointList)-1): mySketch.Line(point1=pointList[i], point2=pointList[i+1]) # Above for loop will help in connecting the coordinates in the sequence myPart = myModel.Part(name='Part A', dimensionality=THREE_D, type=DEFORMABLE_BODY) myPart.BaseSolidExtrude(sketch=mySketch, depth=20.0) myViewport = session.Viewport(name='Viewport for Model A', origin=(10, 10), width=150, height=100) myViewport.setValues(displayedObject=myPart)