Author Topic: Freezing/Thawing Layers by Wildcard Match.  (Read 12744 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #30 on: November 14, 2014, 08:00:59 AM »
A little bit better:
Code: [Select]
(defun ALE_Layer_OnAndThawTest2 ( / ChgLst LyrNam BitVal)
  (setq ChgLst '((0 . "~0") (1 . "$XP*,*HIDDEN*,$SDT*,Defpoints")))
  (vlax-map-Collection
    *aclayers
   '(lambda (LmbDat)
      (setq BitVal nil   LyrNam (strcase (vla-get-Name LmbDat)))
      (foreach ForElm ChgLst
        (if (wcmatch LyrNam (cdr ForElm))
          (if (zerop (car ForElm)) (setq BitVal 0) (setq BitVal 1))
        )
      )
      (and
        BitVal
        (if (zerop BitVal)
          (progn
            (vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-false))
            (vl-catch-all-apply 'vla-put-freeze (list LmbDat :vlax-true))
          )
          (progn
            (vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-true ))
            (vl-catch-all-apply 'vla-put-freeze (list LmbDat :vlax-false))
          )
        )
      )
    )
  )
  (vla-put-activelayer *acdoc (vla-item *aclayers "0"))
)
Code: [Select]
Elapsed milliseconds / relative speed for 32 iteration(s):
    (ALE_LAYER_ONANDTHAWTEST2).....1872 / 2.72 <fastest>
    (LAYERONANDTHAWTEST-AX)........2386 / 2.14
    (ALE_LAYER_ONANDTHAWTEST2).....3057 / 1.67
    (ALE_LAYER_ONANDTHAWTEST2).....3338 / 1.53
    (LAYERONANDTHAWTEST-AX)........4898 / 1.04
    (LAYERONANDTHAWTEST-AX)........5101 / 1 <slowest>

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #31 on: November 14, 2014, 08:14:08 AM »
Code: [Select]
; Now I scraped the barrel (my apologies for transl.)
(defun ALE_Layer_OnAndThawTest3 ( / ChgLst LyrNam BitVal)
  (setq ChgLst '((0 . "~0") (1 . "$XP*,*HIDDEN*,$SDT*,Defpoints")))
  (vlax-map-Collection
    *aclayers
   '(lambda (LmbDat)
      (setq BitVal nil   LyrNam (strcase (vla-get-Name LmbDat)))
      (foreach ForElm ChgLst
        (if (wcmatch LyrNam (cdr ForElm))
           (and (wcmatch LyrNam (cdr ForElm)) (setq BitVal (car ForElm)))
        )
      )
      (and
        BitVal
        (if (zerop BitVal)
          (progn
            (or
              (= (vla-get-LayerOn LmbDat) ':vlax-false)
              (vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-false))
            )
            (or
              (= (vla-get-Freeze LmbDat) ':vlax-true)
              (vl-catch-all-apply 'vla-put-freeze (list LmbDat :vlax-true))
            )
          )
          (progn
            (or
              (= (vla-get-LayerOn LmbDat) ':vlax-true)
              (vl-catch-all-apply 'vla-put-LayerOn (list LmbDat :vlax-true))
            )
            (or
              (= (vla-get-Freeze LmbDat) ':vlax-false)
              (vl-catch-all-apply 'vla-put-Freeze (list LmbDat :vlax-false))
            )
          )
        )
      )
    )
  )
  (vla-put-activelayer *acdoc (vla-item *aclayers "0"))
)
Code: [Select]
Elapsed milliseconds / relative speed for 64 iteration(s):
    (ALE_LAYER_ONANDTHAWTEST3).....1544 / 6.33 <fastest>
    (ALE_LAYER_ONANDTHAWTEST3).....1716 / 5.69
    (ALE_LAYER_ONANDTHAWTEST3).....4024 / 2.43
    (LAYERONANDTHAWTEST-AX)........5850 / 1.67
    (LAYERONANDTHAWTEST-AX)........6490 / 1.5
    (LAYERONANDTHAWTEST-AX)........9766 / 1 <slowest>

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #32 on: November 14, 2014, 08:24:48 AM »
How about just :

Code - Auto/Visual Lisp: [Select]
  1. (setq BitVal  (car ForElm) )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #33 on: November 14, 2014, 08:36:49 AM »
How about just :

Code - Auto/Visual Lisp: [Select]
  1. (setq BitVal  (car ForElm) )
Yes...  8) old age puts you sunglasses... updated.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #34 on: November 14, 2014, 09:00:39 AM »
I think that to make a good test is necessary to start from the worse condition for all functions:
Code: [Select]
(defun LayerOnAndThawTest-ax (/ thawList LayerZero layName)
     (setq thawList '("$XP*,*HIDDEN*" "$SDT*" "Defpoints"))
     (command-s "_.layer" "_On" "*" "_t" "*" "")
...
)

(defun ALE_Layer_OnAndThawTest(n) ( / ChgLst LyrNam BitVal)
  (setq ChgLst '((0 . "~0") (1 . "$XP*,*HIDDEN*,$SDT*,Defpoints")))
  (command-s "_.layer" "_On" "*" "_t" "*" "")
...
)

(defun LayerOnAndThawTest-cmd (/ thawList)
     (setq thawList (_listitems->string
                      '("$XP*,*HIDDEN*" "$SDT*" "Defpoints")
                      ","
                    )
     )
     (command-s "_.layer" "_On" "*" "_t" "*" "_S" "0" "_Freeze" "*" "_On" thawList "_T" thawList "")
     (princ)
)

Code: [Select]
    (LAYERONANDTHAWTEST-CMD).......1060 / 4.22 <fastest>
    (ALE_LAYER_ONANDTHAWTEST)......1935 / 2.31
    (ALE_LAYER_ONANDTHAWTEST3).....3432 / 1.3
    (LAYERONANDTHAWTEST-AX)........4477 / 1 <slowest>



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #35 on: November 14, 2014, 10:26:49 AM »
< .. >
Yes...  8) old age puts you sunglasses... updated.

I survived the 60's ... so everything is rose tinted for me .
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #36 on: November 14, 2014, 10:38:59 AM »
< .. >
Yes...  8) old age puts you sunglasses... updated.

I survived the 60's ... so everything is rose tinted for me .
I am very very close ... :( ............ ;D

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #37 on: November 14, 2014, 08:23:59 PM »
Regarding the use of (vl-catch-all-apply in place of testing if the indexed layer is Active :

Code - Auto/Visual Lisp: [Select]
  1. (or *:acapp          (setq *:acapp (vlax-get-acad-object)))
  2. (or *:activedoc    (setq *:activedoc (vla-get-activedocument *:acapp)))
  3. (or *:layers          (setq *:layers (vla-get-layers *:activedoc)))
  4.  
  5. (defun _LayerTest32 ()
  6.   (vlax-for LayerObj *:layers
  7.     (vl-catch-all-apply 'vla-put-freeze (list LayerObj :vlax-true))
  8.     (vl-catch-all-apply 'vla-put-freeze (list LayerObj :vlax-false))
  9.   )
  10. )
  11. (defun _LayerTest33 (/ activeLayer)
  12.   (setq activeLayer (vla-get-activelayer *:activedoc))
  13.   (vlax-for LayerObj *:layers
  14.     (if (not (equal activeLayer LayerObj))
  15.       (vla-put-freeze LayerObj :vlax-true)
  16.     )
  17.     (if (not (equal activeLayer LayerObj))
  18.       (vla-put-freeze LayerObj :vlax-false)
  19.     )
  20.   )
  21. )
  22.  
  23. (BenchMark2
  24.   800  '(
  25.     (_LayerTest32)
  26.     (_LayerTest33)
  27.    )
  28. )
  29.  
  30.  

Benchmarking-V2 :B=800 [M.P.2005 <revised kdub 2005,2014>] ........
Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (_LAYERTEST32).....936 / 1.1527 <slowest>: 29.25ms Per iteration
    (_LAYERTEST33).....812 / 1 <fastest>: 25.375ms Per iteration

 
Benchmarking-V2 :B=800 [M.P.2005 <revised kdub 2005,2014>] ........
Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (_LAYERTEST32).....921 / 1.1342 <slowest>: 28.78125ms Per iteration
    (_LAYERTEST33).....812 / 1 <fastest>: 25.375ms Per iteration


I suppose 4 ms which represents about a 15% efficiency difference should be considered.
... and the code is more succinct.

But sometimes spending an hour or two to save 4 ms is questionable
 ... as depicted here:

Translated:-
If you can save 5 minutes daily the break even development time is 6 days.
« Last Edit: November 14, 2014, 08:46:30 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Freezing/Thawing Layers by Wildcard Match.
« Reply #38 on: November 14, 2014, 08:58:09 PM »
In answer to a PM which asked 'why I want to test before freezing or thawing the active Layer'


Code - Auto/Visual Lisp: [Select]
  1.  
  2. (or *:acapp     (setq *:acapp (vlax-get-acad-object)))
  3. (or *:activedoc (setq *:activedoc (vla-get-activedocument *:acapp)))
  4. (or *:layers    (setq *:layers (vla-get-layers *:activedoc)))
  5.  
  6. (setq activeLayer (vla-get-activelayer *:activedoc))
  7.  
  8.       ;;=> error: Automation Error. Invalid layer
  9. (vla-put-freeze activeLayer :vlax-true)        
  10.  
  11.       ;;=> error: Automation Error. Invalid layer
  12. (vla-put-freeze activeLayer :vlax-false)  
  13.  
  14.       ;;=> returns #<%catch-all-apply-error%> locally, BUT does not crash
  15. (vl-catch-all-apply 'vla-put-freeze (list activeLayer :vlax-true))
  16.                                                            
  17.  
  18.  
  19.  
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.