spacether/pycalculix

Can't define top/bottom on imported DXF

joeborrello opened this issue · 2 comments

Working with a rectangular part (which should have a perfectly flat, horizontal upper line) I tried to define constraints using part.top and part.bottom but I got the following error:
AttributeError: 'list' object has no attribute 'bottom'

The part variable in this case is coming from the importer.load() function to import the DXF.

Screencap of the part is included here and the DXF is attached.
circle-hole.zip

image

Hi @joeborrello. This is happening because you are trying to access a property on a list and not a part. The load function returns a list of parts, then you need to access the first part and use .top .bottom .left and .right on that part. See my below code which works:

#!/usr/bin/env python3
import os
import sys

import pycalculix as pyc

model_name = 'circle-hole'
model = pyc.FeaModel(model_name)
model.set_units('m')

# set whether or not to show gui plots
show_gui = True
if '-nogui' in sys.argv:
    show_gui = False
# set element shape
eshape = 'quad'
if '-tri' in sys.argv:
    eshape = 'tri'

abs_path = os.path.dirname(os.path.abspath(__file__))
fname = os.path.join(abs_path, '%s.dxf' % model_name)
importer = pyc.CadImporter(model, fname, swapxy=True)
parts = importer.load()
model.plot_geometry(model_name+'_imported', display=show_gui)
#parts[0].chunk()
model.plot_geometry(model_name+'_areas', pnum=False,
                    lnum=False, display=show_gui)
model.plot_geometry(model_name+'_lines', anum=False,
                    pnum=False, display=show_gui)
model.plot_geometry(model_name+'_points', anum=False,
                    lnum=False, display=show_gui)

model.set_etype('axisym', parts)
model.set_eshape(eshape, 2)
model.mesh(1.0, 'gmsh')
model.plot_elements(model_name+'_elements', display=show_gui)

part = parts[0]
model.set_constr('fix', part.top, 'x')
model.set_constr('fix', part.bottom, 'x')
model.plot_constraints(model_name+'_constr', display=show_gui)

Awesome, I'll give this a go tomorrow