Excepting a COMError in Python
<p>Having difficulty excepting a COMError in python. Below is the method I call to do some stuff in AutoCAD.</p>

<pre><code>    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
</code></pre>

<p>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:</p>

<pre><code>COMError: (-2147418111, 'Call was rejected by callee.', (None, None, None, 0, None))
</code></pre>

<p>When nothing is selected and the script shouldn't have to handle the COMError exception, I get:</p>

<pre><code>NameError: global name 'COMError' is not defined
</code></pre>

<p>Not sure what to do. I have <strong>comtypes</strong> imported so I'm not sure why COMError is undefined.</p>