找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1329|回复: 5

[研讨] 显示隐藏实体程序效率测试!!!

[复制链接]
发表于 2004-5-9 00:08:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
由 lsjjm 长老的 《使可见图层上的图元不可见》http://www.xdcad.net/forum/showt ... d=959787#post959787   一贴而引发的测试,仅对lsp,vlisp,vb写法进行测试,arx因本人不会,如果有朋友有能力,希望补上arx程序来进行测试.
  1. ; 显示隐藏实体程序效率测试 dxf60 visible
  2. ;程序前的注释为测试运行所需时间.

  3. ;;以下为测试隐藏10000个圆实体测试://///////////////////////////////
  4. ;1.813秒;1.781秒  ;改while未repeat.
  5. (defun c:test1 (/ ss n ent)
  6.   (setq ss (ssget) n 0)
  7.   (vl-cmdf ".time" "r" "on" "d" "")
  8.   (repeat (setq n (sslength ss))
  9.     (setq ent (ssname ss (setq n(1- n))))
  10.     (vla-put-Visible (vlax-ename->vla-object ent) :vlax-false)
  11.   )
  12.   (vl-cmdf ".time" "off" "d" "")
  13. )
  14. ;01.782秒; 1.844秒  ;不对是否有visible属性进行判断.
  15. (defun c:t1 (/ ss n ent)
  16.   (setq ss (ssget) n 0)
  17.   (vl-cmdf ".time" "r" "on" "d" "")
  18.   (while (< n (sslength ss))
  19.     (setq ent (ssname ss n) n (1+ n))
  20.     (vla-put-Visible (vlax-ename->vla-object ent) :vlax-false)
  21.   )
  22.   (vl-cmdf ".time" "off" "d" "")
  23. )
  24. ;1.187秒;1.109秒   ;使用activeselectionset
  25. (defun c:t2 (/ ss n ent)
  26.   (setq ss (ssget) n 0)
  27.   (vl-cmdf ".time" "r" "on" "d" "")
  28.   (vlax-for obj (vla-get-activeselectionset (vla-get-activedocument(vlax-get-acad-object)))
  29.     (vla-put-Visible obj :vlax-false)
  30.   )
  31.   (vl-cmdf ".time" "off" "d" "")
  32. )
  33. ;
  34. ;----------------------------------------------------------------
  35. ;0.313秒 ;0.313秒  ;vb方法
  36. (defun c:t3()
  37.     (setq ss (ssget) )
  38.     (vl-cmdf ".time" "r" "on" "d" "")
  39.     (command "-vbarun" "tt")
  40.     (vl-cmdf ".time" "off" "d" "")
  41. )
  42. ;----------------------------------------------------------------
  43. ;|vba程序:
  44. Public Sub tt ()
  45. Dim ss As AcadSelectionSet
  46. Dim i As AcadEntity
  47. Set ss = ThisDrawing.ActiveSelectionSet
  48. For Each i In ss
  49. i.Visible = False
  50. Next i
  51. End Sub
  52. |;


  53. ;1.906秒;1.843秒;1.890秒 ;;改dxf 60组码.
  54. (defun c:test1b (/ ss n ent)
  55.   (setq ss (ssget) n 0)
  56.   (vl-cmdf ".time" "r" "on" "d" "")
  57.   (repeat (setq n (sslength ss))
  58.     (setq ent (ssname ss (setq n(1- n))))
  59.     (entmod (cons '(60 . 1) (entget ent)))
  60.   )
  61.   (vl-cmdf ".time" "off" "d" "")
  62. )
  63. ;19.750秒
  64. (defun c:test ()
  65.   (setq ss (ssget) n 0)
  66.   (vl-cmdf ".time" "r" "on" "d" "")
  67.   (while (< n (sslength ss))
  68.     (setq ent (ssname ss n)
  69.           obj (vlax-ename->vla-object ent))
  70.     (if (vlax-property-available-p obj 'Visible T)
  71.       (if (= (vla-get-visible obj) :vlax-true)
  72.         (vla-put-Visible obj :vlax-false)
  73.       )
  74.     )
  75.     (setq n (1+ n))
  76.   )
  77.   (vl-cmdf ".time" "off" "d" "")
  78. )

  79. ;;以下为恢复所有隐藏实体测试://///////////////////////////////
  80. ;4.094秒;2.547(ss使用过滤)
  81. (defun c:test2 (/ ss n ent)
  82.   (setq ss (ssget "x") n 0)
  83.   (vl-cmdf ".time" "r" "on" "d" "")
  84.   (repeat (setq n (sslength ss))
  85.     (setq ent (ssname ss (setq n(1- n))))
  86.     (vla-put-Visible (vlax-ename->vla-object ent) :vlax-true)
  87.   )
  88.   (vl-cmdf ".time" "off" "d" "")
  89. )

  90. ;4.140秒
  91. (defun c:test2b (/ ss n ent)
  92.   (setq ss (ssget "x") n 0)
  93.   (vl-cmdf ".time" "r" "on" "d" "")
  94.   (repeat (setq n (sslength ss))
  95.     (setq ent (ssname ss (setq n(1- n))))
  96.     (if (= (vla-get-visible (setq obj (vlax-ename->vla-object ent))) :vlax-false)
  97.         (vla-put-Visible obj :vlax-true)
  98.     )
  99.   )
  100.   (vl-cmdf ".time" "off" "d" "")
  101. )


  102. ;1.344秒;1.390秒
  103. (defun c:t4()
  104.     ;(setq ss (ssget "x") )
  105.     (vl-cmdf ".time" "r" "on" "d" "")
  106.     (command "-vbarun" "tt2")
  107.     (vl-cmdf ".time" "off" "d" "")
  108. )
  109. ;----------------------------------------------------------------
  110. ;|vba程序:
  111. Public Sub tt2 ()
  112. Dim ss As AcadSelectionSet
  113. Dim i As AcadEntity
  114. Set ss = ThisDrawing.ActiveSelectionSet
  115. ss.Select acSelectionSetAll
  116. For Each i In ss
  117. i.Visible = True
  118. Next i
  119. End Sub

  120. ;;41.765;41.578
  121. (defun c:test ()
  122. (setq ss (ssget "x") n 0)
  123. (vl-cmdf ".time" "r" "on" "d" "")
  124. (while (< n (sslength ss))
  125. (setq ent (ssname ss n)
  126. obj (vlax-ename->vla-object ent))
  127. (if (vlax-property-available-p obj 'Visible T)
  128. (if (= (vla-get-visible obj) :vlax-false)
  129. (vla-put-Visible obj :vlax-true )
  130. )
  131. )
  132. (setq n (1+ n))
  133. )(vl-cmdf ".time" "off" "d" "")
  134. )
  135. |;

  136. ;0.813秒;0.843秒 ;ss使用过滤.
  137. (defun c:t4b ()
  138.     (setq ss (ssget "x" '((60 . 1))))
  139.     (vl-cmdf ".time" "r" "on" "d" "")
  140.     (command "-vbarun" "tt3")
  141.     (vl-cmdf ".time" "off" "d" "")
  142. )
  143. ;----------------------------------------------------------------
  144. ;|vba程序:
  145. Public Sub tt3 ()
  146. Dim ss As AcadSelectionSet
  147. Dim i As AcadEntity
  148. Set ss = ThisDrawing.ActiveSelectionSet
  149. For Each i In ss
  150. i.Visible = True
  151. Next i
  152. End Sub
  153. |;

  154. 补充eachy的程序测试:
  155. ;; by eachy
  156. (defun Ea:OnOffObj (ss mode / ent obj sl n)
  157.   (if (= (type ss) 'PICKSET)
  158.     (progn
  159.       (vlax-map-collection
  160.         (vla-get-activeselectionset
  161.           (vla-get-activedocument (vlax-get-acad-object))
  162.         )
  163.         '(lambda (x) (vla-put-visible x mode))
  164.       )
  165.     )
  166.   )
  167. )
  168. ;;隐藏实体 1.188秒 ;1.187秒
  169. (defun c:Ea:HideObj (/ s t0 t1)
  170.   (princ "\n选择隐藏实体.....")
  171.   (setq s (ssget))
  172.   (vl-cmdf ".time" "r" "on" "d" "");;;;;
  173.   (ea:onoffobj s :vlax-false)
  174.   (vl-cmdf ".time" "off" "d" "")
  175.   (princ)
  176. )
  177. ;;显示全部实体 1.844秒 ;1.813秒  
  178. ;;选集使用过滤速度有明显提高!!! (setq s (ssget "x" '((60 . 1))))
  179. (defun c:Ea:ShowALL (/ s t0 t1)
  180.   (setq s (ssget "x" '((60 . 1))))
  181.   (vl-cmdf ".time" "r" "on" "d" "")
  182.   (ea:onoffobj s :vlax-true)
  183.   (vl-cmdf ".time" "off" "d" "")
  184.   (princ)
  185. )
  186. ;;;!!!补充测试:使用xdapi>>>>
  187. ;0.109秒;0.094秒.
  188. (defun c:x1 (/ s)
  189.   (setq s (ssget))
  190.   (vl-cmdf ".time" "r" "on" "d" "")
  191.   (xdrx_entity_setvisible s nil)
  192.   (vl-cmdf ".time" "off" "d" "")
  193. )
  194. ;0.406秒,0.422秒
  195. (defun c:x2 (/ s)
  196.   (setq s (ssget "x" '((60 . 1))))
  197.   (vl-cmdf ".time" "r" "on" "d" "")
  198.   (xdrx_entity_setvisible s t)
  199.   (vl-cmdf ".time" "off" "d" "")
  200. )


测试结论(注:结论仅作为参考,不保证所有情况下适用):

1 。vb比vlsp,lsp效率有明显提高。
2。vl中使用activeselectionset效率比未使用略有提高(约1/3)。
   如未使用,Visible方法和改60组码速度差不多.(改60略慢,仅对隐藏测试,恢复隐藏未测试)
3.使用vlax-property-available-p 速度被明显拉下来.
4.使用XDRX_API,效率有质的提高,甚至隐藏用时为vba的1/3,恢复为vba的1/2.
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 593个

财富等级: 财运亨通

发表于 2004-5-9 00:40:33 | 显示全部楼层
速度可以忍受,当然和机器的配置有关。

我的工具集中隐藏/显示实体的程序

使用中的两个发现

1 在这个应用中vlax-map-collection 比vlax-for 效率略有提高,很少
2 vlax-ename->vla-object 是比较耗时间的,在利用 vlax-curve 部分函数时,直接用while 和 实体名 比 转换或者 vlax-for 效率要高很多

  1. (defun Ea:OnOffObj (ss mode / ent obj sl n)
  2.   (if (= (type ss) 'PICKSET)
  3.     (progn
  4.       (vlax-map-collection
  5.         (vla-get-activeselectionset
  6.           (vla-get-activedocument (vlax-get-acad-object))
  7.         )
  8.         '(lambda (x) (vla-put-visible x mode))
  9.       )
  10.     )
  11.   )
  12. )
  13. ;;隐藏实体
  14. (defun c:Ea:HideObj (/ s t0 t1)
  15.   (princ "\n选择隐藏实体.....")
  16.   (setq s (ssget))
  17.   (ea:onoffobj s :vlax-false)
  18.   (vl-cmdf ".time" "off" "d" "")
  19.   (princ)
  20. )
  21. ;;显示全部实体
  22. (defun c:Ea:ShowALL (/ s t0 t1)
  23.   (setq s (ssget "x" '((60 . 1))))
  24.   (vl-cmdf ".time" "r" "on" "d" "")
  25.   (ea:onoffobj s :vlax-true)
  26.   (vl-cmdf ".time" "off" "d" "")
  27.   (princ)
  28. )


  1. 命令: ea:hideobj

  2. 选择隐藏实体.....
  3. 选择对象: 指定对角点: 找到 27973 个

  4. 选择对象:

  5. 当前时间:                 2004年5月9日 于 0:36:43:906 下午
  6. 此图形的各项时间统计:
  7.   创建时间:               2000年3月22日 于 15:03:48:210 下午
  8.   上次更新时间:           2004年5月8日 于 23:52:45:093 下午
  9.   累计编辑时间:           8 天 19:16:34.686
  10.   消耗时间计时器 (开):    0 天 00:00:00.031
  11.   下次自动保存时间:       0 天 00:00:00.000

  12. 当前时间:                 2004年5月9日 于 0:36:46:609 下午
  13. 此图形的各项时间统计:
  14.   创建时间:               2000年3月22日 于 15:03:48:210 下午
  15.   上次更新时间:           2004年5月8日 于 23:52:45:093 下午
  16.   累计编辑时间:           8 天 19:16:37.389
  17.   消耗时间计时器 (关):   [color=red] 0 天 00:00:02.734[/color]
  18.   下次自动保存时间:       0 天 00:00:00.000
  19. 27973


  20. 命令: ea:showall

  21. 当前时间:                 2004年5月9日 于 0:38:06:968 下午
  22. 此图形的各项时间统计:
  23.   创建时间:               2000年3月22日 于 15:03:48:210 下午
  24.   上次更新时间:           2004年5月8日 于 23:52:45:093 下午
  25.   累计编辑时间:           8 天 19:17:57.748
  26.   消耗时间计时器 (开):    0 天 00:00:00.015
  27.   下次自动保存时间:       0 天 00:09:59.984

  28. 当前时间:                 2004年5月9日 于 0:38:09:500 下午
  29. 此图形的各项时间统计:
  30.   创建时间:               2000年3月22日 于 15:03:48:210 下午
  31.   上次更新时间:           2004年5月8日 于 23:52:45:093 下午
  32.   累计编辑时间:           8 天 19:18:00.280
  33.   消耗时间计时器 (关):   [color=red] 0 天 00:00:02.547[/color]
  34.   下次自动保存时间:       0 天 00:09:57.453
  35. 27973
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 593个

财富等级: 财运亨通

发表于 2004-5-9 01:19:04 | 显示全部楼层
再来一个 xdapi 的

  1. (defun c:t1 (/ s)
  2.   (setq s (ssget))
  3.   (vl-cmdf ".time" "r" "on" "d" "")
  4.   (xdrx_entity_setvisible s nil)
  5.   (vl-cmdf ".time" "off" "d" "")
  6. )
  7. (defun c:t2 (/ s)
  8.   (setq s (ssget "x" '((60 . 1))))
  9.   (vl-cmdf ".time" "r" "on" "d" "")
  10.   (xdrx_entity_setvisible s t)
  11.   (vl-cmdf ".time" "off" "d" "")
  12. )

运行效果

  1. 命令: t1
  2. 选择对象: 指定对角点: 找到 27973 个

  3. 选择对象:

  4. 当前时间:                 2004年5月9日 于 1:13:57:453 下午
  5. 此图形的各项时间统计:
  6.   创建时间:               2000年3月22日 于 15:03:48:210 下午
  7.   上次更新时间:           2004年5月8日 于 23:52:45:093 下午
  8.   累计编辑时间:           8 天 19:53:48.248
  9.   消耗时间计时器 (开):    0 天 00:00:00.031
  10.   下次自动保存时间:       0 天 00:08:11.172

  11. 当前时间:                 2004年5月9日 于 1:13:58:140 下午
  12. 此图形的各项时间统计:
  13.   创建时间:               2000年3月22日 于 15:03:48:210 下午
  14.   上次更新时间:           2004年5月8日 于 23:52:45:093 下午
  15.   累计编辑时间:           8 天 19:53:48.936
  16.   消耗时间计时器 (关):    [color=red]0 天 00:00:00.703[/color]
  17.   下次自动保存时间:       0 天 00:08:10.484
  18. T

  19. 命令: t2

  20. 当前时间:                 2004年5月9日 于 1:14:17:375 下午
  21. 此图形的各项时间统计:
  22.   创建时间:               2000年3月22日 于 15:03:48:210 下午
  23.   上次更新时间:           2004年5月8日 于 23:52:45:093 下午
  24.   累计编辑时间:           8 天 19:54:08.155
  25.   消耗时间计时器 (开):    0 天 00:00:00.016
  26.   下次自动保存时间:       0 天 00:07:51.266

  27. 当前时间:                 2004年5月9日 于 1:14:17:890 下午
  28. 此图形的各项时间统计:
  29.   创建时间:               2000年3月22日 于 15:03:48:210 下午
  30.   上次更新时间:           2004年5月8日 于 23:52:45:093 下午
  31.   累计编辑时间:           8 天 19:54:08.670
  32.   消耗时间计时器 (关):    [color=red]0 天 00:00:00.531[/color]
  33.   下次自动保存时间:       0 天 00:07:50.750
  34. T
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-5-10 11:14:14 | 显示全部楼层
好像不用那么复杂 提供一个选择变不可见
(defun c:text()(setq ss (ssget))
(setq i 0)
(while (<= i (sslength ss))
(setq abc (ssname SS i))
(redraw abc 2)
(setq i (+ 1 i))
))

测试一下
恢复可见命令regen
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-5-10 12:04:20 | 显示全部楼层
conn 你的不可见程序和陌生人/EA讨论的是完全不同的,如果任何触动REGEN的外挂或者命令都可能触发显示的,比如对一个由于某种疾病引起痛痒的病人,上面的程序就是讨论如何用最短的疗程根除引起痛痒的病根,REDRAW的方法就是在痒的时候挠挠
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2004-5-10 14:38:25 | 显示全部楼层
用 text作为命令名是不明智的(应为test吧?),我见你贴了两次,第一次我想也许是笔误,第二次贴还这样#E$% 。。。。。
用redraw方法,只要regen就重显,但有时候我们希望regen时候也不重显,这就需要象我和eachy讨论的这种程序了。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-1 08:58 , Processed in 0.399226 second(s), 41 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表