Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I wrote some routine in python to modify the leader content
everything is ok, script works fine but python raises too many COMError's at the end of the day I except this errors and jut neglect it because actually code works but, what causes this errors so frequently?
I have to click several times to get a result when it raises this Error
this is an error content I just wrap it with exception during the screencast
Traceback (most recent call last):
File "C:\Users\ASUS\Desktop\test.py", line 14, in <module>
leader = acad.get_selection()
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautocad\api.py", line 175, in get_selection
selection = self.doc.SelectionSets.Add('SS1')
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python310\lib\site-packages\pyautocad\api.py", line 74, in doc
return self.app.ActiveDocument
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python310\lib\site-packages\comtypes\client\lazybind.py", line 168, in __getattr__
return self._comobj._invoke(descr.memid, descr.invkind, 0)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python310\lib\site-packages\comtypes\automation.py", line 745, in _invoke
self.__com_Invoke(memid, riid_null, lcid, invkind,
_ctypes.COMError: (-2147418111, 'Call was rejected by callee.', (None, None, None, 0, None))
[Finished in 639ms]
from pyautocad import Autocad, APoint
import re, sys, keyboard
from comtypes import COMError
acad = Autocad()
counter = 144
tempNum = 144
letters = ['"A"','"B"','"C"']
while True:
try:
if keyboard.is_pressed('esc'):
sys.exit()
leader = acad.get_selection()
for i in leader:
text = re.search(r'(.*)(5.})(\d+)(.*)(([a-z]\.)("[A-Z]"\Z))',i.textString)
phase = letters[(counter-1)%3]
newString = text.group(1) + text.group(2) + str(counter) + text.group(4) + text.group(6) + phase
i.textString = newString
tempNum += 1
except COMError:
counter = tempNum
continue
except AttributeError:
counter = tempNum
continue
counter += 1
print(counter)
Beka Tchigladze
Road/Highway Technical Designer
AEC Collection/C3D 2025
WIN 11 64 PRO
Predator Helios 18, Intel Core i9 14900HX, 32 GB
NVIDIA RTX 4080, 12 GB
YouTube--->Linkedin

Road/Highway Technical Designer
AEC Collection/C3D 2025
WIN 11 64 PRO
Predator Helios 18, Intel Core i9 14900HX, 32 GB
NVIDIA RTX 4080, 12 GB
YouTube--->Linkedin


Solved! Go to Solution.