乐筑天下

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

[编程交流] 在selec中循环通过区块

[复制链接]

34

主题

105

帖子

91

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
224
发表于 2022-7-6 17:22:11 | 显示全部楼层 |阅读模式
嗨,我希望有人能给我解释一下。我(在这个论坛的很多帮助下)编写了一些代码,允许选择具有属性的块,保存某些属性值,代码然后删除块,然后允许用户在图形上选择一个点以插入新块。然后将旧块中的值转移到新块。然后,用户转到下一个块并再次执行该过程。我想做的是更改代码,以便在运行代码时,使autocad选择具有特定名称的每个块,并将每个块的属性保存在阵列中,然后将新块插入到与旧块相同的插入点。
我认为我已经实现了很多这些功能。我需要添加的唯一一件事是,块选择具有特定名称的所有块,然后设置一个数组来执行I=cnt(cnt是所选块的顶部数量),然后循环遍历我现有的代码,唯一的更改是插入点从允许用户选择更改为获取旧的块插入指向并在同一点中插入名称块。
 
通过一次选择一个块来工作的代码是
 
  1. Public Sub BRPT1_StorAttValues()
  2.    Dim MyBlockRef As AcadBlockReference
  3.    Dim myvaratt As Variant
  4.    Dim i As Double
  5.    Dim MyoEnt As AcadEntity
  6.    Dim MyBlockObj As AcadBlock
  7.    Dim OLD_BLOCK_NAME As String
  8.    Dim NEW_BLOCK_NAME As String
  9.    'Dim MyAttTextStr As String
  10.    
  11.    MyAttTextStr_Old_1 = "ROOM_NUMBER"
  12.    MyAttTextStr_Old_2 = "HEIGHT"
  13.    MyAttTextStr_Old_3 = "COMMENT"
  14.    
  15. NEW_BLOCK_NAME = "LEVEL4_ATTBLOCK"   ''''change 'the text to current 'new block name'
  16.    On Error Resume Next
  17.    ThisDrawing.SelectionSets("SelectBlock").Delete
  18.    If Err Then Err.Clear
  19.    With ThisDrawing.Utility
  20.        '' create a new selectionset
  21.        Set MyOldBlockObjSS = ThisDrawing.SelectionSets.Add("SelectBlock")
  22.        '' let user select entities interactively
  23.        MyOldBlockObjSS.SelectOnScreen
  24.         'MyObjSS.SelectOnScreen FilterType, FilterData
  25.         'MyObjSS.Select acSelectionSetAll 'FilterType, FilterData
  26.        '' highlight the selected entities
  27.        MyOldBlockObjSS.Highlight True
  28.       
  29.        '' pause for the user
  30.        .prompt vbCr & MyOldBlockObjSS.Count & " entities selected"
  31.        '.GetString False, vbLf & "Enter to continue "
  32.        For Each MyoEnt In MyOldBlockObjSS
  33.            If TypeOf MyoEnt Is AcadBlockReference Then
  34.                Set MyBlockRef = MyoEnt
  35.                myvaratt = MyBlockRef.GetAttributes
  36.                For i = 0 To UBound(myvaratt)
  37.                    If myvaratt(i).TagString = MyAttTextStr_Old_1 Then
  38.                        'myvaratt(i).TextString = "Test"
  39.                        MyAttTextStr1 = myvaratt(i).TextString
  40.                            myvaratt(i).Update
  41.                           
  42.                    End If
  43.                Next
  44.            End If
  45.        Next
  46. 'End With
  47.        For Each MyoEnt In MyOldBlockObjSS
  48.            If TypeOf MyoEnt Is AcadBlockReference Then
  49.                Set MyBlockRef = MyoEnt
  50.                myvaratt = MyBlockRef.GetAttributes
  51.                For i = 0 To UBound(myvaratt)
  52.                    If myvaratt(i).TagString = MyAttTextStr_Old_2 Then
  53.                        'myvaratt(i).TextString = "Test"
  54.                        MyAttTextStr2 = myvaratt(i).TextString
  55.                            myvaratt(i).Update
  56.                            
  57.                         
  58.                    End If
  59.                Next
  60.            End If
  61.        Next
  62. 'End With
  63.        For Each MyoEnt In MyOldBlockObjSS
  64.            If TypeOf MyoEnt Is AcadBlockReference Then
  65.                Set MyBlockRef = MyoEnt
  66.                myvaratt = MyBlockRef.GetAttributes
  67.                For i = 0 To UBound(myvaratt)
  68.                    If myvaratt(i).TagString = MyAttTextStr_Old_3 Then
  69.                        'myvaratt(i).TextString = "Test"
  70.                        MyAttTextStr3 = myvaratt(i).TextString
  71.                            myvaratt(i).Update
  72.                            
  73.                         
  74.                    End If
  75.                Next
  76.            End If
  77.        Next
  78. End With
  79. MyAttTextStr1 = Right$(MyAttTextStr1, 3)
  80.    MyAttTextStr2 = Right$(MyAttTextStr2, 4)
  81.    
  82.            MyAttTextStr2 = MyAttTextStr2 / 1000#
  83. MyAttTextStr2 = Round(MyAttTextStr2, 2#)
  84.                     ' DO NOT DELETE KEEP FOR CHECKING
  85.                   ' MsgBox (MyAttTextStr1)
  86.                    'MsgBox (MyAttTextStr2)
  87.                   ' MsgBox (MyAttTextStr3)
  88.    
  89.    
  90.                            MyOldBlockObjSS.Erase
  91.                            
  92.       BRPT2_InsertingBlockWithNewValues
  93.       
  94.   End Sub
  1. Sub BRPT2_InsertingBlockWithNewValues()
  2.    ' Define the block
  3. 'Dim MyAttTextStr As String
  4.    Dim blockObj As AcadBlock
  5.    Dim insertionPnt(0 To 2) As Double
  6.    insertionPnt(0) = 0
  7.    insertionPnt(1) = 0
  8.    insertionPnt(2) = 0
  9.    'Set blockObj = ThisDrawing.Blocks.Add _
  10.                     '(insertionPnt, "LEVEL4_ATTBLOCK")
  11.                        '(insertionPnt, "APA013")
  12. Dim MyInsertPt As Variant
  13. MyInsertPt = ThisDrawing.Utility.GetPoint(, vbCr & "Pick insertion point: ")
  14.    ' Insert the block
  15.    Dim blockrefobj As AcadBlockReference
  16.    
  17.    Myblockrefobj = "LEVEL4_ATTBLOCK"
  18.    'Myblockrefobj = "APA013"
  19.    
  20.                    Set blockrefobj = ThisDrawing.ModelSpace.InsertBlock _
  21.                (MyInsertPt, Myblockrefobj, 1#, 1#, 1#, 0)
  22.    'ZoomAll
  23.   ' MsgBox "Block Has Been Inserted " & blockrefobj.ObjectName
  24.    
  25.    
  26.    BRPT3_InsertStordValueInToNewBlock
  27.    
  28. End Sub
  1.   
  2.   Sub BRPT3_InsertStordValueInToNewBlock()
  3.    
  4.    
  5.    Dim MyBlockRef As AcadBlockReference
  6.    Dim MyObjSS As AcadSelectionSet
  7.    Dim myvaratt As Variant
  8.    Dim i As Double
  9.    Dim MyoEnt As AcadEntity
  10.    Dim MyBlockObj As AcadBlock
  11.    Dim OLD_BLOCK_NAME As String
  12.    Dim NEW_BLOCK_NAME As String
  13.   
  14.       MyAttTextStr_NEW_1 = "ROOM_REF"
  15.    MyAttTextStr_NEW_2 = "ROOM_CEILING_HEIGHT"
  16.    MyAttTextStr_NEW_3 = "ROOM_DESC"
  17.    
  18. NEW_BLOCK_NAME = "LEVEL4_ATTBLOCK"   ''''change 'the text to current 'new block name'
  19. 'MyAttTextStr = "Test 1"
  20.    On Error Resume Next
  21.    ThisDrawing.SelectionSets("SelectBlock").Delete
  22.    If Err Then Err.Clear
  23.    With ThisDrawing.Utility
  24.        '' create a new selectionset
  25.        Set MyObjSS = ThisDrawing.SelectionSets.Add("SelectBlock")
  26.        '' let user select entities interactively
  27.        'MyObjSS.SelectOnScreen
  28.        MyObjSS.Select acSelectionSetLast
  29.         'MyObjSS.SelectOnScreen FilterType, FilterData
  30.         'MyObjSS.Select acSelectionSetAll 'FilterType, FilterData
  31.        '' highlight the selected entities
  32.        MyObjSS.Highlight True
  33.       
  34.        '' pause for the user
  35.        .prompt vbCr & MyObjSS.Count & " entities selected"
  36.        '.GetString False, vbLf & "Enter to continue "
  37. '-----------------------------------------------------------------------------
  38.        For Each MyoEnt In MyObjSS
  39.            If TypeOf MyoEnt Is AcadBlockReference Then
  40.                Set MyBlockRef = MyoEnt
  41.                myvaratt = MyBlockRef.GetAttributes
  42.                For i = 0 To UBound(myvaratt)
  43.                    If myvaratt(i).TagString = MyAttTextStr_NEW_1 Then
  44.                        myvaratt(i).TextString = MyAttTextStr1
  45.                        
  46.                                End If
  47.                Next
  48.            End If
  49.        Next
  50.                        
  51. '-----------------------------------------------------------------------------
  52.           For Each MyoEnt In MyObjSS
  53.            If TypeOf MyoEnt Is AcadBlockReference Then
  54.                Set MyBlockRef = MyoEnt
  55.                myvaratt = MyBlockRef.GetAttributes
  56.                For i = 0 To UBound(myvaratt)
  57.                
  58.                    If myvaratt(i).TagString = MyAttTextStr_NEW_2 Then
  59.                   
  60.                   
  61.                        myvaratt(i).TextString = MyAttTextStr2
  62.                        
  63.                   
  64.                   
  65.                                     myvaratt(i).Update
  66.                                     
  67.                            
  68.                                End If
  69.                Next
  70.            End If
  71.        Next
  72. '-----------------------------------------------------------------------------
  73.                         For Each MyoEnt In MyObjSS
  74.            If TypeOf MyoEnt Is AcadBlockReference Then
  75.                Set MyBlockRef = MyoEnt
  76.                myvaratt = MyBlockRef.GetAttributes
  77.                For i = 0 To UBound(myvaratt)
  78.                
  79.                  If myvaratt(i).TagString = MyAttTextStr_NEW_3 Then
  80.                        myvaratt(i).TextString = MyAttTextStr3
  81.                        
  82.                  End If
  83.                Next
  84.            End If
  85.        Next
  86. End With
  87.    
  88.   End Sub
  1. Public MyAttTagStr_Old_1 As String
  2. Public MyAttTagStr_Old_2 As String
  3. Public MyAttTagStr_Old_3 As String
  4. Public MyAttTagStr_NEW_1 As String
  5. Public MyAttTagStr_NEW_2 As String
  6. Public MyAttTagStr_NEW_3 As String
  7. Public MyAttTextStr1 As String
  8. Public MyAttTextStr2 As String
  9. Public MyAttTextStr3 As String
  10. Public MyOldBlockObjSS As AcadSelectionSet
回复

使用道具 举报

34

主题

105

帖子

91

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
224
发表于 2022-7-6 19:19:56 | 显示全部楼层
那是我的旧密码。我现在开始尝试用以下内容修改它,下面的模块选择所有名为APA013的块
  1. Sub selectBlock()
  2. Dim FilterType(0) As Integer
  3. Dim FilterData(0) As Variant
  4.       On Error Resume Next
  5.    ThisDrawing.SelectionSets("SelectBlock").Delete
  6.    If Err Then Err.Clear
  7.    With ThisDrawing.Utility
  8.        '' create a new selectionset
  9.   Set objSS = ThisDrawing.SelectionSets.Add("SelectBlock")
  10.   FilterType(0) = 2
  11.   FilterData(0) = "APA013"
  12. objSS.Select acSelectionSetAll, , , FilterType, FilterData
  13.        objSS.Highlight True
  14.            blkcnt = objSS.Count
  15.             'objSS.Highlight False
  16.                'objSS.Delete
  17.            
  18.           End With
  19.            
  20.            StorAttValues
  21.            
  22. End Sub

从那里我不知道如何使代码循环通过每个块,然后再开始代码?
 
谢谢你的帮助,
 
col公司
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 15:42 , Processed in 0.332702 second(s), 56 queries .

© 2020-2025 乐筑天下

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