Chad Ehret 发表于 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:
       
         
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.
页: 1 [2]
查看完整版本: VBA-如何删除所有行