乐筑天下

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

[编程交流] GroupLayerFil之间的关系

[复制链接]

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 17:06:46 | 显示全部楼层 |阅读模式
嗨,伙计们
我的问题可能相当复杂,所以我希望有人能回答:
有人知道组层过滤器和层之间的编程关系吗或者我在哪里可以找到它?
 
我已经找到了组层过滤器的位置(使用VLAX),
但我认为目前关于他们的唯一有用信息是他们的名字。
它们中的每一个不应该都有一个层数的“计数”属性吗?
或者至少每个层对象都与其所在的组层过滤器有一些连接信息(方法或属性)。
 
180646eeegty8qzb7sswsr.jpg
 
为了找到我抛弃的任何关系:
-图层集合,
-图层集合扩展Dict,
-Layers collection Extended Dict中的每一项,
-“ACAD_LAYERFILTERS”集合(位于Layers Coll Extended Dict内),
-“ACAD_LAYERFILTERS”系列中的每一项,
-活动层,
-活动层的扩展Dict
 
以下是使用(C:ForTest)的示例图:
分组层过滤器测试。图纸
 
以下是我使用VLIDE控制台获得的(缩短的)信息:
  1. ; Helper functions:
  2. (defun DT ( o / ) (if (= (type o) 'VLA-OBJECT) (vlax-dump-object o T))) ; Dump True (I'm using it as a shortcut)
  3. (defun GetExtDict ( o / ) (if (and (= (type o) 'VLA-OBJECT) (vlax-method-applicable-p o 'GetExtensionDictionary)) (vlax-invoke o 'GetExtensionDictionary)))
  4. (defun DTColl ( coll / ) (if (= (type coll) 'VLA-OBJECT) (vlax-for o coll (vlax-dump-object o T)))) ; Dump True (everything inside of a collection)
  5. (defun Coll->Lst ( #Collection / Lst ) (vlax-for o #Collection (setq Lst (cons o Lst))) (reverse Lst)); convert Collection into List
  6. ; Start digging:
  7. (setq AcLay (vla-get-ActiveLayer (vla-get-ActiveDocument (vlax-get-acad-object))))
  8. (setq ExtDictAcLay (GetExtDict AcLay))
  9. (setq LayColl (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
  10. (setq ExtDictCollOfLayersColl (GetExtDict LayColl))
  11. ; (DTColl ExtDictCollOfLayersColl) ; inside of it there are: ACAD_LAYERFILTERS ACAD_LAYERSTATES ACLYDICTIONARY
  12. (setq LAYERFILTERS (vla-item ExtDictCollOfLayersColl "ACAD_LAYERFILTERS"))
  13. (setq LAYERSTATES (vla-item ExtDictCollOfLayersColl "ACAD_LAYERSTATES"))
  14. (setq ACLYDICTIONARY (vla-item ExtDictCollOfLayersColl "ACLYDICTIONARY"))
  15. _$ (DTcoll LAYERFILTERS)
  16. ; IAcadXRecord: XRecord objects are used to store and manage arbitrary data
  17. ; Property values:
  18. ;   Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff78a999110>
  19. ;   Document (RO) = #<VLA-OBJECT IAcadDocument 0000002a7ec52b78>
  20. ;   Handle (RO) = "20C"
  21. ;   HasExtensionDictionary (RO) = 0
  22. ;   Name = "Group1"
  23. ;   ObjectID (RO) = 42
  24. ;   ObjectName (RO) = "AcDbXrecord"
  25. ;   OwnerID (RO) = 43
  26. ;   TranslateIDs = -1
  27. ; Methods supported:
  28. ;   Delete ()
  29. ;   GetExtensionDictionary ()
  30. ;   GetXData (3)
  31. ;   GetXRecordData (2)
  32. ;   SetXData (2)
  33. ;   SetXRecordData (2)
  34. ; IAcadXRecord: XRecord objects are used to store and manage arbitrary data
  35. ; Property values:
  36. ;   Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff78a999110>
  37. ;   Document (RO) = #<VLA-OBJECT IAcadDocument 0000002a7ec52b78>
  38. ;   Handle (RO) = "20E"
  39. ;   HasExtensionDictionary (RO) = 0
  40. ;   Name = "Group2"
  41. ;   ObjectID (RO) = 44
  42. ;   ObjectName (RO) = "AcDbXrecord"
  43. ;   OwnerID (RO) = 43
  44. ;   TranslateIDs = -1
  45. ; Methods supported:
  46. ;   Delete ()
  47. ;   GetExtensionDictionary ()
  48. ;   GetXData (3)
  49. ;   GetXRecordData (2)
  50. ;   SetXData (2)
  51. ;   SetXRecordData (2)
  52. ; IAcadXRecord: XRecord objects are used to store and manage arbitrary data
  53. ; Property values:
  54. ;   Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff78a999110>
  55. ;   Document (RO) = #<VLA-OBJECT IAcadDocument 0000002a7ec52b78>
  56. ;   Handle (RO) = "210"
  57. ;   HasExtensionDictionary (RO) = 0
  58. ;   Name = "Group3"
  59. ;   ObjectID (RO) = 45
  60. ;   ObjectName (RO) = "AcDbXrecord"
  61. ;   OwnerID (RO) = 43
  62. ;   TranslateIDs = -1
  63. ; Methods supported:
  64. ;   Delete ()
  65. ;   GetExtensionDictionary ()
  66. ;   GetXData (3)
  67. ;   GetXRecordData (2)
  68. ;   SetXData (2)
  69. ;   SetXRecordData (2)
  70. ; IAcadXRecord: XRecord objects are used to store and manage arbitrary data
  71. ; Property values:
  72. ;   Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff78a999110>
  73. ;   Document (RO) = #<VLA-OBJECT IAcadDocument 0000002a7ec52b78>
  74. ;   Handle (RO) = "212"
  75. ;   HasExtensionDictionary (RO) = 0
  76. ;   Name = "Group4"
  77. ;   ObjectID (RO) = 46
  78. ;   ObjectName (RO) = "AcDbXrecord"
  79. ;   OwnerID (RO) = 43
  80. ;   TranslateIDs = -1
  81. ; Methods supported:
  82. ;   Delete ()
  83. ;   GetExtensionDictionary ()
  84. ;   GetXData (3)
  85. ;   GetXRecordData (2)
  86. ;   SetXData (2)
  87. ;   SetXRecordData (2)
  88. T
  89. _$

你可以试着用上面的句子来“挖掘”/检查。
 
如果无法打开dwg,请使用以下测试代码重新创建组图层过滤器和图层测试dwg:
  1. ; To create the test Layers with their LayerGroupFilters:
  2. (defun C:ForTest ( / LayGroupNames LayLstGroup1 LayLstGroup2 LayLstGroup3 LayLstGroup4 n)
  3. (defun CreateLayer ( #Name / )
  4.         (entmake
  5.                 (list
  6.                         (cons 0 "LAYER")
  7.                         (cons 100 "AcDbSymbolTableRecord")
  8.                         (cons 100 "AcDbLayerTableRecord")
  9.                         (cons 2 #Name)
  10.                         (cons 70 0)
  11.                 )
  12.         )
  13. )
  14. (setq LayGroupNames '("Group1" "Group2" "Group3" "Group4"))
  15. (setq
  16.         LayLstGroup1 '("Group1-Lay1" "Group1-Lay2" "Group1-Lay3" "Group1-Lay4" "Group1-Lay5" "Group1-Lay6" "Group1-Lay7")
  17.         LayLstGroup2 '("Group2-Lay1" "Group2-Lay2" "Group2-Lay3" "Group2-Lay4" "Group2-Lay5" "Group2-Lay6" "Group2-Lay7")
  18.         LayLstGroup3 '("Group3-Lay1" "Group3-Lay2" "Group3-Lay3" "Group3-Lay4" "Group3-Lay5" "Group3-Lay6" "Group3-Lay7")
  19.         LayLstGroup4 '("Group4-Lay1" "Group4-Lay2" "Group4-Lay3" "Group4-Lay4" "Group4-Lay5" "Group4-Lay6" "Group4-Lay7")
  20. )
  21. (setq n 0)
  22. (foreach x (list LayLstGroup1 LayLstGroup2 LayLstGroup3 LayLstGroup4)
  23.         (mapcar 'CreateLayer x)
  24.         (command "._-layer" "filter" "new" "property" "All" (strcat "NAME=="" (nth n LayGroupNames) "*"") (nth n LayGroupNames) "X" nil)
  25.         (setq n (1+ n))
  26. )
  27. (princ)
  28. ); defun C:ForTest

 
原因是我对AUGI论坛上的“一个简单请求”的帖子很好奇。
用户询问是否可以重命名一组特定图层,方法是添加它们所在图层组过滤器名称的前缀。
然而,这不是我的目标。
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 17:22:03 | 显示全部楼层
可以今天我做了一个小进步:
  1. (defun C:test ( / ld AllLyrNames LayersColl LFtContainer MyLayerFilterNames Lst FtsLst)
  2. (while (setq ld (tblnext "LAYER" (not ld)))
  3.         (setq AllLyrNames (cons (cdr (assoc 2 ld)) AllLyrNames))
  4. )
  5. (setq LayersColl (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
  6. (setq LFtContainer (vla-item (vla-GetExtensionDictionary LayersColl) "ACAD_LAYERFILTERS"))
  7. (vlax-map-collection LFtContainer '(lambda (x) (setq MyLayerFilterNames (cons (vla-get-Name x) MyLayerFilterNames))))
  8. ; (if MyLayerFilterNames
  9. ; (foreach x (reverse MyLayerFilterNames)
  10. ; (print (HowMyLayerFilterIsCreated x))
  11. ; )
  12. ; )
  13. (if MyLayerFilterNames
  14.         (progn
  15.                 (if (not Lst) (setq Lst (list)))
  16.                 (setq FtsLst (mapcar 'HowMyLayerFilterIsCreated MyLayerFilterNames))
  17.                 (foreach Ft FtsLst
  18.                         (setq Lst (append Lst (mapcar '(lambda (x) (if (wcmatch x (cadr Ft)) (cons (car Ft) x))) AllLyrNames)))
  19.                 )
  20.                 (setq Lst (reverse (vl-remove nil Lst)))
  21.                 (foreach x Lst (print x))
  22.         )
  23. ); if MyLayerFilterNames
  24. (princ)
  25. ); defun C:test
  26. (defun HowMyLayerFilterIsCreated ( LyrFilterName / LayersColl LFtContainer MyLayerFilter XRecordDataLst MyLayerFilterXRecordDataType MyLayerFilterXRecordData )
  27. (if
  28.         (and
  29.                 (setq LayersColl (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
  30.                 (setq LFtContainer (vla-item (vla-GetExtensionDictionary LayersColl) "ACAD_LAYERFILTERS"))
  31.                 (setq MyLayerFilter (vla-item LFtContainer LyrFilterName))
  32.         )
  33.         (progn
  34.                 (vla-GetXRecordData MyLayerFilter 'MyLayerFilterXRecordDataType 'MyLayerFilterXRecordData)
  35.                 (setq XRecordDataLst (mapcar 'vlax-variant-value (vlax-safearray->list MyLayerFilterXRecordData)))
  36.         )
  37. )
  38. XRecordDataLst
  39. );| defun HowMyLayerFilterIsCreated |; (or (vlax-get-acad-object) (vl-load-com))

随附上述打印结果。dwg如下所示:
  1. Command: TEST
  2. ("Group1" . "Group1-Lay1")
  3. ("Group1" . "Group1-Lay2")
  4. ("Group1" . "Group1-Lay3")
  5. ("Group1" . "Group1-Lay4")
  6. ("Group1" . "Group1-Lay5")
  7. ("Group1" . "Group1-Lay6")
  8. ("Group1" . "Group1-Lay7")
  9. ("Group2" . "Group2-Lay1")
  10. ("Group2" . "Group2-Lay2")
  11. ("Group2" . "Group2-Lay3")
  12. ("Group2" . "Group2-Lay4")
  13. ("Group2" . "Group2-Lay5")
  14. ("Group2" . "Group2-Lay6")
  15. ("Group2" . "Group2-Lay7")
  16. ("Group3" . "Group3-Lay1")
  17. ("Group3" . "Group3-Lay2")
  18. ("Group3" . "Group3-Lay3")
  19. ("Group3" . "Group3-Lay4")
  20. ("Group3" . "Group3-Lay5")
  21. ("Group3" . "Group3-Lay6")
  22. ("Group3" . "Group3-Lay7")
  23. ("Group4" . "Group4-Lay1")
  24. ("Group4" . "Group4-Lay2")
  25. ("Group4" . "Group4-Lay3")
  26. ("Group4" . "Group4-Lay4")
  27. ("Group4" . "Group4-Lay5")
  28. ("Group4" . "Group4-Lay6")
  29. ("Group4" . "Group4-Lay7")

我只需要弄清楚如何这样构造Lst报价:
  1. '("Group1" . '("Group1-Lay1" "Group1-Lay2" "Group1-Lay3" "Group1-Lay5" "Group1-Lay6" "Group1-Lay7"))
  2. '("Group2" . '("Group2-Lay1" "Group2-Lay2" "Group2-Lay3" "Group2-Lay5" "Group2-Lay6" "Group2-Lay7"))
  3. '("Group3" . '("Group3-Lay1" "Group3-Lay2" "Group3-Lay3" "Group3-Lay5" "Group3-Lay6" "Group3-Lay7"))
  4. '("Group4" . '("Group4-Lay1" "Group4-Lay2" "Group4-Lay3" "Group4-Lay5" "Group4-Lay6" "Group4-Lay7"))

所以它会更可读(至少对我来说)。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:28:45 | 显示全部楼层
也许向后看一下车=group1将“group1 layername”添加到临时“lstemp”获取下一个if=group1将“group1 layername”添加到“lstemp”继续。一旦group1/=group2,创建新的层group1列表(“group1”。(lstemp))将lstemp替换为nil,并对group2进行agian。希望它有意义。
 
  1. groupname = "Group1"
  2. lsttemp = ("Group1-Lay1" "Group1-Lay2" "Group1-Lay3" "Group1-Lay5" "Group1-Lay6" "Group1-Lay7"))
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:44:59 | 显示全部楼层
图形中的图层过滤器真的是“组过滤器”吗?我不能确定,因为BricsCAD只支持图层特性过滤器,但图形中的过滤器似乎就是这种类型。
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 17:55:48 | 显示全部楼层
是的,BIGAL,我正在考虑类似的事情,但也许我可以再回头,修改“Lst”创建以适应我之前的发现(来自上面代码的注释部分):
  1. (defun C:test ( / LayersColl LFtContainer MyLayerFilterNames )
  2. (setq LayersColl (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
  3. (setq LFtContainer (vla-item (vla-GetExtensionDictionary LayersColl) "ACAD_LAYERFILTERS"))
  4. (vlax-map-collection LFtContainer '(lambda (x) (setq MyLayerFilterNames (cons (vla-get-Name x) MyLayerFilterNames))))
  5. (if MyLayerFilterNames
  6.         (foreach x (reverse MyLayerFilterNames)
  7.                 (print (HowMyLayerFilterIsCreated x))
  8.         )
  9. )
  10. (princ)
  11. ); defun C:test
  12. (defun HowMyLayerFilterIsCreated ( LyrFilterName / LayersColl LFtContainer MyLayerFilter XRecordDataLst MyLayerFilterXRecordDataType MyLayerFilterXRecordData )
  13. (if
  14.         (and
  15.                 (setq LayersColl (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
  16.                 (setq LFtContainer (vla-item (vla-GetExtensionDictionary LayersColl) "ACAD_LAYERFILTERS"))
  17.                 (setq MyLayerFilter (vla-item LFtContainer LyrFilterName))
  18.         )
  19.         (progn
  20.                 (vla-GetXRecordData MyLayerFilter 'MyLayerFilterXRecordDataType 'MyLayerFilterXRecordData)
  21.                 (setq XRecordDataLst (mapcar 'vlax-variant-value (vlax-safearray->list MyLayerFilterXRecordData)))
  22.         )
  23. )
  24. XRecordDataLst
  25. );| defun HowMyLayerFilterIsCreated |; (or (vlax-get-acad-object) (vl-load-com))

我得到了这个结果:
  1. Command: TEST
  2. ("Group1" "Group1*" "*" "*" 0 "*" "*")
  3. ("Group2" "Group2*" "*" "*" 0 "*" "*")
  4. ("Group3" "Group3*" "*" "*" 0 "*" "*")
  5. ("Group4" "Group4*" "*" "*" 0 "*" "*")

也许用每个层名对cadr进行wcmatch,然后以某种方式与car(代表组名)进行对比。
我认为我的这些清单与这一行有关:
180648cz2dhg8uvpzu3g7h.jpg
 
恐怕你是对的,罗伊,因为我正在使用这一行创建这些示例属性过滤器:
  1. (command "._-layer" "filter" "new" "property" "All" (strcat "NAME=="" (nth n LayGroupNames) "*"") (nth n LayGroupNames) "X" nil)

我真的不知道这两者之间的区别:
180650z3waj3233swke2ld.jpg
但现在我看到,双击带有groupfilter名称的文件夹时,上面的对话框“Layer Filter Properties”只出现在创建的“Property”过滤器上,而不是“Group”过滤器上。
虽然我不确定我会为“群组”找到什么信息(HowMyLayerFilterIsCreated)。
我会进一步实验,至少我现在得到了我需要的“信息”。。。因此,这就成了一个列表构建/操作的问题。
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:59:55 | 显示全部楼层
@Grrr:
如果项不在集合中,则item方法将出错:
您可以使用“vl catch all构造”来解决此问题:
  1. (KGA_Sys_Apply 'vla-item (list (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "DoesNotExist"))
  2. ;;; ======================================================================
  3. ;;; Lib function: KGA_Sys_Apply
  4. ;;; Purpose:      Shortcut for standard "vl-catch-all construction".
  5. ;;; Arguments:    expr   - Expression to evaluate.
  6. ;;;               varLst - List of variables.
  7. ;;; Return value: Varies. Note: A nil value can mean two things: there was
  8. ;;;               an error or the expression returned nil.
  9. ;;;               Use (KGA_Sys_ApplyAlt) if this is a problem.
  10. ;;; Remarks:      None.
  11. ;;; Examples:
  12. ;;; (KGA_Sys_Apply 'strcat '("a" "bb" "ccc" 1))      => nil
  13. ;;; (KGA_Sys_Apply 'strcat '("a" "bb" "ccc" "dddd")) => "abbcccdddd"
  14. ;;; ======================================================================
  15. (defun KGA_Sys_Apply (expr varLst / ret)
  16. (if (not (vl-catch-all-error-p (setq ret (vl-catch-all-apply expr varLst))))
  17.    ret
  18. )
  19. )
  20. ;;; Similar to (KGA_Sys_Apply) but the return value is T or nil (there was an error).
  21. (defun KGA_Sys_ApplyAlt (expr varLst)
  22. (not (vl-catch-all-error-p (vl-catch-all-apply expr varLst)))
  23. )
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 18:09:50 | 显示全部楼层
是的,罗伊,我忘了“错误陷阱”这些。我更喜欢这样:
  1. ; modeT - if is set to true: then the return would be 'T or nil, otherwise the returned value or nil
  2. ; Examples: ;;; (ErrCatch nil '/ '(4 2)) -> 2 ;;; (ErrCatch T '/ '(4 2)) -> T ;;; (ErrCatch nil '/ '(4 0)) -> nil ;;; (ErrCatch T '/ '(4 0)) -> nil ;;;
  3. (defun ErrCatch ( modeT func varLst / rtn ) (if (not (vl-catch-all-error-p (setq rtn (vl-catch-all-apply func varLst)))) (if modeT 'T rtn)) )

例子:
  1. 12

谢谢
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 08:57 , Processed in 1.136642 second(s), 80 queries .

© 2020-2025 乐筑天下

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