乐筑天下

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

[编程交流] 使用镜像属性

[复制链接]

13

主题

70

帖子

57

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 22:15:51 | 显示全部楼层 |阅读模式
我写了一些VBA代码来镜像一个对象(因为我必须通过编程而不是手动完成),我遇到了一个问题
 
VBA镜像功能似乎不像普通镜像命令那样自动镜像块的属性
 
我会附上一个测试dwg文件,并张贴代码,如果有人可以向我解释如何修复代码,使属性也镜像
 
  1. Option Explicit
  2. Sub AutoMirror()
  3. Dim x1 As AcadBlockReference
  4. Dim x2 As AcadBlockReference
  5. Dim inspt As Variant
  6. ThisDrawing.Utility.GetEntity x1, inspt, "Select item to mirror:"
  7. Set x2 = MirrorFix(x1)
  8. End Sub
  9. Public Function MirrorFix(entMirror As AcadBlockReference) As AcadBlockReference
  10. Dim pt1(2) As Double
  11. Dim pt2(2) As Double
  12. Dim inspt As Variant
  13. Dim bb1 As Variant
  14. Dim bb2 As Variant
  15. Dim AttList As Variant
  16. Dim i As Integer
  17. Dim nHeight As Integer
  18. Dim attr(3) As String
  19. Dim entNew As AcadBlockReference
  20. If entMirror.XScaleFactor <> Abs(entMirror.XScaleFactor) Then
  21.    'save attribute info to variables and then delete from block
  22.    ' or the bounding box will be wrong
  23.    AttList = entMirror.GetAttributes
  24.    attr(0) = AttList(0).TextString
  25.    attr(1) = AttList(1).TextString
  26.    attr(2) = AttList(2).TextString
  27.    attr(3) = AttList(3).TextString
  28.    AttList(0).TextString = ""
  29.    AttList(1).TextString = ""
  30.    AttList(2).TextString = ""
  31.    AttList(3).TextString = ""
  32.    
  33.    ' mirror the block
  34.    ' doesnt mirror the attributes for some reason
  35.    entMirror.GetBoundingBox bb1, bb2
  36.    pt1(0) = bb1(0) + ((bb2(0) - bb1(0)) / 2)
  37.    pt1(1) = bb1(1) + ((bb2(1) - bb1(1)) / 2)
  38.    pt2(0) = pt1(0) + (10 * Cos(entMirror.Rotation)) ' new X
  39.    pt2(1) = pt1(1) + (10 * Sin(entMirror.Rotation)) ' new Y
  40.    Set entNew = entMirror.Mirror(pt1, pt2)
  41.    entMirror.Delete
  42.    
  43.    ' add attribute info back to block
  44.    AttList = entNew.GetAttributes
  45.    AttList(0).TextString = attr(0)
  46.    AttList(1).TextString = attr(1)
  47.    AttList(2).TextString = attr(2)
  48.    AttList(3).TextString = attr(3)
  49. Else
  50.    Set entNew = entMirror
  51. End If
  52. Set MirrorFix = entNew
  53. End Function

镜子测试。图纸
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 11:39 , Processed in 0.712365 second(s), 54 queries .

© 2020-2025 乐筑天下

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