当前位置:网站首页>A solution to the error of selecting objects in pyautocad
A solution to the error of selecting objects in pyautocad
2022-04-22 07:10:00 【orzzd】
pyautocad Select the solution of object error reporting
brief introduction
pyautocad The library is designed by Russian engineers Roman Haritonov Development , For simplified use Python Language writing AutoCAD ActiveX Automation Script . The name of the package file and GIthub Here it is .
Mistakes show
In the official documentation , Provides a solution for iteratively selecting objects :
for text in acad.iter_objects('Text'):
print text.TextString, text.InsertionPoint
for obj in acad.iter_objects(['Text', 'Line']):
print obj.ObjectName
But after practical use , My machine will prompt the following error :
_ctypes.COMError: (-2147467262, ' This interface is not supported ', (None, None, None, 0, None))
_ctypes.COMError: (-2147467262, 'No such interface supported', (None, None, None, 0, None))
Access Forum , I find “-2147467262” This error is usually caused by a poor connection with the program used , My machine has been installed AutoCAD2008、AutoCAD2010、AutoCAD2020、AutoCAD2021 Several versions , So it may be the error caused by too many installed versions .
Preliminary solution
In the Forum , Two solutions are given , The first solution is through acad.iter_objects_fast, Instead of acad.iter_objects, After testing, it is found that it is OK , But there will be a bug. My need is to get all the objects , Then delete it , Use acad.iter_objects_fast This method , Always can't get the last object , That is, the last object will be left after each deletion .
Finally consider the second solution , Change to use win32com This package controls AutoCAD.
Final solution
First import the package :import win32com.client as win32, If you don't have this bag , have access to pip install win32com Download . But my machine will report an error :DLL load failed while importing win32api: The specified module was not found , Baidu after discovery , Put the environment ***\Lib\site-packages\pywin32_system32\ What's in it *** Copy to ***C:\Windows\System32*** Can solve .

And then use win32com To control CAD, The code is as follows :
# establish AutoCAD example
wincad = win32.Dispatch("AutoCAD.Application")
doc = wincad.ActiveDocument
# Clear existing selection sets
try:
self.doc.SelectionSets.Item("SS1").Delete()
except:
print("Delete selection failed")
# Create selection set
slt = self.doc.SelectionSets.Add("SS1")
# Future generations
slt.Select(5) # acSelectionSetAll = 5
# Delete... In turn
for i in range(slt.Count):
slt[i].delete()
win32com For other ways to use, see the reference link .
Reference link
pyautocad example is not running
ImportError: DLL load failed while importing win32api: The specified module was not found
The fifth chapter Create and edit AutoCAD object
Create and edit AutoCAD object (VBA&python)
版权声明
本文为[orzzd]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220606226715.html
边栏推荐
猜你喜欢

RTD2171U方案|AG9310MFQ替代RTD2171U设计电路|Typec转hdmi 4K30HZ高清投屏方案设计

Qinheng ch573 development board

什么是socket编程?

MATLAB:去除音频信号噪音

阿里云部署Tiny Tiny RSS踩坑笔记

RSS入坑指南

STM32 timer ocref output configuration timx - > CCER

在消防联网(楼宇、工厂、海上风电、管廊等)中CAN光纤转换器、CAN总线光端机典型应用案例

CAN光端机在消防联网中的应用

Application of mcicecan in industrial computer
随机推荐
MATLAB:女声转男声
Typical application cases of can optical fiber converter and can bus optical transceiver in fire Networking (buildings, factories, offshore wind power, pipe gallery, etc.)
MCIeCAN在工控机中的应用
转行数字IC验证的学习路线是什么样的?现在开始转是否来得及?985本硕,电子学院研二
STM32学习记录0002-STM32初探
Leetcode598: range summation II
IDEA debug调试教程
阿里云部署RSSHub踩坑笔记
Application of usbcan card in CAN bus in EOL test system of power battery pack
Alternative ps8625 | alternative ps8622 | design and development of cost-effective EDP to LVDS adapter board cs5211
MySQL完全卸载,mysql服务清理
FreeRTOS v10. 1.0 source code Chinese annotation version
mui.plusReady 不生效
如何成为IC验证工程师?
RTD2171U方案|AG9310MFQ替代RTD2171U设计电路|Typec转hdmi 4K30HZ高清投屏方案设计
Quantify the relationship between 911 calls and years from 2015 to 2017
leetcode打卡日记 day 01
miniPCIe接口CAN卡为工控机扩展CAN通道
Sss1700 qfn36 single chip designs a USB typec headset | supports the automatic switching of USB headset scheme between wire control and European and American regulations
HDMI switcher scheme | 3 in and 1 out HDMI switcher | 5 in and 1 out hdmi2 Design circuit of ag7111 0 switcher