- 6319
- 积分
- 2225
- 粉丝
- 2867
- 获赞
- 45
- 评论
- 1712
- 收藏
热门文章
分类专栏
CAD批量替换块(批量替换外图框)——CADvba实现
yngsqq: 是的,有两套代码适用不同场景。
迁与千寻: 有时公司不同人不同操作,同样大小的图框,有的是无单位,有的是毫米,有的是英寸,直接替换会造成大小混乱。 建议加入根据目标图框大小算出缩放比例(等比例缩放,只需算一个方向即可)
yngsqq: 修改Dimension的textoverride属性
yngsqq: Sub ProcessSelectedObjects() Dim doc As AcadDocument Dim sset As AcadSelectionSet Dim ent As AcadEntity Dim prompt As String Dim selectionMade As Boolean On Error GoTo ErrorHandler Set doc = ThisDrawing ' 创建选择集 doc.SelectionSets.Add "MySelectionSet", acSelectionSetAll Set sset = doc.SelectionSets("MySelectionSet") ' 检查是否成功创建了选择集并进行了屏幕选择 If sset.Count = 0 Then prompt = "未选择任何对象。" ThisDrawing.Utility.Prompt prompt GoTo Cleanup End If ' 遍历选择集中的对象 For Each ent In sset Select Case True Case TypeOf ent Is AcadText prompt = "文本内容为:" & ent.TextString Case TypeOf ent Is AcadMText prompt = "多行文本内容为:" & ent.Text Case TypeOf ent Is AcadDimension prompt = "是标注" Case Else ' 可添加对其他类型对象的处理逻辑(若有需要) prompt = "未知类型对象" End Select ThisDrawing.Utility.Prompt prompt Next ent Cleanup: ' 清理资源 If Not sset Is Nothing Then sset.Delete Set sset = Nothing Set doc = Nothing Exit Sub ErrorHandler: MsgBox "错误: " & Err.Description, vbCritical, "错误处理" Resume Cleanup End Sub
yngsqq: Sub AddPrefixToDimensions() Dim doc As AcadDocument Dim dimObj As AcadDimension Dim dimText As String ' 尝试获取当前文档 On Error Resume Next Set doc = ThisDrawing On Error GoTo 0 ' 清除错误处理 ' 检查是否成功获取文档 If doc Is Nothing Then MsgBox "无法获取当前文档。", vbExclamation Exit Sub End If ' 遍历所有标注 For Each dimObj In doc.Dimensions ' 检查标注是否有文本覆盖 dimText = dimObj.TextOverride If Not IsEmpty(dimText) And dimText <> "" Then ' 添加前缀 dimObj.TextOverride = "d_" & dimText Else ' 处理没有文本覆盖的情况(可选) ' 例如,可以跳过或记录这些标注 ' MsgBox "标注 " & dimObj.ObjectID & " 没有文本覆盖。", vbInformation End If Next dimObj ' 清理 Set dimObj = Nothing Set doc = Nothing End Sub