乐筑天下

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

[编程交流] 如何将物体放在前面?

[复制链接]

14

主题

40

帖子

26

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 12:09:06 | 显示全部楼层 |阅读模式
你好,
 
因为我在一些区块中使用了抹布,我想把它们放在顶部。有时,块意外放置在线条下方,因此线条完全可见。
 
因为我还有一个数据库连接,可以选择每个块,所以我也想把它放在同一个例程的顶部。
  1. Public Elem As Object
  2.    For Each Elem In ThisDrawing.ModelSpace
  3.        With Elem
  4.            If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
  5.                If ((Elem.HasAttributes) And (Left(Elem.EffectiveName, 3) = "G_B") Or (Left(Elem.EffectiveName, 3) = "G_E") Or _
  6.                    (Left(Elem.EffectiveName, 3) = "G_I") Or (Left(Elem.EffectiveName, 3) = "G_L")) Then
  7. [color=red]                Elem.MoveToTop (DOESNT WORK?!)[/color]
  8.                End If
  9.            End If
  10.        End With
  11.    Next Elem

 
VBA帮助对我帮助不大。。。你们能帮帮我吗?
 
Thnx!!
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 12:32:35 | 显示全部楼层
 
 
下面是帮助中的一个示例,略有更改
希望这有意义
 
  1. Option Explicit
  2. Sub OrderToTop()
  3. ' This example creates a SortentsTable object and
  4. ' changes the draw order of selected object(s) to top.
  5. Dim oSset As AcadSelectionSet
  6. Dim oEnt
  7. Dim i As Integer
  8. Dim setName As String
  9. setName = "$Order$"
  10. 'Make sure selection set does not exist
  11. For i = 0 To ThisDrawing.SelectionSets.Count - 1
  12. If ThisDrawing.SelectionSets.Item(i).Name = setName Then
  13. ThisDrawing.SelectionSets.Item(i).Delete
  14. Exit For
  15. End If
  16. Next i
  17. Set oSset = ThisDrawing.SelectionSets.Add(setName)
  18. oSset.SelectOnScreen
  19. If oSset.Count > 0 Then
  20. ReDim arrObj(0 To oSset.Count - 1) As AcadObject
  21. 'Process each object
  22. i = 0
  23. For Each oEnt In oSset
  24. Set arrObj(i) = oEnt
  25. i = i + 1
  26. Next
  27. End If
  28. On Error GoTo Err_Control
  29. 'Get an extension dictionary and, if necessary, add a SortentsTable object
  30. Dim eDictionary As Object
  31. Set eDictionary = ThisDrawing.ModelSpace.GetExtensionDictionary
  32. ' Prevent failed GetObject calls from throwing an exception
  33. On Error Resume Next
  34. Dim sentityObj As Object
  35. Set sentityObj = eDictionary.GetObject("ACAD_SORTENTS")
  36. On Error GoTo 0
  37. If sentityObj Is Nothing Then
  38. ' No SortentsTable object, so add one
  39. Set sentityObj = eDictionary.AddObject("ACAD_SORTENTS", "AcDbSortentsTable")
  40. End If
  41. 'Move selected object(s) to the top
  42. sentityObj.MoveToTop arrObj
  43. Application.Update
  44. Exit Sub
  45. Err_Control:
  46. If Err.Number 0 Then MsgBox Err.Description
  47. End Sub

 
 
 
~'J'~
回复

使用道具 举报

14

主题

40

帖子

26

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 12:37:19 | 显示全部楼层
谢谢你的回复fixo!
 
它工作得很好。剩下一个简单的问题。。。。
 
如何填充骨灰盒?我不想在屏幕上选择。我自己制作了一系列物品:
  1. Sub OrderToTop()
  2. ' This example creates a SortentsTable object and
  3. ' changes the draw order of selected object(s) to top.
  4. Dim oSset As AcadSelectionSet
  5. Dim oEnt
  6. Dim I As Integer
  7. Dim setName As String
  8. setName = "$Order$"
  9. 'Make sure selection set does not exist
  10. For I = 0 To ThisDrawing.SelectionSets.Count - 1
  11.    If ThisDrawing.SelectionSets.Item(I).Name = setName Then
  12.        ThisDrawing.SelectionSets.Item(I).Delete
  13.    Exit For
  14.    End If
  15. Next I
  16. Set oSset = ThisDrawing.SelectionSets.Add(setName)
  17. [color=red] ReDim ssobjs(0 To ThisDrawing.Blocks.Count - 1) As AcadBlock[/color]
  18. [color=red] I = 0[/color]
  19. [color=red] For I = 0 To ThisDrawing.Blocks.Count - 1[/color]
  20. [color=red]     Set ssobjs(I) = ThisDrawing.Blocks.Item(I)[/color]
  21. [color=red] Next[/color]
  22. [color=red] ' Add the array of objects to the selection set[/color]
  23. [color=red] [b]oSset.AddItems ssobjs[/b][/color]
  24. If oSset.Count > 0 Then
  25. ReDim arrObj(0 To oSset.Count - 1) As AcadObject
  26. 'Process each object
  27. I = 0
  28. For Each oEnt In oSset
  29. Set arrObj(I) = oEnt
  30. I = I + 1
  31. Next
  32. End If
  33. On Error GoTo Err_Control
  34. 'Get an extension dictionary and, if necessary, add a SortentsTable object
  35. Dim eDictionary As Object
  36. Set eDictionary = ThisDrawing.ModelSpace.GetExtensionDictionary
  37. ' Prevent failed GetObject calls from throwing an exception
  38. On Error Resume Next
  39. Dim sentityObj As Object
  40. Set sentityObj = eDictionary.GetObject("ACAD_SORTENTS")
  41. On Error GoTo 0
  42. If sentityObj Is Nothing Then
  43. ' No SortentsTable object, so add one
  44. Set sentityObj = eDictionary.AddObject("ACAD_SORTENTS", "AcDbSortentsTable")
  45. End If
  46. 'Move selected object(s) to the top
  47. sentityObj.MoveToTop arrObj
  48. Application.Update
  49. Exit Sub
  50. Err_Control:
  51. If Err.Number <> 0 Then MsgBox Err.Description

 
如果文本为粗体,则会出现错误:对象“IAcadSelectionSet”的方法“AddItems”失败。
 
我试图将SSOBJ作为Object、Acadentity、Variant和AcadObject进行模糊处理,但它仍然不起作用。
 
怎么会?发生了什么?答案是什么?
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 12:49:35 | 显示全部楼层
 
抱歉,您混淆了AcadBlock和AcadBlockReference的概念
请看一下关于
以下是不使用选择集的代码
  1. Sub OrderToTop()
  2. ' This example creates a SortentsTable object and
  3. ' changes the draw order of inserted block regerence(s) to top.
  4. Dim oEnt As AcadEntity
  5. Dim oLayout As AcadLayout
  6. Dim I As Integer
  7. Dim ssobjs() As AcadEntity
  8. I = 0
  9. For Each oLayout In ThisDrawing.Layouts
  10. For Each oEnt In oLayout.Block
  11. If TypeOf oEnt Is AcadBlockReference Then
  12. ReDim Preserve ssobjs(I) As AcadEntity
  13. Set ssobjs(I) = oEnt
  14. I = I + 1
  15. End If
  16. Next
  17. Next
  18. On Error GoTo Err_Control
  19. 'Get an extension dictionary and, if necessary, add a SortentsTable object
  20. Dim eDictionary As Object
  21. Set eDictionary = ThisDrawing.ModelSpace.GetExtensionDictionary
  22. ' Prevent failed GetObject calls from throwing an exception
  23. On Error Resume Next
  24. Dim sentityObj As Object
  25. Set sentityObj = eDictionary.GetObject("ACAD_SORTENTS")
  26. On Error GoTo 0
  27. If sentityObj Is Nothing Then
  28. ' No SortentsTable object, so add one
  29. Set sentityObj = eDictionary.AddObject("ACAD_SORTENTS", "AcDbSortentsTable")
  30. End If
  31. 'Move selected object(s) to the top
  32. sentityObj.MoveToTop ssobjs 'arrObj
  33. Application.Update
  34. Exit Sub
  35. Err_Control:
  36. If Err.Number <> 0 Then MsgBox Err.Description
  37. End Sub

 
~'J'~
回复

使用道具 举报

14

主题

40

帖子

26

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 13:02:22 | 显示全部楼层
总是一个棘手的部分。AcadBlocks等。。。。
 
但关键是:它工作得很好!
 
非常感谢!!!:眨眼:
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 13:20:37 | 显示全部楼层
 
很乐意帮忙
 
干杯
 
~'J'~
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-5 07:01 , Processed in 0.618848 second(s), 64 queries .

© 2020-2025 乐筑天下

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