明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1372|回复: 4

请教一段VBA代码

[复制链接]
发表于 2007-4-1 11:58:00 | 显示全部楼层 |阅读模式

Sub Getusersselection()
Dim usersselection As AcadSelectionSet
Dim drawingselected As AcadEntity
With ThisDrawing
On Error Resume Next
.SelectionSets("currentselection").Delete
MsgBox "select objects !hit enter to finish!"
Set usersselection = ?
.SelectionSets.Add ("currentselection")
usersselection.SelectOnScreen
For Each drawingselected In usersselection
drawingselected.color = acGreen
Next
End With
End Sub

各位高手!小弟在此请教,该段代码的作用是在CAD模型空间选取直线进行变换颜色.

但代码中红色部分编译程序报错,我个人觉得也不符合格式,请问各位高手该段代码应该怎样修改.

发表于 2007-4-1 15:10:00 | 显示全部楼层

以下代码经过我测试,应该没问题的
Sub Getusersselection()
Dim usersselection As AcadSelectionSet
Dim drawingselected As AcadEntity
If ThisDrawing.SelectionSets.Count <> 0 Then
   Do While ThisDrawing.SelectionSets.Count <> 0
      ThisDrawing.SelectionSets.Item(0).Delete
   Loop
End If
MsgBox "select objects !hit enter to finish!"
Set usersselection = ThisDrawing.SelectionSets.Add("example")
usersselection.SelectOnScreen
For Each drawingselected In usersselection
         drawingselected.color = acGreen
Next
usersselection.Delete
End Sub

 楼主| 发表于 2007-4-2 07:03:00 | 显示全部楼层
谢谢大哥!小弟还有一个问题。大哥是否看过AUTOCADVBA从入门到精通这本书。在第150页的第13行命令,大哥是否能将代码发送上来,小弟用的是扫描书,看不请里面的标点。
 楼主| 发表于 2007-4-2 07:06:00 | 显示全部楼层
另大哥可否将QQ号等联系方式留给小弟,小弟初学有很多问题不懂,需请教!
发表于 2007-4-2 13:08:00 | 显示全部楼层

楼主代码输入有误,红色代码和它下面一行应为同一行:

Set usersselection = .SelectionSets.Add ("currentselection")

二楼的这段代码:

If ThisDrawing.SelectionSets.Count <> 0 Then
   Do While ThisDrawing.SelectionSets.Count <> 0
      ThisDrawing.SelectionSets.Item(0).Delete
   Loop
End If


改为这样是不是更简单些?


Do Until ThisDrawing.SelectionSets.Count = 0
   ThisDrawing.SelectionSets.Item(0).Delete
Loop

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-2-22 02:15 , Processed in 0.163552 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表