from abaqus import *
from abaqusConstants import *
fields = (('Width :','400'),('Height :','320'))
iWidth = None
while iWidth==None:
    iWidth,iHeight=getInputs(fields=fields,label='Enter Hole Plate Dimensions :')
iWidth=int(iWidth)
iHeight=int(iHeight)
iRadius = 10
iWidth = iWidth - iWidth % (iRadius * 4)
iHeight = iHeight - iHeight % (iRadius * 4)
myModel=mdb.Model(name='Model A')
mySketch = myModel.Sketch(name ='Sketch A', sheetSize = iWidth*2)
mySketch.rectangle(point1 =(0,0),point2=(iWidth,iHeight))
i=2*iRadius
while i<iWidth:
  j=2*iRadius
  while j<iHeight:
    mySketch.CircleByCenterPerimeter(center=(i,j),point1=(i,j+iRadius))
    j=j+4*iRadius
  i=i+4*iRadius
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.makeCurrent()
myViewport.maximize()
myViewport.setValues (displayedObject = myPart)
myViewport.partDisplay. setValues (renderStyle=SHADED)
axis1 = myPart.DatumAxisByTwoPoint (point1 = (0.0,0.0,0.0),point2 = (iWidth,0.0 ,0.0))
axis2 = myPart.DatumAxisByTwoPoint (point1 = (0.0,0.0,0.0),point2 = (0.0,iHeight,0.0))
datums=myPart.datums
i = 2*iRadius
while i < iWidth :
  d=myPart.DatumPointByCoordinate(coords=(i,0.0,0.0))
  myCell = myPart.cells[ : ]
  myPart.PartitionCellByPlanePointNormal(point = datums[ d.id ],normal = datums[ axis1.id ] , cells = myCell)
  i = i + 2*iRadius
j = 2*iRadius
while j < iHeight:
  d=myPart.DatumPointByCoordinate(coords=(0.0,j,0.0))
  myCell = myPart.cells[ : ]
  myPart.PartitionCellByPlanePointNormal(point = datums[ d.id ],normal = datums[ axis2.id ] , cells = myCell)
  j = j + 2*iRadius
fields = (('Size :','10.0'))
iSize=None
while iSize==None:
#  iSize=getInputs('Enter a number for Global Seeds Size','10.0')
  iSize=getInputs(fields=fields,label='Enter a number for Global Seeds Size:')
  iSize=float(10.0)
  myPart.seedPart(size=iSize,deviationFactor=0.1)
myPart.generateMesh ()
myViewport.partDisplay.setValues(mesh=ON)