乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: katto01

[编程交流] VBA-如何删除所有行

[复制链接]

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 22:43:01 | 显示全部楼层
The reason you were getting a "type mismatch" error in the For Each loop is that the collection you're looping through (ThisDrawing.ModelSpace) contains more entity types than just AcadLine objects.  You'll need to modify your loop to handle any type of entity, check to see if it's a line, and then delete it if it's a line.  Code will probably look something like this:
       
         
  1. Sub DeleteAllLinesOnLayer(ByVal TargetLayer as String)        Dim oEntity as AcadEntity        For Each oEntity In ThisDrawing.ModelSpace                If oEntity.Layer = TargetLayer And TypeOf oEntity is AcadLine Then                        oEntity.Delete                        ThisDrawing.Regen                End If        NextEnd Sub
Note:  The "ThisDrawing.Regen" is there just to force the drawing to be updated so you can see each line being deleted.  Of course, all of the other entities on the layer (such as text, arcs, etc.) will be left behind.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 14:52 , Processed in 1.114807 second(s), 52 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表