乐筑天下

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

[编程交流] 选择VBA之前和af

[复制链接]

14

主题

40

帖子

26

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 14:20:10 | 显示全部楼层 |阅读模式
我一直忙于一项日常工作,现在我就是这样做的;
 
我在按钮中使用以下命令启动例程:
-vbarun;GEA\u ATT\u CH.dvb!此图纸。删除met_过滤器;
 
  1. Sub Delete_met_Filter()
  2.    Dim set2 As AcadSelectionSet
  3.    Dim II As Integer
  4.    Dim AttarrayY As Variant
  5.    Dim Varatts As AcadAttributeReference
  6.    Dim ElEment As Object
  7.    Dim Aantal As Double
  8. thisdrawing.StartUndoMark
  9. Aantal = 0
  10. Set set2 = thisdrawing.ActiveSelectionSet <----- Needs to change to??
  11.    For Each ElEment In set2
  12.    With ElEment
  13.        If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
  14.            If ((ElEment.HasAttributes) And (Left(ElEment.Name, 3) = "G_B") Or (Left(ElEment.Name, 3) = "G_E") Or _
  15.            (Left(ElEment.Name, 3) = "G_I") Or (Left(ElEment.Name, 3) = "G_L")) Then
  16.                AttarrayY = ElEment.GetAttributes
  17.                For II = 0 To UBound(AttarrayY)
  18.                    Set Varatts = AttarrayY(II)
  19.                    If Varatts.TagString = "NOTE_2" And Varatts.TextString = "Checked" Then
  20.                        Aantal = Aantal + 1
  21.                II = II + 1
  22.                    End If
  23.                Next
  24.            Else
  25.                set2.Erase
  26.                GoTo Einde
  27.            End If
  28.        End If
  29.    End With
  30.    Next ElEment
  31.    If Aantal >= 1 Then
  32.        G_ans_erase = MsgBox("U heeft " & Aantal & " checked items in uw selectie, wilt u doorgaan?", vbYesNo + vbDefaultButton2, "Controle block-verwijdering")
  33.        If G_ans_erase = vbYes Then
  34.        set2.Erase
  35.        GoTo Einde
  36.        End If
  37.        If G_ans_erase = vbNo Then
  38.        GoTo Einde
  39.        End If
  40.    End If
  41.    If Aantal = 0 Then
  42.        set2.Erase
  43.    End If
  44. Einde:
  45. set2.Clear
  46. thisdrawing.EndUndoMark
  47. End Sub

 
我想将erase命令重新定义为vba例程。我想这不是问题。但还有一个问题。
 
如果您首先选择某个项目,然后启动该例程,则该例程将起作用。但我也希望它在例行程序开始之前没有进行选择的情况下工作。就像删除命令一样,你选择你的对象,然后启动命令,或者启动命令,然后选择你的对象。它以两种方式工作。
 
如果我在没有选择任何对象的情况下启动例程。例程使用以前选择的项目。此图纸。除非从图形中删除这些项目,否则ActiveSelectionSet总是满的。我需要另一种选择对象的方法。你有什么想法吗??
 
我试过在宏前面使用“select”命令。但我没能让它工作。(^C^Cselect;\-vbarun;GEA\u ATT\u CH.dvb!Thisdrawing.Delete\u met\u Filter;。然后我在例程中使用:“set2.Select acSelectionSetPrevious”)可能我用错了?或者有没有其他方法可以将某些内容放在宏前面?你能让它工作吗?
 
总之,问题是:
如何在例程中读取在例程开始之前选择的选项(在set2中设置)。(一个想法?也无法实现)。如果没有进行选择,并且用户需要在例程启动后选择项目,则该选项也可以使用。(如果..那么…在屏幕上选择??)
 
谢谢你的帮助!
回复

使用道具 举报

14

主题

40

帖子

26

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 15:56:08 | 显示全部楼层
我修好了!
 
  1. Dim DelSel As AcadSelectionSet
  2. Dim Aantal As Double
  3. Public Sub ACADApp_BeginCommand(ByVal CommandName As String)
  4.   If CommandName = "SELECT" Then
  5.        If thisdrawing.PickfirstSelectionSet.count >= 1 Then 'kijken of een actieve selectie is en wegzetten in DelSel
  6.            Set DelSel = thisdrawing.PickfirstSelectionSet
  7.        End If
  8.        If thisdrawing.PickfirstSelectionSet.count = 0 Then 'als er geen actieve selectie is, select command uitvoeren
  9.            On Error Resume Next
  10.            Set DelSel = thisdrawing.SelectionSets.Add("NEW")
  11.        End If
  12.    End If
  13. End Sub
  14. Public Sub AcadDocument_EndCommand(ByVal CommandName As String)
  15.    If CommandName = "SELECT" Then
  16.    On Error Resume Next
  17.        If DelSel.count < 1 Then             Set DelSel = thisdrawing.ActiveSelectionSet                                                                                    Call Delete_met_Filter
  18.        Else
  19.            Call Delete_met_Filter
  20.        End If
  21.    End If
  22.    If CommandName = "ERASE" Then
  23.        thisdrawing.SendCommand ("U" & vbCr)
  24.        thisdrawing.SendCommand ("erase" & vbCr)
  25.    End If
  26. End Sub
  27. Sub Delete_met_Filter()
  28.    Dim II As Integer
  29.    Dim AttarrayY As Variant
  30.    Dim Varatts As AcadAttributeReference
  31.    Dim ElEment As Object
  32. Aantal = 0
  33. On Error Resume Next
  34.    For Each ElEment In DelSel
  35.    With ElEment
  36.        If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
  37.            If ((ElEment.HasAttributes) And (Left(ElEment.Name, 3) = "G_B") Or (Left(ElEment.Name, 3) = "G_E") Or _
  38.            (Left(ElEment.Name, 3) = "G_I") Or (Left(ElEment.Name, 3) = "G_L")) Then
  39.                AttarrayY = ElEment.GetAttributes
  40.                For II = 0 To UBound(AttarrayY)
  41.                    Set Varatts = AttarrayY(II)
  42.                    If Varatts.TagString = "NOTE_2" And Varatts.TextString = "Checked" Then
  43.                        Aantal = Aantal + 1
  44.                II = II + 1
  45.                    End If
  46.                Next
  47.            End If
  48.        End If
  49.    End With
  50.    Next ElEment
  51.    If Aantal = 0 Then
  52.    DelSel.Erase
  53.    GoTo Einde
  54.    End If
  55.    If Aantal >= 1 Then
  56.        G_ans_erase = MsgBox("U heeft " & Aantal & " checked items in uw selectie, wilt u doorgaan?", vbYesNo + vbDefaultButton2, "Controle block-verwijdering")
  57.        If G_ans_erase = vbYes Then
  58.            DelSel.Erase
  59.            GoTo Einde
  60.        End If
  61.        If G_ans_erase = vbNo Then
  62.            GoTo Einde
  63.        End If
  64.    End If
  65. Einde:
  66. DelSel.Delete
  67. End Sub
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-6-6 16:50 , Processed in 2.007267 second(s), 57 queries .

© 2020-2025 乐筑天下

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