Having difficulty excepting a COMError in python. Below is the method I call to do some stuff in AutoCAD.
def populate_drawing(self):
nMeasurementsFinal = Feature_recognition.determine_OD_dims(Feature_recognition(), "C:\\Users\\buntroh\\Documents\\Rotoworks\\122508.csv")
while True:
try:
for nObject in self.acad.iter_objects(None, None, None, False):
if hasattr(nObject, 'TextString'):
try:
nObject.TextString = nMeasurementsFinal[nObject.TextString]
except KeyError as e:
continue
except COMError:
self.acad.doc.SendCommand("Chr(3)")
break
The COMError exception is because whenever something is selected in AutoCAD before the script is run, it returns a COMError. However, even with the exception, I still get:
COMError: (-2147418111, 'Call was rejected by callee.', (None, None, None, 0, None))
When nothing is selected and the script shouldn't have to handle the COMError exception, I get:
NameError: global name 'COMError' is not defined
Not sure what to do. I have comtypes imported so I'm not sure why COMError is undefined.